Reputation: 1186
I'm trying to segment a grayscale picture generated from field measurements, that is why it is not a conventional 3-channel picture.
I have tried this piece of code:
import cv2 #this is the openCV library
import numpy as np
# some code to generate img
ret,thresh = cv2.threshold(img ,0,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU)
And it spits out this error:
cv2.error: ..\..\..\modules\imgproc\src\thresh.cpp:719: error: (-215) src.type() == CV_8UC1 in function cv::threshold
I have no idea on how to solve this since the usage seems to be pretty straight forward, so any idea is welcome.
Upvotes: 0
Views: 1403
Reputation: 1186
So indeed the problem is the image type, since it contains double values thay need to be normalized to 0 ~ 255.
in my case 1000 is the maximum value possible
img = cv2.convertScaleAbs(img / 1000.0 * 255)
This worked for me.
Upvotes: 0
Reputation: 5978
The error is due to the following assert statement CV_Assert( src.type() == CV_8UC1 );
in thresh.cpp
, meaning your input image is not of type CV_8UC1
.
So make sure that your generated input image img
is in fact CV_8UC1
(one channel 8-bit image).
Upvotes: 3