简体   繁体   中英

cv2.imshow() argument format?

I am modifying the pixels of an image I read via a camera and I am trying to see it on the screen using imshow() , but I end up getting a black screen each time. The only way it works is if I save it first(using imwrite() and then read it again (using imread() )

This yields a black screen:-

def foo(im):
    cv2.show(im)
    cv2.waitKey(10)

ret_im = some_fn(some_image)
foo(ret_im)

Whereas, this gives the correct image:-

def foo(im):
    cv2.show(im)
    cv2.waitKey(10)

ret_im = some_fn(some_image)
cv2.write("some_name.png",ret_im)
ret_im = cv2.read("some_name.png")
foo(ret_im)

The original image also works like a charm. Eg:

def foo(im):
    cv2.show(im)
    cv2.waitKey(10)

foo(some_image)

I think, this has something to do with the input data format. I have tried matching it with the some_image type, by modifying the image.

I must mention here that I am modifying the image treating it as a list and at the end, converting it to numpy array using: numpy.array(list_name)

So, it can be considered as working with :

def foo(im):
    cv2.show(im)
    cv2.waitKey(10)

ret_im = numpy.array(some_fn(some_image))
foo(ret_im) 

The image format required "uint8" numbers. I was using int32 numbers which was causing the issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM