Issue
I am creating an image so:
image = np.empty(shape=(height, width, 1), dtype = np.uint16)
After that I convert the image to BGR model:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2BGR)
I'd like to convert the image now in a dtype = np.uint8
in order to use that image with cv2.threshold()
function. I meant, I would like to convert the image to CV_8UC1
.
Solution
You can use cv2.convertScaleAbs
for this problem. See the Documentation.
Check out the command terminal demo below :
>>> img = np.empty((100,100,1),dtype = np.uint16)
>>> image = cv2.cvtColor(img,cv2.COLOR_GRAY2BGR)
>>> cvuint8 = cv2.convertScaleAbs(image)
>>> cvuint8.dtype
dtype('uint8')
Hope it helps!!!
Answered By - Abid Rahman K
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.