Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/358.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用OpenCV测量对象的视长度(以像素为单位)_Python_Python 3.x_Opencv_Computer Vision_Blender - Fatal编程技术网

Python 使用OpenCV测量对象的视长度(以像素为单位)

Python 使用OpenCV测量对象的视长度(以像素为单位),python,python-3.x,opencv,computer-vision,blender,Python,Python 3.x,Opencv,Computer Vision,Blender,我曾经从不同角度/姿势渲染过3D对象的不同图像。对象具有彩色边(如图所示) 现在,我打算使用OpenCV测量橙色和蓝色边缘(Lo和Lb)的长度(以像素为单位)。如果边缘是由单个像素构成的(即,由单个边缘构成的线),这将是一项简单的任务。但是,这里的情况并非如此 非常感谢您的帮助。这里是Python OpenCV中的一种方法 - Read the input - Threshold on one of the colors - Apply morphology to close gap

我曾经从不同角度/姿势渲染过3D对象的不同图像。对象具有彩色边(如图所示)

现在,我打算使用OpenCV测量橙色和蓝色边缘(Lo和Lb)的长度(以像素为单位)。如果边缘是由单个像素构成的(即,由单个边缘构成的线),这将是一项简单的任务。但是,这里的情况并非如此


非常感谢您的帮助。

这里是Python OpenCV中的一种方法

 - Read the input
 - Threshold on one of the colors
 - Apply morphology to close gap
 - Get the contour
 - Get the rotated rectangle
 - Get the length from the rotated rectangle
 - Compute the centerline length
 - Draw the rotated rectangle on the input
 - Draw the centerline on the input
 - Save the results

输入:



阈值图像:

形态图像:

输入时旋转的矩形:

输入时的中心线:

测量:

length= 488.6615295410156
thickness= 9.058079719543457
centerline_length 488.83637344207517


使用cv2.inRange()设置颜色阈值。然后得到轮廓线。然后使用cv2.minareact()获取旋转的边界框。这将返回该区域的长度、宽度和角度。对其他颜色执行相同操作。是否要求用户拾取点?让blender在投影到屏幕上后将你的物体的角倾倒?@ChristophRackwitz我无法得到它:/这看起来很整洁。是否可以应用于非结构化边(如其他3条边)?是的,您可以通过颜色和形态学设置阈值,将其清理成一条直线或四边形。如果可以这样做,则可以获得旋转的边界框。或者如果它们足够薄,只需计算非零像素。仔细观察您的原始图像,蓝色和绿色区域很好,但顶部的红色边缘不是干净的、恒定的红色。另一种方法是在较大的主四边形区域上设置阈值。然后获取轮廓,然后使用approxPolyDP()将顶点数减少到适当的四边形。然后从顶点计算4条边的长度。
length= 488.6615295410156
thickness= 9.058079719543457
centerline_length 488.83637344207517