Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/324.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/security/4.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_Opencv_Computer Vision_Feature Extraction - Fatal编程技术网

Python 它如何计算opencv中黑色像素轮廓上的立体度?

Python 它如何计算opencv中黑色像素轮廓上的立体度?,python,opencv,computer-vision,feature-extraction,Python,Opencv,Computer Vision,Feature Extraction,坚固度计算方法与面积/凸面外壳面积之比类似: #calculating area from contour area = cv2.contourArea(unicocnt) #calculating hull and hull area hull = cv2.convexHull(unicocnt) hull_area = cv2.contourArea(hull) #solidity solidity = float(area)/hull_area 计算圆形图像时,我得到的所有值都接近

坚固度计算方法与面积/凸面外壳面积之比类似:

#calculating area from contour
area = cv2.contourArea(unicocnt)

#calculating hull and hull area
hull = cv2.convexHull(unicocnt) 
hull_area = cv2.contourArea(hull)

#solidity
solidity = float(area)/hull_area
计算圆形图像时,我得到的所有值都接近1,因此我假设,当我计算轮廓面积时,我计算圆形内部的面积,而不考虑内部是否为白色像素(轮廓为黑色)

图像样本:

代码:

出现此错误时:

if (cv2.pointPolygonTest(hull, unicocnt) >= 0):
TypeError: Required argument 'measureDist' (pos 3) not found
尝试以下算法(伪代码):


我不明白这个问题。正如你所说的问题,你已经自己回答了。问题是,在计算过程中,所有的圆都被认为是黑白像素,而不仅仅是黑色像素的面积!总面积是什么意思?这些是我的区域:8769区Hull区8995.5区M00 8769 M00考虑所有区域的黑白像素不仅黑!对不起,这样不行。我将把我的答案改为你如何自己编写算法。我不实用,我不知道如何在python OpenCVX中转换(x=MinX到MaxX)这个双精度(y=MinY到MaxY)轮廓结构不是有吗?哦,好吧。将MinX和MinY分别设置为0,将MaxX和MaxY分别设置为图像的宽度和高度。cv2.pointPolyContest(hull、unicont、FALSE)(或0..我不知道它是bool还是预期的int。)
ColoredArea = 0
for i in range(0,len(imgbnbin)):
    a = imgbnbin[i]
    for j in range (0, len(a)):
        if (cv2.pointPolygonTest(hull, unicocnt) >= 0):        
            if (getPixel(x,y) == black):
                ColoredArea = ColoredArea +1; 
if (cv2.pointPolygonTest(hull, unicocnt) >= 0):
TypeError: Required argument 'measureDist' (pos 3) not found
int ColoredArea = 0;
for (x=MinX to MaxX)
   for (y=MinY to MaxY)
        if (cv2.pointPolygonTest(hull, pt(x,y)) >= 0)
           if (getPixel(x,y) == black)
               ColoredArea++;