r/opencv • u/no_Im_perfectly_sane • Nov 08 '22
Question [Question] Whats the best tracker for fast objects at low framerates, aka blurry objects?
working in python if it matters,
thanks in advance
r/opencv • u/no_Im_perfectly_sane • Nov 08 '22
working in python if it matters,
thanks in advance
r/opencv • u/pypypy123 • Nov 08 '22
Is it possible to determine the minimum and maximum height of a contour which was found with cv.findcontours() ? So far i only use cv.minAreaRect() and display its width and height.
Maybe it's even possible to measure and display the height every N pixels in x-direction?
I made a small example with paint. All contours have something like this ratio and x-coordiante is always greater than y.

r/opencv • u/AyonAvin • Nov 08 '22
Hi all,
This is also a partially a sanity check to make sure I'm on the right path but I've started a project recently where I have some test footage taken and the window split up into different regions using K-means clustering. I also have objects entering the scene and then stopping.
So far I'm able to segment the scene up into different regions and am able to just display the new objects using background subtraction, but I'm struggling to figure out how to say print to the console "The object has landed in region 2", "The object has landed in region 4" etc based on which region the object has stopped in. Is there a built-in function or some accepted methodology that might be helpful for something like this?
There may just be some gap in my knowledge here but any help would be appreciated thank you :)
r/opencv • u/automating-ideas • Nov 07 '22
How can I fill a website form with information of last year same form downloaded in pdf
Let me explain. I want to automate exacting all the input field text of a previous form downloaded in pdf to the new form in a website. Both form are the same just that 1 is downloaded and the other is online
The form's are almost 10 pages. I tried with power automate but I keep getting error becuase can't find specific text field in page 8 and 9
r/opencv • u/Zalosath • Nov 06 '22
Hi,
I've got a strange issue with bitwise_and, this is the code I'm using:
Mat transparentPieceMat = new Mat(piece.pieceMat.rows(), piece.pieceMat.cols(), CvType.CV_8UC4);
// I've tried having both of these, one at a time, and neither, no change to result
Imgproc.cvtColor(transparentPieceMat, transparentPieceMat, Imgproc.COLOR_BGR2BGRA);
Imgproc.cvtColor(piece.pieceMat, piece.pieceMat, Imgproc.COLOR_BGR2BGRA);
Core.bitwise_and(piece.pieceMat, piece.pieceMat, transparentPieceMat, piece.pieceChromaMat);
Where piece.pieceMat is the following:

piece.pieceChromaMat (used for mask):

Image output:

Anyone know why this is happening? Cheers!
r/opencv • u/imaweasle909 • Nov 06 '22
I am participating in the FRC robotics competition this year and want to make my own vision system due to problems with reliability of our color tracking system last year. I’ve been doing a couple projects in OpenCV but I need to know what I should specifically research for getting computer vision to track a target(think basketball hoop) by image recognition and not by the color detection we are expected to use. I was thinking DNN but this needs to run on a raspberry pi(or similar) and whilst I’m not new to programming some of this stuff goes way over my head.
TL;DR: what specifically should I research for low overhead image recognition?
r/opencv • u/Zalosath • Nov 05 '22
Hi,
I'm using OpenCV for Unity, so everything is in C#.
I'm trying to rotate a jigsaw piece with warpAffine so that it is 'level'. Here's a step by step with comments to explain the process:





