gpt4 book ai didi

python - opencv+python : Assertion failure when findcontours

转载 作者:太空宇宙 更新时间:2023-11-03 21:34:39 26 4
gpt4 key购买 nike

我正在从事图像处理项目。

我正在使用 opencv 2.4.11 + python 2.7

代码很简单

def preprocessing(src):
src = cv2.resize(src, (0,0), fx=6, fy=6)
kernel = np.ones((5,5), np.uint8)

dilate = cv2.dilate(src, kernel, iterations = 1)
erode = cv2.erode(dilate, kernel, iterations = 1)

cv2.imshow("dilate", dilate)
cv2.imshow("erode", erode)

th, thresh = cv2.threshold(erode, 200, 255, cv2.THRESH_BINARY)
cv2.imshow("thresh", thresh)

contours, hierarchy = cv2.findContours(thresh,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
cv2.drawContours(src,contours,-1,(0,255,0),3)

cv2.imshow("src", src)
cv2.waitKey()


print "==== start image processing ====="
im2 = cv2.imread("training1.png",cv2.CV_LOAD_IMAGE_GRAYSCALE)
preprocessing(im2)

但是 findcontours 返回断言失败

输出是

OpenCV Error: Assertion failed (step[dims-1] == (size_t)CV_ELEM_SIZE(flags)) in create, file /tmp/opencv20160107-29960-t5glvv/opencv-2.4.12/modules/core/src/matrix.cpp, line 236
Traceback (most recent call last):
File "process.py", line 55, in <module>
preprocessing(im2)
File "process.py", line 44, in preprocessing
contours, hierarchy = cv2.findContours(thresh,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
cv2.error: /tmp/opencv20160107-29960-t5glvv/opencv-2.4.12/modules/core/src/matrix.cpp:236: error: (-215) step[dims-1] == (size_t)CV_ELEM_SIZE(flags) in function create

有人可以帮忙吗?非常感谢

最佳答案

代码运行良好。原因是图片文件丢失。

关于python - opencv+python : Assertion failure when findcontours,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37084893/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com