0

I'm trying to display an image on screen using OpenCV, but nothing happens - all I see is a black screen.

No error message is received.

I'm using Mac and I have a secondary screen connected. When I run the code, both are turned black for 10 seconds but the image is not displayed. This is the code:

    while True:
        if not os.path.isfile(pic_name):
            print("Wrong path: ", pic_name)
            return

        image = cv2.imread(pic_name, 0)
        if image is not None:

            print(image)

            cv2.imshow('image', image)
            k = cv2.waitKey(1000)

            if k == 27:         # If escape was pressed exit
                cv2.destroyAllWindows()
                break

            break
    return pic_time

Also - when printing the image as nd-array, values are good:

[[  0   3   4 ... 239 220   3]
[  0   2   0 ... 238 219   3]
[  2   6   0 ... 237 218   2]
...
[  0  26 127 ... 175 173   2]
[  0  33 149 ... 169 168   3]
[  3  22 145 ... 167 163   2]]

Thanks!

Jeru Luke
  • 20,118
  • 13
  • 80
  • 87
Cranjis
  • 1,590
  • 8
  • 31
  • 64
  • 1
    Maybe check if your image actually loaded. – Mark Setchell Feb 25 '18 at 22:13
  • @MarkSetchell What do you mean? How can I do that? – Cranjis Feb 27 '18 at 08:47
  • https://stackoverflow.com/a/23628409/2836621 – Mark Setchell Feb 27 '18 at 08:56
  • @MarkSetchell still doesn't work: `while True: if not os.path.isfile(pic_name): print("Wrong path: ", pic_name) return image = cv2.imread(pic_name, 0) if image is not None: print(image) cv2.imshow('image', image) k = cv2.waitKey(1000) return pic_time ` image is not None but I still get a black screen Also, when I print the image it has actual values: `[[180 177 182 ... 205 204 204] [180 176 181 ... 207 207 208] [179 175 180 ... 205 205 205]...` – Cranjis Feb 27 '18 at 09:38
  • Ugh! Pease don't put code in comments - it is hard to read. Rather, click `edit` under your question and update it there. What does `sips` have to say about the image you are using? `sips -g all YourImage.jpg` – Mark Setchell Feb 27 '18 at 09:46
  • @MarkSetchell Sorry, fixed the edit and put the code in the question. sips output: `pixelWidth: 533 pixelHeight: 400 typeIdentifier: public.jpeg format: jpeg formatOptions: default dpiWidth: 72.000 dpiHeight: 72.000 samplesPerPixel: 3 bitsPerSample: 8 hasAlpha: no space: RGB` – Cranjis Feb 27 '18 at 09:59
  • @MarkSetchell Any idea? – Cranjis Mar 01 '18 at 21:00
  • No, I'm stuck too :-( How did you install it? – Mark Setchell Mar 01 '18 at 21:17
  • @MarkSetchell using anaconda.. and I'm using Mac – Cranjis Mar 02 '18 at 16:21

0 Answers0