Ask Your Question
1

imshow can not correctly show a png file

asked 2018-03-22 11:16:17 -0600

outwalllife gravatar image

updated 2020-10-24 02:15:18 -0600

when I try to imshow a png image description

it show noting.

But I can use the chrome open the png file and show it.

edit retag flag offensive close merge delete

Comments

It shows nothing ? What does it mean? opencv is an image processing library It does not process alpha channel

LBerger gravatar imageLBerger ( 2018-03-22 11:18:47 -0600 )edit

please show your code. most likely, there's something simple missing, like a waitkey().

berak gravatar imageberak ( 2018-03-22 11:28:55 -0600 )edit
2

Well, your image is transparent. So when you display it, every pixel is either background (black) or black. That's why you don't see anything.

kbarni gravatar imagekbarni ( 2018-03-22 12:33:04 -0600 )edit

So how should I display it. I export a pcb file to pdf, and then I open pdf by office word2016, and then I save this picture to png file, and I can not imshow it .

outwalllife gravatar imageoutwalllife ( 2018-03-23 03:02:38 -0600 )edit

you use word for image manipulation ? lol. that sounds bad.

berak gravatar imageberak ( 2018-03-23 03:24:16 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
2

answered 2018-03-23 03:22:23 -0600

berak gravatar image

updated 2018-03-23 03:25:09 -0600

unfortunately, given the weird and complicated pipeline you used, when creating this image, ALL information is in the alpha channel (ONLY!).

so, needs a small detour to make it visible:

im = cv2.imread("platine.png", -1) # keep alpha
alpha = im[:,:,3] # extract it
binary = ~alpha   # invert b/w
cv2.imshow("P",binary)
cv2.waitKey()

imho you should avoid anything with alpha in it, it only causes trouble.

you probably should try to change your pipeline, so it saves a single channel image, with black contours on white bg, instead of trying to mend it later like above.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2018-03-22 11:16:17 -0600

Seen: 8,488 times

Last updated: Mar 23 '18