【发布时间】:2019-11-27 15:17:14
【问题描述】:
我正在尝试将图像裁剪到轮廓的边界。我从这个answer 中找到了一个代码
mask = np.zeros_like(image)
cv2.drawContours(mask, [c], -1, 255, -1)
out = np.zeros_like(image)
out[mask == 255] = image[mask == 255]
(y, x) = np.where(mask == 255)
(topy, topx) = (np.min(y), np.min(x))
(bottomy, bottomx) = (np.max(y), np.max(x))
out = out[topy: bottomy + 1, topx:bottomx + 1]
crop_img = image[topy: bottomy + 1, topx:bottomx + 1]
cv2.imshow("croppedd", crop_img)
c 是一个轮廓。
我收到如下错误:
Traceback (most recent call last):
File "detect_shapes.py", line 66, in <module>
(y, x) = np.where(mask == 255)
ValueError: too many values to unpack (expected 2)
如何解决我的问题?
- Python 3.7 版
- OpenCV 版本 3.4.4
我认为这与我的形象无关,但这里是我的形象;
【问题讨论】:
标签: python-3.x numpy opencv