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.
Related
I'm trying to detect a photograph in front of the screen with OpenCV (using a webcam). I am using the following code, which uses findContours() to detect rectangles (which for my purpose would count as a photograph.
https://github.com/opencv/opencv/blob/master/samples/cpp/squares.cpp
This works well, but findContours expects a white background against black, so the image needs to be inverted. I tried changing the threshold, but i still can't get it to detect a photograph.
Am i going about this the right way or would there be a better approach to this.
Thank you for your time!
I´m making a small project in C++ using OpenCV and Dlib. This is a pipeline:
Load image with 2 faces
Detect both faces
Find face Landmarks using Dlib shape predictor
Create masks using these landmarks
Warp masks and images using both faces landmarks
Blend all images (original, and 2 warped)
Correct colors of switched faces
Has somebody an idea how could I correct colors of that switched faces to approximately match original face?
After using seamlessClone I get this result. The problem is that I can't accuratelly choose argument center for seamlessClone. I used this code to get centers
Moments m = moments((mask>=50), true);
Point center(m.m10/m.m00, m.m01/m.m00);
I get this result.
As you can see first face is aligned perfectly but second not :( On other images it is much worse.
Any Idea what point to use as center?
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.
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)?
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.