python: OpenCV depth of image unsupported (CV_64F)

前端 未结 1 820
Happy的楠姐
Happy的楠姐 2020-12-19 00:53

So, I\'m trying to show a binary picture with only black and white using this code:

import cv2
import numpy as np

x_img = cv2.imread(\"lenac.tif\")

x_img_g         


        
1条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-19 01:17

    try cv2.imshow("", y.astype('float32')) or cv2.imshow("", y.astype('uint8') * 255)

    CV_64F means the numpy array 'dtype' is 64bit floating-point opencv only works with 'float32' (32-bit floating point) where image range for imshow is 0.0-1.0 or 'uint8' (unsigned 8-bit) 0-255

    Since y was a bool, converting to a number means converting True to 1

    for float32, that is fine because 1 is max for imshow range

    if you use uint8, that means your trying to display pixels of value 1/255 which will be barely visible, so you can multiply by 255 to bring those pixels to max and appear as bright white pixels

    0 讨论(0)
提交回复
热议问题