我在 Python OpenCV 中找到了一个 MSER 示例。当我尝试运行它时,当它尝试重塑list
/时出现错误numpy.array
。错误是:
AttributeError:“列表”对象没有属性“重塑”
我该如何解决这个问题?在下面的简单代码中,我注释了错误发生的位置:
import cv2
import numpy as np
img = cv2.imread('../images/Capture2.JPG', 0);
vis = img.copy()
mser = cv2.MSER_create()
regions = mser.detectRegions(img)
hulls = []
for p in regions:
# Error on below line: 'AttributeError: 'list' object has no attribute 'reshape''
hulls.append( cv2.convexHull(p.reshape(-1, 1, 2)) )
# Note a numpy array isn't working either: error: 'ValueError: cannot reshape array of size 2605 into shape (1,2)'
p = np.array(p)
hulls.append( cv2.convexHull(p.reshape(-1, 1, 2)) )
cv2.polylines(vis, hulls, 1, (0, 255, 0))
cv2.imshow('img', vis)
cv2.waitKey(0)
cv2.destroyAllWindows()