OpenCV TypeError:不支持src数据类型= 19

时间:2018-07-09 09:22:29

标签: python opencv-python

我在执行此代码时遇到问题:import cv2 将numpy导入为np

## (1) Convert to gray, and threshold
colr = np.asarray("C:/Users/Andrei/Documents/Repos/imagerecognition/tmp/3AfbhWLynVqN.jpeg")
gray = cv2.cvtColor(colr, cv2.COLOR_BGR2GRAY)
th, threshed = cv2.threshold(gray, 240, 255, cv2.THRESH_BINARY_INV)

## (2) Morph-op to remove noise
kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (11,11))
morphed = cv2.morphologyEx(threshed, cv2.MORPH_CLOSE, kernel)

## (3) Find the max-area contour
_, cnts, _ = cv2.findContours(morphed, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
cnt = sorted(cnts, key=cv2.contourArea)[-1]

## (4) Crop and save it
x,y,w,h = cv2.boundingRect(cnt)
dst = img[y:y+h, x:x+w]
cv2.imwrite("001.png", dst)

删除图片中的白色背景是任务。但是我收到一个错误TypeError:不支持src数据类型= 19。该怎么办?我需要隐藏图像吗?

0 个答案:

没有答案