【发布时间】:2015-01-16 19:34:24
【问题描述】:
我用过openCV python,遇到了一个错误。
img_blur = cv2.medianBlur(self.cropped_img,5)
img_thresh_Gaussian = cv2.adaptiveThreshold(img_blur, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, 11, 2)
plt.subplot(1,1,1),plt.imshow(img_thresh_Gaussian, cmap = 'gray')
plt.title("Image"), plt.xticks([]), plt.yticks([])
plt.show()
但我收到了:
cv2.error: /home/phuong/opencv_src/opencv/modules/imgproc/src/thresh.cpp:1280: error: (-215) src.type() == CV_8UC1 in function adaptiveThreshold
我必须安装其他东西吗?
【问题讨论】:
-
输入必须是8bit,单通道。您可能甚至在应用中值模糊之前就忘记了转换为灰度。
-
CV_8UC1 是源类型,而您的
img_blur类型必须不同(即需要更改)。目标需要是相同的类型,即 CV8UC1 或更大的类型,如 CV16UC1,以覆盖可能的精度损失。我在 C++ API 中有类似的问题。