Opencv 2.4.2 Calcopticalflowpyrlk Doesn't Find Any Points

Optical Flow class in opencv(CalcOpticalFlowPyrLK) Parameters

The connection of these two values is that you first have to check the status array. The status array says if a feature point was found or not. This "check" has a higher priority then the error. The documentation says: "if the flow wasn’t found then the error is not defined". But the memory has to get alloceted anyway to keep the index correspondences. In C++ you have to initalize values, if this not happend there will be some random value. So I think OpenCV is not fill the array with zeros or something before. So that is why it can happend that the error is really small, but there is no status bit!

Here is some explenation how it Lucas-Kanada Method works.

When I was implementing Optical Flow in OpenCV i found this nice link.

Also the book Mastering OpenCV with Practical Computer Vision Projects has a usefull chapter about that.

JavaCV: How to Find Significant points in a binary image

You can use a loop here to find the most left, right, top and bottom points. However, you need to think on how to make a smart loop. You could just loop through all pixels, but you could also use a smarter approach. For instance, the left most point is probably somewhere on the left. So if you use a scanline which goes from left to right you might be more likely to find this pixel than if you would just scan top->bottom. This being said, it is quite easy to get the values from an image.

Let's say we have an image binaryImg with n channels. In case of a gray scale image n should be 1, but in case of a color image n should be 3. Let's say we have the indices 0 <= y < height, 0 <= x < width and 0 <= k < n. We can the value of a pixel(x, y) as follows:

((uchar *)(binaryImg->imageData + y*binaryImg->widthStep))[x*binaryImg->nChannels + k]

Since a gray image has only a single channel, we can check if a pixel is white using:

((uchar *)(binaryImg->imageData + y*binaryImg->widthStep))[x] == 255

In terms of speed, this solution will give a worst case time of O(n), but in practice you will not have to look through all pixels.

Tracking user defined points with OpenCV

If you look for a solution that is implemented in opencv the pyramidal Lucas Kanade (PLK) method is quit good, else I would prefer a Particle Filter based tracker.
To improve your tracking performance with the PLK be sure that you have set up the parameters correctly. E.g. for large motion you need a level at ca. 3 or 4. The window should not be to small ( I prefer 17x17 to 27x27). Also keep in mind that the methods needs textured areas to be able to track the points. That means corner like image content (aperture problem).

I would propose to seed a set of points (ps) in a grid around the points (P) you want to track. And than use a foreward - backward threshold to reject falsly tracked points. The motion of your points (P) will be computed by the mean motion of the particular residual point sets (ps).

The foreward backward confidence is computes by estimating the motion from frame 1 to frame 2. (ptList1 -> ptList2). And that from frame 2 to frame 1 with the points of ptList2 (ptList2 -> ptListRef). Motion vectors will be rejected if (|| ptRef - pt1 || > fb_threshold).



Related Topics



Leave a reply



Submit