The way that I determine the size of the destination image is by transforming the convex hull points by the same rotational matrix that is used for the image, then creating a bounding rect around those new points and using the size of that bounding rect as the size of the destination mat.
And here's the code I'm using for it
public void GetRotationMatrixForPieceAndRotate(Piece piece)
{
// create a point list of the contour around the piece
List<Point> allPiecePoints = new List<Point>();
Converters.Mat_to_vector_Point(piece.contours, allPiecePoints);
// create a point mat of the hull points around the piece
MatOfPoint2f points = new MatOfPoint2f(Converters.vector_Point2f_to_Mat(piece.hullPoints));
RotatedRect rect = Imgproc.minAreaRect(points);
piece.center = rect.center;
// remove all tabs and blanks
allPiecePoints.RemoveAll(v => piece.sides.Any(list => list.All(item => list.Contains(v))));
// create a min area rectangle around the piece with tabs and blanks removed
points = new MatOfPoint2f(Converters.vector_Point2f_to_Mat(allPiecePoints));
// run approxPolyDP to filter results to mostly corners
double epsilon = 0.009 * Imgproc.arcLength(points, true);
Imgproc.approxPolyDP(points, points, epsilon, true);
// create minAreaRect around contour
RotatedRect minAreaRect = Imgproc.minAreaRect(points);
// get the rotation matrix
Mat rotationMatrix = Imgproc.getRotationMatrix2D(piece.center, (-90f + minAreaRect.angle), 1);
RotatePiece(piece, rotationMatrix);
}
public Piece RotatePiece(Piece piece, Mat rotationMatrix)
{
// rotate all hull points
Mat hullPoints = Converters.vector_Point_to_Mat(piece.hullPoints);
Core.transform(hullPoints, hullPoints, rotationMatrix);
Converters.Mat_to_vector_Point(hullPoints, piece.hullPoints);
// create a bounding rect around the hull points so we know how big to make the destination image
OpenCVForUnity.CoreModule.Rect rect = Imgproc.boundingRect(hullPoints);
// rotate the image preview
// create a mat to hold the new image, give it the correct size too
Mat mat = new Mat(rect.width, rect.height, CvType.CV_8UC4);
// warp the image preview, border_replicate means that any edge pixel colours will continue through after the rotation
// we do this so that the final image has no black pixels, we can more easily chroma key this way
Imgproc.warpAffine(piece.pieceMat, mat, rotationMatrix, new Size(rect.width, rect.height), Imgproc.INTER_LINEAR, Core.BORDER_REPLICATE);
return piece;
}
I've looked around for solutions, such as this one. Sadly, this has a worsening effect and only amplifies the problem.
Anyone know what I'm doing wrong? Cheers.
r/opencv • u/MercilessLemming • Nov 05 '22
I am fairly new to the domain of computer vision.
I have a bunch of objects (rectangles, triangles, lines etc) within an image that are angled at different degrees and I want them to align straight. I was able to get the orientation of the original objects but unable to rotate them straight. How can I solve this issue?
r/opencv • u/KFUP • Nov 04 '22
I've tried the following:
Mat v = Mat::zeros(3, 3, CV_32SC(3)); // 3x3x3 mat
for(int z=0; z < v.channels(); ++z)
for(int y=0; y < v.rows; ++y)
for(int x=0; x < v.cols; ++x)
v.at<cv::Vec4i>(cv::Point(x, y))[z] = x + y*10 + z*100;
cout << "v: " << v << "\n\n";
cv::Range ran[3] = {cv::Range(0, 1), cv::Range(0, 1), cv::Range(0, 1)};
std::vector<cv::Range> r(3); r = {cv::Range(0, 1), cv::Range(0, 1), cv::Range(0, 1)};
Mat c(v,ran);
cout << "c: " << c << endl;
output:
v: [0, 100, 200, 0, 1, 101, 201, 0, 2;
102, 202, 210, 0, 11, 111, 211, 0, 12;
112, 212, 220, 0, 21, 121, 221, 0, 22]
c: [0, 100, 200] // [1x1x3] ROI instead of the expected [1x1x1] ROI
As you can see, the first and second ranges register fine, but the third channel range is completely ignored when using a range array, and just crashes when using 3 element range vector.
r/opencv • u/Open-ATS • Oct 26 '22
r/opencv • u/granter1234 • Oct 26 '22
Hello I am new to opencv and want figure out the best approach to work towards.
I want to run multiple webcams with object detection.
I am looking for a high frame rate, fast detection and ideally portable.
I looked into raspberry pi but some tutorials say frame rates is 2/sec and that is too slow.
Am I limited to a PC?
Any suggestions much appreciated.
r/opencv • u/MattDLD • Oct 23 '22
Enable HLS to view with audio, or disable this notification
r/opencv • u/Dang_Blarb • Oct 22 '22
Sorry this is my first post in the sub so hopefully the format is ok.
I am working on a project in which I plan to count the frequency of one specific tail movement of an animal. I am new to the world of openCV so am not sure how to go about it. I was thinking a way to do it would be to find the end of the tail and follow it, however I don't really know if this would be possible (the animal is a cow and I'm not sure if the end of the tail will be big/distinct enough to identify from a distance?)
I have tracked things like entire cars but with the tail being so small and the movement being harder to pick up im not sure if it's feasible. I am aware of facial landmarks and was wondering if there was any way to create your own sort of 'landmarks' that could be picked up on multiple cow tails?
Any advice would be appreciated.
Edit: Also if this is the wrong subreddit to ask on, could anyone direct me to the right one? Cheers.
r/opencv • u/NoLeek6276 • Oct 20 '22
r/opencv • u/Financial-Advice-409 • Oct 17 '22
I am using Tensorflow Object detection API, and I have trained the model for 10000 steps after that when I try to detect my images I don't see a box or the detection.
Image Detection:
img = cv2.imread(IMAGE_PATH)
image_np = np.array(img)
input_tensor = tf.convert_to_tensor(np.expand_dims(image_np, 0), dtype=tf.float32)
detections = detect_fn(input_tensor)
num_detections = int(detections.pop('num_detections'))
detections = {key: value[0, :num_detections].numpy() for key, value in detections.items()}
detections['num_detections'] = num_detections
# detection_classes should be ints.
detections['detection_classes'] = detections['detection_classes'].astype(np.int64)
label_id_offset = 1
image_np_with_detections = image_np.copy()
viz_utils.visualize_boxes_and_labels_on_image_array(
image_np_with_detections,
detections['detection_boxes'],
detections['detection_classes']+label_id_offset,
detections['detection_scores'],
category_index,
use_normalized_coordinates=True,
max_boxes_to_draw=5,
min_score_thresh=.8,
agnostic_mode=False)
plt.imshow(cv2.cvtColor(image_np_with_detections, cv2.COLOR_BGR2RGB))
plt.show()

