我正在编写一个opencv程序,我在另一个stackoverflow问题上找到了一个脚本:计算机视觉:屏蔽人手
当我运行脚本的答案时,我收到以下错误:
Traceback (most recent call last):
File "skinimagecontour.py", line 13, in <module>
contours, _ = cv2.findContours(skin_ycrcb, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
ValueError: too many values to unpack
Run Code Online (Sandbox Code Playgroud)
代码:
import sys
import numpy
import cv2
im = cv2.imread('Photos/test.jpg')
im_ycrcb = cv2.cvtColor(im, cv2.COLOR_BGR2YCR_CB)
skin_ycrcb_mint = numpy.array((0, 133, 77))
skin_ycrcb_maxt = numpy.array((255, 173, 127))
skin_ycrcb = cv2.inRange(im_ycrcb, skin_ycrcb_mint, skin_ycrcb_maxt)
cv2.imwrite('Photos/output2.jpg', skin_ycrcb) # Second image
contours, _ = cv2.findContours(skin_ycrcb, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
for i, c in enumerate(contours):
area = cv2.contourArea(c)
if area > 1000:
cv2.drawContours(im, contours, …Run Code Online (Sandbox Code Playgroud) 我正在开发一个python脚本来隔离图像中颜色匹配的最大和第二大对象.我已经设法得到最大的物体,在它周围画一个轮廓并画一个盒子.但是,我很难找到找到第二大对象的解决方案.我希望单独检测第二大对象.
import numpy as np
import cv2
font = cv2.FONT_HERSHEY_SIMPLEX
lineType = cv2.LINE_AA
im = cv2.imread('Photos/test.jpg')
im_ycrcb = cv2.cvtColor(im, cv2.COLOR_BGR2HSV)
ball_ycrcb_mint = np.array([0, 90, 100],np.uint8)
ball_ycrcb_maxt = np.array([25, 255, 255],np.uint8)
ball_ycrcb = cv2.inRange(im_ycrcb, ball_ycrcb_mint, ball_ycrcb_maxt)
#cv2.imwrite('Photos/output2.jpg', ball_ycrcb) # Second image
areaArray = []
count = 1
_, contours, _ = cv2.findContours(ball_ycrcb, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
for i, c in enumerate(contours):
area = cv2.contourArea(c)
areaArray.append(area)
areaLargest = np.argmax(areaArray)
areaLargestMax = max(areaArray)
areaLargestCnt = contours[areaLargest]
x, y, w, h = cv2.boundingRect(areaLargestCnt)
if area == …Run Code Online (Sandbox Code Playgroud)