I have a series of images. I am posting a sample image here. I need to extract features from the image as the coordinates of 60 markers painted on each image. Then from a sp
It's quite easy to find all markers using code similar to yours - you just have to convert image to HSV colour space and than use inRange function - HSV color space is better for such tasks, because it 'focuses' on colours, not on brightness. This code:
Mat m = imread("D:\\face.jpg"), m2, m3;
cvtColor(m, m, CV_RGB2HSV);
resize(m, m, Size(m.cols/2, m.rows/2));
inRange(m, Scalar(0, 90, 50), Scalar(15, 175, 190), m2);
imshow("qwe", m);
imshow("qwe2", m2);
dilate(m2, m3, Mat());
imshow("qwe", m);
imshow("qwe2", m2);
imshow("qwe3", m3);
waitKey(-1);
return 0;
Few things about this code:
- of course you have to change path to file
- resize is not important - i have used it only, because image is to big for my screen
- values of inRange scalar can be easily found by looking at displayed image in HSV (OpenCV shows each image with 3 channels as RGB image, so it will look a bit weird) - just read the values from bottom of a window(probably you have to build OpenCV with QT for this, otherwise the window won't have this informations): Note - values are in other order than usually(HSV), so if you read for example colour (a, b, c) from the bottom of the screen, you should use Scalar(c, a, b).
Result after inRange:
Final result:
As you can see, there are others objects on images, but there should be easy to detect and erase - just look for markers only in region with face(use face detection) or simply for each contours find it bounding rect and check what percentage of bounding rect area is contour area - if this value is small than drop this contours(because it's not similar to circle).
For a problem like this, there could be multiple solutions to accomplish what you want to do. You could use OpenCV to help you implement the functions yourself. Some suggestions on how to handle this type of problem:
It also depends on a few things. It looks like the shirt in this image has quite a bit of blue, so it would probably get segmented in with the markers. To remove this you could use OpenCV's face detection to find the face then only worry about the found face region.
Also it depends on if you know where the nose marker is. If you can manually select it (can use OpenCV to do this), you can set a seed on the nose marker, then do the previous steps.
If you can't manually select it, based on this image it appears the nose marker is close to the center of the image (if you are using the nose tip). You may be able to find the centroid closest to the image center and use this. Doing this would be dependent on the rest of the images that you would be testing on though. Also, this automatic method of determining the nose marker, may not work as there are other markers that are pretty close. You may pick one of those up instead of the actual nose tip.
As I said this is a pretty subjective problem, there could be many solutions to solve it. These are just a couple of suggestions to maybe help point you in the right direction.