Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
123 views
in Technique[技术] by (71.8m points)

python - Failure to use adaptiveThreshold: CV_8UC1 in function adaptiveThreshold

I have used openCV python and encountered an error.

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()

but I received:

cv2.error: /home/phuong/opencv_src/opencv/modules/imgproc/src/thresh.cpp:1280: error: (-215) src.type() == CV_8UC1 in function adaptiveThreshold

Do I have to install something else?

question from:https://stackoverflow.com/questions/27014207/failure-to-use-adaptivethreshold-cv-8uc1-in-function-adaptivethreshold

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

you should load your file like this

src.create(rows, cols, CV_8UC1);
src = imread(your-file, CV_8UC1);

and after that

adaptiveThreshold(src, dst, 255, ADAPTIVE_THRESH_GAUSSIAN_C, THRESH_BINARY, 75, 10);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...