OpenCV C++ set ROI from a rectangular area - c++

Anyone know how to set ROI based on image bellow?
I used Hough Transform to detect the white line and draw the red line into the image.
What I need to do is to set the ROI in the rectangle.
Since Hough Transform unable to get location of each rectangle and the main problem is I cannot defined the location (x,y) manually.
Any solution that able to auto detect the rectangle and set the ROI?
Anyone can give some idea for me or the code can be use?
Please forgive my poor english and thank you.

this blog post is very good in explaining how to find a rectangle with the hough transform and it has also some c++ code with opencv 2 API.
The approach is to find lines, intersect them, and find the rectangle. In your case you will have more rectangles and so it's a little bit more complicated..
But if you manage to obtain such image.. why don't use just some threshold and find connected regions (aka blob)?

Related

How to crop out multiple contours in OpenCV?

Can someone guide me in cropping the contours area I found in RGB format?
I am going to separate the contours group and save it into area for Recognition.
I am using C++ with OpenCV library.
Is using ApproxPoly() the right direction?
Sorry for my bad English as I am not native English Speaker.
Edit: #api5, sorry for the unclear question. I want to extract to contour content for coin recognition. What I am trying to implement is crop out as many background as I can before I use Hough Circle Transform to detect the coin.
While separating the coins is also my goal, I am still trying to configure the erode mask. Maybe I will try to use homomorphic filter so that I dont need to use unmask sharping to improve the coin contrast.
I think I found my lead in Grabcut algorithm. Will be back once it works as I intended.
Original Image
Found Contours image

Shape Detection Using OpenCv

I am working on Image Processing and for that i am using OpenCV Library in c++.
I have one image in which i want to detect particular shape and mainly want its point.
I have below image , where four black corners are there.I want to detect four corner points as i have drawn with red color.
And please note that image can be at any angle or position. Not straight always.
I have tried cv::threshold, canny, findContours, minAreaRect but I am not getting expected output.
Please anybody can help me.Thanks in Advance.
OpenCV has a function to detect corners using the Harris-Stephens method, here is a tutorial with C++ code example.

Finding individual center points of circles in an image

I am using open CV and C++. I have a completely dark image which has 3 colored points on it. I need their center coordinates. If I have only one colored point in the dark image, it will automatically display its center coordinate. However,if I take as input the dark image with the 3 colored points,my program will make an average if those 3 coordinates and return the center of the 3 colored points together,which is my exact problem. I need their individual center coordinates.
Can anyone suggest a method to do that please. Thanks
Here is the code http://pastebin.com/RM7chqBE
Found a solution!
load original image to grayscale
convert original image to gray
set range of intensity value depending on color that needs to be detected
vector of contours and hierarchy
findContours
vector of moments and point
iterate through each contour to find coordinates
One of the ways to do this easily is to use the findContours and drawContours function.
In the documentation you have a bit of code that explains how to retrieve the connected components of an image. Which is what you are actually trying to do.
For example you could draw every connected component you will find (that means every dot) on it's own image and use the code you already have on every image.
This may not be the most efficient way to do this however but it's really simple.
Here is how I would do it
http://pastebin.com/y1Ae3e2V
I'm not sure this works however as I don't have time to test it but you can try it.

How can I find ROI and detect markers inside?

I'm a beginner in computer vision. I have a question about detection and tracking. I want to detect the white rectangle in the image below, to determine the interesting area and to detect the contour of the red markers.
But I don't want to make use of color information to detect the markers.
Can anyone give me suggestions on how to do this?
If you want to just detect the circles, an adapted Hough Tranfrom should work.
You can find the contours with CvFindContours and use CvApproxPoly() to find the rectangle. You can find a good example of how to use this function to find rectangles here and adapt it to your situation. To find the circles I would advise to do something with the ratio between the arcLength and the area of the contours you find as for circles this ratio is very specific. To find the arcLength use cvArcLength(CvSeq* c) to find the area use cvContourArea(CvSeq* c) while going through the contours in a for loop.

Extract Rectangle From Contour OpenCV

after making some edge and corner detection and then find contours i have this output.
how i can crop this image and return only this rectangle using openCV
EDIT:
i tried cvBoundingRect and then setimageROI but the output image still having some background but i want the rectangle only
Thank You.
i hope you need the rectangle area you selected.
For this you need to make another grayscale image, let us call it 'mask'. Then draw the rectangle contour obtained on it and fill it with white (255,255,255). You will obtain an image like this ( all images hand-edited in paint program):
Now just have an bitwise_and operation on both the images. You will get result as this:
**NB:**Now if it is not the one you wanted, instead you wanted this kind of selection, You can find information about it in this SOF question (thanks to karl philip for the link) .
I guess Mustafa wants to get the box automatically? If not, please accept Abid's answer and ignore this one.
Otherwise:
As I don't know how far it should generalize, for this specific image, do hough transform, which gives you straight lines. However the line at the bottom can become false positive. But with some post processing, e.g. blur, dilate, you will be able to get rid of it. Or you could use the knowledge that the lines build a rectangle.