问题描述
所以我需要做的是从普通用户拍摄的图像测量脚长。该图像将包含具有黑色袜子穿着的脚,硬币(或其他已知尺寸的物体)和其他两个物体将在其上的白色纸(例如A4)。
我已经有了什么?
- 我已经使用opencv,但只是简单的项目;
- 我已开始阅读一些关于相机校准的文章(),但仍然不知道我是否要走那么远。
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:对不起我的英语,我真的要改进它: - /
Ps: sorry about my english, I really have to improve it :-/
推荐答案
首先,一些图像获取的东西:
First, some image acquisition things:
- 你能指望黑色袜子和白色背景吗?
- 您可以标准化视角吗?
- 您可以标准化场景的照明吗?
- 最后,如果您缩放(或将相机放得更近),您会得到更好的估计,以便脚部填充更多的图像框架。
- 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.
- Can you standardize the viewing angle? Looking directly down at the foot will reduce perspective distortion.
- Can you standardize the lighting of the scene? That will ease a lot of the processing discussed below.
- 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.)
- 下一个任务是隔离感兴趣区域(ROI)。如果你的相机俯视脚,那么ROI可以限制为白色矩形。我的回答这个Stack Overflow post是一个很好的开始平方/矩形识别:
- 如果脚完全位于白色矩形中,可以剪裁图像到步骤#1中发现的rect。
- 使用阈值函数Binarize图片:。如果您选择阈值参数,您应该可以将图片缩小到黑色区域(黑色像素)和白色区域(非黑色像素)。
- 你可以尝试匹配轮廓,但如果这是我的问题,我会使用边界框为一个更有趣(也可能是鲁棒)解决方案的快速解决方案或时刻。
- 使用cvFindContours黑色(袜子)区域的轮廓:
- 使用cvApproxPoly将轮廓转换为多边形形状
- 对于简单的解决方案,请使用cvMinRect2找到针对袜子形状的任意取向的边界框。框的短轴应与largura.jpg中的线对应,框的长轴应与comprimento.jpg中的线对应。
- 如果您想要更多(可能)的精确度,可以尝试cvMoments来计算形状的时刻。
- 使用cvGetSpatialMoment来确定脚的轴。有关空间时刻的更多信息,请访问:,此处为 http://opencv.willowgarage.com/documentation/
- 在轴已知的情况下,您可以旋转图像,使长轴轴对齐(即垂直)。然后,您可以简单地水平和垂直计算像素,以获得线的长度。注意,在这个面向时间的过程中有几个假设。这是一个有趣的解决方案,但它可能不提供任何更多的准确性 - 特别是因为您的尺寸测量的准确性很大程度上取决于上面讨论的相机定位问题。
- 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?
- 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.
- "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).
- 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.
- Use cvFindContours to find the contours of the black (sock) region: http://opencv.willowgarage.com/documentation/structural_analysis_and_shape_descriptors.html#findcontours
- Use cvApproxPoly to convert the contour to a polygonal shape http://opencv.willowgarage.com/documentation/structural_analysis_and_shape_descriptors.html#approxpoly
- 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
- 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
- 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
- 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.
最后,我提供了到旧的C接口的链接。你可以看看新的C ++接口(我根本没有把我的代码迁移到2.4)
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)
这篇关于使用已知的对象大小从图片中测量对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!