python3调用opencv报错:TypeError: Expected cv::UMat for argument 'array’
def measure_object(image):
gray = cv.cvtColor(image, cv.COLOR_RGBA2GRAY)
ret, binary = cv.threshold(gray, 0, 255, cv.THRESH_BINARY | cv.THRESH_OTSU)
print("ret:%s" % ret)
cv.imshow("binary image", binary)
contours, hireachy = cv.findContours(binary, cv.RETR_EXTERNAL, cv.CHAIN_APPROX_SIMPLE)
for contour in enumerate(contours):
# area = cv.contourArea(contour) #得到第几个轮廓面积
x, y, w, h = cv.boundingRect(contour) #得到外接矩形的大小
#求取几何矩
mm = cv.moments(contour)
# type(mm)
cx = mm['m10']/mm['m00']
cy = mm['m01'] / mm['m00']
cv.circle(image, (np.int(cx), np.int(cy)), 3, (0, 0, 255), -1)
cv.rectangle(image, (x, y), ((x+w), (y+h)), (0, 0, 255), 2)
cv.imshow("measure_contours", image)
print("-------hello python-------")
src = cv.imread('pic\\sample2.jpg')
# cv.namedWindow("input image", cv.WINDOW_AUTOSIZE)
cv.imshow('sample2', src)
measure_object(src)
cv.waitKey(0)
cv.destroyAllWindows()
报错如下:
查询了cv.boundingRect() 方法是返回 四个参数没错,请教一下大神。