5

So what I need to do is measuring a foot length from an image taken by an ordinary user. That image will contain a foot with a black sock wearing, a coin (or other known size object), and a white paper (eg A4) where the other two objects will be upon. What I already have? -I already worked with opencv but just simple projects; -I already started to read some articles about Camera Calibration ("Learn OpenCv") but still don't know if I have to go so far.

What I am needing now is some orientation because I still don't understand if I'm following right way to solve this problem. I have some questions: Will I realy need to calibrate camera to get two or three measures of the foot? How can I find the points of interest to get the line to measure, each picture is a different picture or there are techniques to follow?

Ps: sorry about my english, I really have to improve it :-/

2
  • Can you add a representative image? The answer below takes care of the size estimation, but does not address your "points of interest" question. Several methods for feature identification exist, and an image (with desired features) would assist. Jul 9, 2012 at 18:41
  • First of all thanks for quick response. imagine something like take: dl.dropbox.com/u/8286271/comprimento.jpg dl.dropbox.com/u/8286271/largura.jpg I have these two pictures and what I have to do is measure length and width of the foot. But my question is how to find this lines? Is there some method to find these points?
    – mar
    Jul 10, 2012 at 12:06

4 Answers 4

4

First, some image acquisition things:

  1. Can you count on the black sock and white background? The colors don't matter as much as the high contrast between the sock and background.
  2. Can you standardize the viewing angle? Looking directly down at the foot will reduce perspective distortion.
  3. Can you standardize the lighting of the scene? That will ease a lot of the processing discussed below.
  4. Lastly, you'll get a better estimate if you zoom (or position the camera closer) so that the foot fills more of the image frame.

Analysis. (Note this discussion will directed to your question of identifying the axes of the foot. Identifying and analyzing the coin would use a similar process, but some differences would arise.)

  1. The next task is to isolate the region of interest (ROI). If your camera is looking down at the foot, then the ROI can be limited to the white rectangle. My answer to this Stack Overflow post is a good start to square/rectangle identification: What is the simplest *correct* method to detect rectangles in an image?
  2. If the foot lies completely in the white rectangle, you can clip the image to the rect found in step #1. This will limit the image analysis to region inside the white paper.
  3. "Binarize" the image using a threshold function: http://opencv.willowgarage.com/documentation/cpp/miscellaneous_image_transformations.html#cv-threshold. If you choose the threshold parameters well, you should be able to reduce the image to a black region (sock pixels) and white regions (non-sock pixel).
  4. Now the fun begins: you might try matching contours, but if this were my problem, I would use bounding boxes for a quick solution or moments for a more interesting (and possibly robust) solution.
  5. Use cvFindContours to find the contours of the black (sock) region: http://opencv.willowgarage.com/documentation/structural_analysis_and_shape_descriptors.html#findcontours
  6. Use cvApproxPoly to convert the contour to a polygonal shape http://opencv.willowgarage.com/documentation/structural_analysis_and_shape_descriptors.html#approxpoly
  7. For the simple solution, use cvMinRect2 to find an arbitrarily oriented bounding box for the sock shape. The short axis of the box should correspond to the line in largura.jpg and the long axis of the box should correspond to the line in comprimento.jpg. http://opencv.willowgarage.com/documentation/structural_analysis_and_shape_descriptors.html#minarearect2
  8. If you want more (possible) accuracy, you might try cvMoments to compute the moments of the shape. http://opencv.willowgarage.com/documentation/structural_analysis_and_shape_descriptors.html#moments
  9. Use cvGetSpatialMoment to determine the axes of the foot. More information on the spatial moment may be found here: http://en.wikipedia.org/wiki/Image_moments#Examples_2 and here http://opencv.willowgarage.com/documentation/structural_analysis_and_shape_descriptors.html#getspatialmoment
  10. With the axes known, you can then rotate the image so that the long axis is axis-aligned (i.e. vertical). Then, you can simply count pixels horizontally and vertically to obtains the lengths of the lines. Note that there are several assumptions in this moment-oriented process. It's a fun solution, but it may not provide any more accuracy - especially since the accuracy of your size measurements is largely dependent on the camera positioning issues discussed above.

Lastly, I've provided links to the older C interface. You might take a look at the new C++ interface (I simply have not gotten around to migrating my code to 2.4)

3

Antonio Criminisi likely wrote the last word on this subject years ago. See his "Single View Metrology" paper , and his PhD thesis if you have time.

0
0

You don't have to calibrate the camera if you have a known-size object in your image. Well... at least if your camera doesn't distort too much and if you're not expecting high quality measurements.

A simple approach would be to detect a white (perspective-distorted) rectangle, mapping the corners to an undistorted rectangle (using e.g. cv::warpPerspective()) and use the known size of that rectangle to determine the size of other objects in the picture. But this only works for objects in the same plane as the paper, preferably not too far away from it.

1
  • So calibration is only a solution if I need more quality in measurements. Let me check if I understand your solution: first I have to detect a white rectangle that maps the contours of the known object (eg: coin). Second, once I know the scale between width lenght, I have to distort the effect caused by perspective with cv::warpPerspective(). After this any measuring can be made.
    – mar
    Jul 10, 2012 at 12:05
0

I am not sure if you need to build this yourself, but if you just need to do it, and not code it. You can use KLONK Image Measurement for this. There is a free and payable versions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.