calculate distance based on disparity map - c++

I am trying to program a robot that detect obstacles and estimate distance.
I am using computer vision for this task . I calculated the disparity map but I do not know how to detect obstacles and estimate the distance.
what are the steps I need to follow to accomplish this goal?
what are the Open CV's functions I will need to use?
Is there any source codes?

Related

Finding regions of higher numbers in a matrix

I am working on a project to detect certain objects in an aerial image, and as part of this I am trying to utilize elevation data for the image. I am working with Digital Elevation Models (DEMs), basically a matrix of elevation values. When I am trying to detect trees, for example, I want to search for tree-shaped regions that are higher than their surrounding terrain. Here is an example of a tree in a DEM heatmap:
https://i.stack.imgur.com/pIvlv.png
I want to be able to find small regions like that that are higher than their surroundings.
I am using OpenCV and GDAL for my actual image processing. Do either of those already contain techniques for what I'm trying to accomplish? If not, can you point me in the right direction? Some ideas I've had are going through each pixel and calculating the rate of change in relation to it's surrounding pixels, which would hopefully mean that pixels with high rates change/steep slopes would signify an edge of a raised area.
Note that the elevations will change from image to image, and this needs to work with any elevation. So the ground might be around 10 meters in one image but 20 meters in another.
Supposing you can put the DEM information into a 2D Mat where each "pixel" has the elevation value, you can find local maximums by applying dilate and then substract the result from the original image.
There's a related post with code examples in: http://answers.opencv.org/question/28035/find-local-maximum-in-1d-2d-mat/

Gaze tracking with a webcam (openCV and C++)

I'm trying to realize a tool that returns the 2D coordinates of the point that the user is looking at. To do that I'm using openCV, c++ language and a low-cost webcam. I have the 2D coordinates of the center of the two pupils (leftPupil, rightPupil) but I don't know how to find the user's gaze.
I suppose that some information is missing but I don't know the right formula to estimate the gaze.
Is it mandatory to add a laser to get the distance of the user from the webcam? Must I analyze the geometric form of the pupil (if they are circles or elipses)? In this case, how can I detect the case in which they are eliptic or round?
Thank your for your ideas

OpenCV - Shape Distance Method

Currently I am working on a project of detecting defects of product line by comparing the pictures taken by camera. I tried to use OpenCV to extract the edges of the sample picture and the testing picture. However, I am not sure about the next step of comparison. How should I make a conclusion of ok? What measure should I use to compare the pictures?
What I come up in mind is using square difference of every pixels. However, it depends too much on the static environment. I saw the shape distance and Hausdoff distance provided by opencv. Which one should I use? For shape distance, where could I find the logic or methodology behind it? Thanks !!!
I tried to compare two identical pictures (bmp) (just copied from another). The shape distance calculated by shape distance is not zero .... It makes me difficult to set the threshold of shape distance. For Hausdoff distance, the distance calculated is even larger....
Thank you for your kind attention!!

3D Graph cut with shape prior

I'm applying 3D graph cuts based on Yuri Boykov's implementation in C++, itk and boost for min cut/max flow. First I provide some foreground and background seeds. Then I create the graph and assign the weight to the edges using 3D neighborhood (boundary term):
weight=vcl_exp(-vcl_pow(pixelDifference,2)/(2.0*sigma*sigma)),
being sigma a noise function.
Then I assign the source/sink edges depending on the intensity probability histogram (regional term):
this->Graph->add_tweights(nodeIterator.Get(),
-this->Lambda*log(sinkHistogramValue),
-this->Lambda*log(sourceHistogramValue));
So the energy function is E= regional term+boundary term. Then, the cut is compute with Boycov's implementation, but I don't understand exactly how. Anyway, now I want to add a shape prior to the cut, but I have no clue on how to do it.
Do I have to change the weight of the edges?
Do I have to create another energy function? And if so, how?
How could I provide both functions to the mincut/max flow algorithm?
Hope my questions are easily understandable.
Thank you very much,
Karen

Detecting a cross in an image with OpenCV

I'm trying to detect a shape (a cross) in my input video stream with the help of OpenCV. Currently I'm thresholding to get a binary image of my cross which works pretty good. Unfortunately my algorithm to decide whether the extracted blob is a cross or not doesn't perform very good. As you can see in the image below, not all corners are detected under certain perspectives.
I'm using findContours() and approxPolyDP() to get an approximation of my contour. If I'm detecting 12 corners / vertices in this approximated curve, the blob is assumed to be a cross.
Is there any better way to solve this problem? I thought about SIFT, but the algorithm has to perform in real-time and I read that SIFT is not really suitable for real-time.
I have a couple of suggestions that might provide some interesting results although I am not certain about either.
If the cross is always near the center of your image and always lies on a planar surface you could try to find a homography between the camera and the plane upon which the cross lies. This would enable you to transform a sample image of the cross (at a selection of different in plane rotations) to the coordinate system of the visualized cross. You could then generate templates which you could match to the image. You could do some simple pixel agreement tests to determine if you have a match.
Alternatively you could try to train a Haar-based classifier to recognize the cross. This type of classifier is often used in face detection and detects oriented edges in images, classifying faces by the relative positions of several oriented edges. It has good classification accuracy on faces and is extremely fast. Although I cannot vouch for its accuracy in this particular situation it might provide some good results for simple shapes such as a cross.
Computing the convex hull and then taking advantage of the convexity defects might work.
All crosses should have four convexity defects, making up four sets of two points, or four vectors. Furthermore, if your shape was a cross then these four vectors will have two pairs of supplementary angles.