美文网首页
error: (-215:Assertion failed) n

error: (-215:Assertion failed) n

作者: 林木_lker | 来源:发表于2019-05-21 16:40 被阅读0次

    最近在用opencv做图片差异比较,使用的是网上的示例,其中有一段获取不同点的轮廓时报错了。
    代码:

    thresh = cv2.threshold(diff,0,255,cv2.THRESH_BINARY_INV | cv2.THRESH_OTSU)[1]
    cnts = cv2.findContours(thresh.copy(),cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)
    cnts = cnts[0] if imutils.is_cv2() else cnts[1]
    

    报错信息:
    Traceback (most recent call last):
    File "diff-image.py", line 27, in <module>
    (x,y,w,h) = cv2.boundingRect(c)
    cv2.error: OpenCV(4.1.0) /Users/travis/build/skvark/opencv-python/opencv/modules/imgproc/src/shapedescr.cpp:743: error: (-215:Assertion failed) npoints >= 0 && (depth == CV_32F || depth == CV_32S) in function 'pointSetBoundingRect'

    最后在stackoverflow上找到了解决办法,原来是opencv版本问题造成的。
    解决办法:

    thresh = cv2.threshold(diff,0,255,cv2.THRESH_BINARY_INV | cv2.THRESH_OTSU)[1]
    cnts = cv2.findContours(thresh.copy(),cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)
    cnts = cnts[1] if imutils.is_cv3() else cnts[0]
    

    详细问题解决描述
    https://stackoverflow.com/questions/54734538/opencv-assertion-failed-215assertion-failed-npoints-0-depth-cv-32

    相关文章

      网友评论

          本文标题:error: (-215:Assertion failed) n

          本文链接:https://www.haomeiwen.com/subject/qjbjzqtx.html