【问题标题】:Problem with the opencv library in pythonpython中opencv库的问题
【发布时间】:2021-05-12 08:48:02
【问题描述】:

这是我的 python 脚本: -def detect_corner(binary_map, intersections):

field_separation = np.copy(binary_map)

cv2.line(field_separation, (intersections[0][0],intersections[0][1]), (intersections[1][0],intersections[1][1]),0, 4)

contours = cv2.findContours(field_separation,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)[1]

print(contours)
#Find the greatest area contour

areas = []


for contour in contours:

    areas.append(cv2.contourArea(contour))

max_index = np.argmax(areas)
max_area = areas.pop(max_index)

remaining_area = sum(areas)

return (remaining_area/max_area)

此代码在另一个系统上正常运行,但当我在我的系统中运行它时,它显示以下错误:

'cv2.error: OpenCV(4.0.0) /io/opencv/modules/imgproc/src/shapeescr.cpp:272: error: (-215:Assertion failed) npoints >= 0 && (depth == CV_32F || depth == CV_32S) 在函数'contourArea''中

你能帮帮我吗?

【问题讨论】:

    标签: python opencv


    【解决方案1】:

    您遇到的问题应该是由于使用了旧版本模块的代码。

    我修改了findContours(...)[]。这应该可以解决您的问题。

    field_separation = np.copy(binary_map)
    
    cv2.line(field_separation, (intersections[0][0],intersections[0][1]), (intersections[1][0],intersections[1][1]),0, 4)
    
    contours = cv2.findContours(field_separation,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)[0]
    
    print(contours)
    #Find the greatest area contour
    
    areas = []
    
    
    for contour in contours:
    
        areas.append(cv2.contourArea(contour))
    
    max_index = np.argmax(areas)
    max_area = areas.pop(max_index)
    
    remaining_area = sum(areas)
    
    return (remaining_area/max_area)
    
    

    如果我对您有帮助,请您接受答案作为解决方案(;

    快乐编码

    【讨论】:

      猜你喜欢
      • 2021-01-02
      • 1970-01-01
      • 2021-04-07
      • 2018-10-27
      • 2022-01-04
      • 2013-01-05
      • 1970-01-01
      • 1970-01-01
      • 2021-06-05
      相关资源
      最近更新 更多