0

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 specific marker (on the nose) I need to find the distance of all other markers.

I was trying to use openCV as language to accomplish this and was reading the docs but after a week Im still not able to achieve the objective. Can anyone please guide me in the right direction. If not the whole solution give me a link or a tutorial to follow to give me an idea as to how to accomplish that.

Please refer to my image uploaded. The markers are painted in blue all over the image.This is the image from which the features need to be taken out.

Any help would be appreciated. Thanks.

Here is the code that I tried but it turned out to be badly offtrack.

     //This function threshold the HSV image and create a binary image
Mat GetThresholdedImage(Mat imgRGB){        
    Mat imgThresh;   
    inRange(imgRGB, Scalar(95,110,151), Scalar(112,125,169), imgThresh); 
    return imgThresh;
} 
int main(){
 Mat frame;
 frame = imread("other/test2.jpeg");
 namedWindow("Input");      
 namedWindow("Ball");

 Mat imgRGB=frame.clone();

 Mat imgThresh = GetThresholdedImage(imgRGB);


 imshow("Ball", imgThresh);            
 imshow("Input", frame);

 waitKey(0);
 return 0;
}

Sohaib
  • 4,556
  • 8
  • 40
  • 68
  • 1
    have a look at that [question](http://stackoverflow.com/questions/11095113/how-to-detect-and-match-a-marker-using-opencv-template-matching) there is some good entry point and sample! – alexbuisson Sep 12 '13 at 18:47

2 Answers2

5

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): enter image description here 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:
enter image description here Final result:
enter image description here
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).

cyriel
  • 3,522
  • 17
  • 34
  • I have just one question. How do I find the range. I tried using the HSV but I just couldn't get the range right. Sorry for the late reply I got tied up in a separate project. – Sohaib Sep 17 '13 at 17:08
  • You can read it from bottom of the window(marked on first image) or just create simple application with 6 sliders for H, S, V upper and lower boundary and use it to find boundaries manually. – cyriel Sep 19 '13 at 08:27
  • Can I number all the detected regions? – Sohaib Sep 25 '13 at 15:09
  • 1
    I'm not sure what yu are asking, but probably just need to use function findContours - http://docs.opencv.org/doc/tutorials/imgproc/shapedescriptors/find_contours/find_contours.html – cyriel Sep 29 '13 at 10:55
  • Ill see your link but what I really meant is that I need to mark the markers as say marker1, marker2 .. and so on and then calculate the distances from the marker on the bridge of the nose. So I need the coordinates for all the white blobs dont I? – Sohaib Oct 01 '13 at 13:41
  • Apparently findContour does exactly that. Thanks. Is there someplace where I can reach you a little faster than this site? I have a few doubts. – Sohaib Oct 01 '13 at 14:16
  • You can contact me via email ( cysiek9 [at] gmail.com ), but i can't promise that i will answer very fast :) – cyriel Oct 01 '13 at 23:07
3

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:

  1. Segment the blue markers from the image. Possibly using a threshold on the blue channel to get the those points. They should have a pretty high value in the blue channel.
  2. Since the markers appear to more than one pixel, you could treat the nearby neighbors pixels that are blue as a cluster and find the centroid of each cluster(marker).
  3. From the centroid on the nose tip, computer the distance to each cluster centroid on the face.

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.

bruvel
  • 396
  • 2
  • 6
  • And maybe you can use a hough transformation to detect the blue markers as a circle - so you don't need to use the face detection. – retinotop Sep 13 '13 at 08:36
  • Thanks a lot for you answer bruvei. Ill try solutions. I know this questions means I haven't done my background work well but I just did not know how to start. – Sohaib Sep 13 '13 at 17:33
  • @retinotop could you please elaborate. I need to find the coordinates for the blue marker to find distances. – Sohaib Sep 14 '13 at 14:17
  • @bruvel I tried doing what u told me to. I put a threshold and tried to detect those regions. But the result is badly offtrack. Ill share my code in the question above. – Sohaib Sep 14 '13 at 19:10