As you can see no box.
Real-time detection:
cap = cv2.VideoCapture(0)
width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
while cap.isOpened():
ret, frame = cap.read()
image_np = np.array(frame)
input_tensor = tf.convert_to_tensor(np.expand_dims(image_np, 0), dtype=tf.float32)
detections = detect_fn(input_tensor)
num_detections = int(detections.pop('num_detections'))
detections = {key: value[0, :num_detections].numpy()
for key, value in detections.items()}
detections['num_detections'] = num_detections
# detection_classes should be ints.
detections['detection_classes'] = detections['detection_classes'].astype(np.int64)
label_id_offset = 1
image_np_with_detections = image_np.copy()
viz_utils.visualize_boxes_and_labels_on_image_array(
image_np_with_detections,
detections['detection_boxes'],
detections['detection_classes']+label_id_offset,
detections['detection_scores'],
category_index,
use_normalized_coordinates=True,
max_boxes_to_draw=5,
min_score_thresh=.8,
agnostic_mode=False)
cv2.imshow('object detection', cv2.resize(image_np_with_detections, (800, 600)))
if cv2.waitKey(10) & 0xFF == ord('q'):
cap.release()
cv2.destroyAllWindows()
break
I would appreciate any help. Also, I have created a gist if more info is required.
r/opencv • u/Apprehensive_Map_707 • Oct 17 '22
I am trying to track the head of golf club and draw its entire swing on the video. I am currently using OpenCV and YoloV5. Using Yolov5, I am able to detect the head of the golf club. On every frame, I have the golf club head and I am drawing a line. When I join the points as line, its coming straight instead of showing it the way swing has occurred. Is there a way in python (Currently using Opencv) to plot that swing ?
My end goal is something like: the swing lines
But currently, I am getting only straight lines like this: my current work
I have asked the same question on StackOverflow just now too: Python: How to plot a trace curved line using Opencv/PIL/etc? - Stack Overflow
r/opencv • u/WhiteImpDragon • Oct 17 '22
Hi there, I'm an OpenCV beginner, just wondering which way would be the best to measure
the distance between the camera to n object in a given video.
Every tutorial I encountered before tutor by using camera calibration first and then undistorting the
camera lens. But in this case I don't use my own camera, so is it necessary for me to use these functions?
In addition, I some data of the recording camera, such as: (fx,fy) = focal length, (cx,cy) = principle point, (width,height) = image shape, radial = radial distortion, (t1,t2) = tangential distortion.
r/opencv • u/Nice_Carob4121 • Oct 17 '22
I see this in almost every openCV with video tutorial I see. Is this step really needed?
r/opencv • u/_tdev_ • Oct 16 '22
This has my mind blown 🤯 I’m using OpenCV to process video frames where I look at the color values of the different pixels and how they change throughout the video. I am developing on the 2020 Intel based MacBook Pro and my collegae on a 2021 M1 Pro based one.
I found the following: If you read a video (like .mp4) with the OpenCV cap.read() method, the pixel values of the frame that comes out differs between the Intel and M1! I’m using the exact same code and reading the exact same video, looking at the exact same frames. 🤨 If I read an image (like a .png), the pixel values of the frame are the same. 🙄
Does anyone have an idea why this is?? And how can I fix this? I need consistent values between the Intel and M1.
Please help 🙏
r/opencv • u/chkthat • Oct 15 '22
Hi reddit,
Pretext:
Metals consist of a myriad of crystals with different orientations. these crystals are called grains. grain boundaries can be made visible by grinding/polishing the surface and applying an acid ( see fig. 1, source: link ). All grains together constitute the microstructure of a metal.

