How can I determine co-ordinates of the lane? - opencv

I am using opencv to determine coordinates the lane between two red lines like this:
Lane-detection:
It is not rectangle so I can't use cv2.rectangle to cover on it.
Does everyone have some ideas?

Related

Detecting contours of predefined shape with OpenCV

I'm working on a project which locates the Machine Readable Zone on ID cards.
For this I need to do some pre processing to extract the ID card from a scanned image which typically are randomly disposed on a white page. I'm able to locate the majority of the cards by using a Histogram equalization with CLAHE before a contour detection. But in some cases the border around the MRZ is totally invisible (white on white) as shown on the attached image.
I'd like to detect rectangle of a predefined shape as I know the shape of the ID card will be always the same but so far I wasn't able to find a way do do something like this with OpenCV.
Basically what I need is to find two rectangle of a fixed ratio that best match the 2 cards on the scan.
I'm wondering if I need to try OpenCV matchers or if there is a simpler way to accomplish this kind of detection.
The solution to you problem is likely going to be matrix transformations. The concept is to pinpoint 4 coordinates on the card that can be easily detected using opencv, such as the the rectangle colored in blue & cyan.
Have coordinates of the card with the predefined shape stored in an array, where a corner of the card is at the 0, 0. Also store the coordinates of the blue * cyan rectangle in an array. With the two arrays you can find the perspective transform of the two arrays using the cv2.getPerspectiveTransform method.
Using the perspective transform found, you can detect the coordinates of the whole card every time you detect the coordinates of the blue & cyan rectangle.

Draw a non intersecting polygon after detecting corners with OpenCV

I have this image:
and I am using cv2.goodFeaturesToTrack to detect the coroners, so now I have this:
The corners are in red and the numbers show the order of which goodFeaturesToTrack got the corners.. for example, corner with number 0 is the first detected one, etc...
If I were to connect the dots based on that order, I would get a messy polygon so I thought of using a function that given a random set of points, it returns them in an order with which the polygon wouldn't intersect..
I found this function and it does exactly what I want.
However, although the polygon doesn't intersect, for this example I am not getting the same shape as the initial one (I am getting a non self-intersecting polygon but a different shape).
Does anyone have an idea to fix this? I was thinking of making cv2.goodFeaturesToTrack return an ordered set of points but I couldn't figure out how to do that.
Thank you so much!
If you want to get the polygon, you can threshold the image and extract the outer contour with findContours, using CV_RETR_EXTERNAL as the mode to obtain the outer contour and CV_CHAIN_APPROX_SIMPLE as the method. CV_CHAIN_APPROX_SIMPLE compresses horizontal, vertical, and diagonal segments and leaves only their end points (see the documentation).
If you want to use corner detection results and arrange them in correct order to make the polygon, you'll have to trace the boundary of the shape and add those corner points into a list as you find them along the boundary. For this, I think you can use findContours with CV_RETR_EXTERNAL and CV_CHAIN_APPROX_NONE to get every pixel. Still, you might not find your detected corner points exactly on the contour returned from findContours, so you'll have to use a proximity threshold.

openCV detect shapes inside contour

Is there a way to detect shapes inside a contour ? On the image you can see give way and no passage signs(triangle on top of circle). Is there a way to detect the circle from this contour? Triangle is easy because of the inner triangle but I cant figure out how to get the circle.
Take a look at Hough Circle Transform.
It is used to detect circles.
Relevant link: http://docs.opencv.org/2.4/doc/tutorials/imgproc/imgtrans/hough_circle/hough_circle.html

Is there an MKSquare in iOS?

I have a bunch of lat/long coordinates and I need to draw a square polygon around each one. Each square will be a set size (e.g. 50x50) with the coordinate in the centre. I see there is a MKCircle class but is there an MKSquare equivalent (I couldn't fine one but that doesn't mean there isn't) and if there isn't, any suggestions on how this could be achieved? I have done some searching and didn't produce any solid suggestions.
I would also like to make the square 3D as in if the map is tilted it would show a height kind of like buildings.
You can use MKPolygon for this. Simply provide four coordinates the correct distance from your center point and the four coordinates will form a square.

How to draw different shapes on an image in openCV?

I am a beginner in OpenCV. I know C++ and Android Programming. I have decided to shift on OpenCV.
In my project, Using OpenCV I am detecting a red color ball through camera and getting its coordinates. Using these coordinates, I want to draw the same line or shape on a separate white image. For example, if the use user moves ball to write the alphabet W in the air, and I have received all the coordinates of ball position, I want to draw W on the separate image. I am not asking for code, but little help and guidance.
Thanks in advance.
If you have the coordinates it is easy. First create your cv::Mat and set it all white.
cv::Mat image;
image.setTo(cv::Scalar(255,255,255));
Then if you have the begin and the end coordinates you can draw a line using opencv line function.
cv::line(image, cv::Point(initial_coords.x, initial_coords.y), cv::Point(end_coords.x, end_coords.y), cv::Scalar(0,0,255));
Finally to do the w use puttext function
cv::putText(image, "text", cv::Point(coords.x, coords.y), cv::FONT_HERSHEY_SCRIPT_SIMPLEX, 2, Scalar::all(255), 3,8);
If you need to erase the window before adding new things use again the
image.setTo(cv::Scalar(255,255,255));

Resources