OpenCV中文网站

 找回密码
 立即注册
搜索
热搜: 安装 配置
查看: 4089|回复: 2

Python-OpenCV程序报错

[复制链接]
发表于 2018-11-5 20:56:52 | 显示全部楼层 |阅读模式
#程序
import cv2
import numpy as np
from matplotlib import pyplot as plt

img = cv2.imread('D:/download/PyCharm/PycharmProjects/5.1.jpg')
img = cv2.medianBlur(img,5)

ret,th1 = cv2.threshold(img,127,255,cv2.THRESH_BINARY)
th2 = cv2.adaptiveThreshold(img,255,
      cv2.ADAPTIVE_THRESH_MEAN_C,
      cv2.THRESH_BINARY,11,2)
th3 = cv2.adaptiveThreshold(img,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C,cv2.THRESH_BINARY,11,2)

titles = ['original image' , 'global thresholding ','Adaptive mean thresholding',
          'adaptive gaussian thresholding']
images = [img,th1,th2,th3]

for i in range(4):
    plt.subplot(2, 2, i+1),plt.imshow(images,'gray')
    plt.title(titles)
    plt.xticks([]),plt.yticks([])
plt.show()
报错提示:Traceback (most recent call last):  File "D:/download/PyCharm/PycharmProjects/1049.py", line 11, in <module>    cv2.THRESH_BINARY,11,2)cv2.error: OpenCV(3.4.3) C:\projects\opencv-python\opencv\modules\imgproc\src\thresh.cpp:1524: error: (-215:Assertion failed) src.type() == CV_8UC1 in function 'cv::adaptiveThreshold'不得其解,求助大佬!
回复

使用道具 举报

发表于 2018-11-5 22:30:00 | 显示全部楼层
请重新整理你提交的代码
回复 支持 反对

使用道具 举报

发表于 2018-11-6 09:12:01 | 显示全部楼层
第一,已经提示你11行报错
第二,进一步报错信息二值化需要单通道,你的输入是彩色图,要做灰度转换
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|OpenCV中文网站

GMT+8, 2024-4-24 18:36 , Processed in 0.009797 second(s), 15 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表