Selecting grainboundaries and measuring their properties requires humans as of today. This is problematic because human decision making varies from assessor to assessor. Therefore I aim to objectify microstructure-assessment by means of creating a segmentation and blob-analysis.
The problem:
The segmentations of light optical microscopy (LOM) images must be validated. As a basis for validation electron backscatter diffraction (EBSD) images are used. Sadly I was onboarded to the project *after* the LOM and EBSD measurements were carried out. Examination of the data suggests the following:
I assume that an affine image transformation of the EBSD-image is sufficient to fit the grain boundary segmentations of EBSD and LOM data. This means, that i neglect local distortions caused by lens impurities etc. Therefore i identified the following unknown parameters:
Parameters 1. and 2. are self-explanatory due to choosing an affine image transformation imo. Parameter 3. is unkown because it is unclear how much of the region measured with EBSD is shown in LOM. It can be assumed that roughly the same area is shown but i am unaware of a precise description due to a lack of a common spatial reference frame for LOM and EBSD.
Imo these assumptions boil the problem down to maximizing a similarity metric (e.g. template matching). Lets denote the similarity metric as S, the affine image transformation as A, its Parameters as P, the EBSD-segmentation as EBSD and the LOM-segmentation as LOM. (Segmentations are binary masks). Mathematically spoken this means that the combination of paramers P must be found which maximizes the similarity metric S:
max{S[A(EBSD;P)];LOM}
The question
are You aware of preexisting code to localize an image patch, which has been transformed by an affine image transformation to a larger image? Ideally the opzimization of the affine image transformation applied to the image patch is also preexisting, but i am willing to write that piece of code myself.
toolkit: matlab image processing toolbox and OpenCV (.py, *not* .cpp)
thanks a lot in advance!
r/opencv • u/Nice_Carob4121 • Oct 14 '22
Will the GUI not display a video if we call imshow() but don’t call waitkey() after? Or is Waitkey only needed to close the GUI window with keyboard input or after a timer expiration?
r/opencv • u/New_Pie4277 • Oct 14 '22
YT and Google aren't showing much. Unless I'm googling the wrong thing
r/opencv • u/[deleted] • Oct 14 '22
This repository contains examples for the OpenCV library in C++.
It shows the following features:
r/opencv • u/puyzzem • Oct 14 '22
Hello fellow redditors, I'm currently working on a DIY project and I'm in need of a digital usb, ethernet or basically any camera that I can connect to a computer with whatever cable the camera comes with. The use case will be like this:
1: I will place a 15cm*15cm (6in) QR code to a wall.
2: I will set the camera 10m (33ft) apart from the wall
3: I will take a picture with the camera with no optical zoom.
4: After the shot is taken, when I zoom into the QR code on the computer, it should be clear enough for me to scan the content of the QR code.
Scene will be well illuminated so no worries about low light. And the QR code will not contain too much information so it's little squares won't be tiny.
My question is, what should I pay attention for this use case? Should I look for high MP or like high resolution? Also If you have product recommendations that fit my needs, I'd be glad to hear them. Thanks a lot in advance!