Ask Your Question

AnnaMP's profile - activity

2020-11-13 22:28:04 -0600 received badge  Notable Question (source)
2020-03-23 10:54:23 -0600 received badge  Popular Question (source)
2019-01-31 09:02:09 -0600 received badge  Teacher (source)
2019-01-29 14:29:47 -0600 marked best answer imshow() Python/macOS not showing the image

I'm literally just starting out, but already stuck .. I'm trying to get an image to display, but imshow() only opens an empty window. I don't get any errors, and the program doesn't hang (pressing a key closes the window just fine) - it's just that there is no image in the window.

I know that the image is loaded correctly, because I'm printing out the arrays and image data looks right. Also I can see that the window always has the correct _measurements_ for whichever image file I'm picking.

import numpy as np
import cv2

img = cv2.imread('butterfly.jpg', 0)
print(img)

cv2.imshow('Butterfly', img)
cv2.waitKey(0)
cv2.destroyAllWindows()

Things I have tried (to no avail):

  • using an absolute path instead
  • adding cv2.startWindowThread(); cv2.namedWindow('Butterfly') before the imshow() command
  • reading lots of posts with similar problems

I'm using Python3.6, on macOS (Mojave), cv2 v.4.0.1

Any ideas what I might be doing wrong?

-- Edit -- print(cv2.getBuildInformation()) gives me this:

General configuration for OpenCV 4.0.1 =====================================
  Version control:               unknown

  Extra modules:
    Location (extra):            /tmp/opencv-20190105-31032-o160to/opencv-4.0.1/opencv_contrib/modules
    Version control (extra):     unknown

  Platform:
    Timestamp:                   2019-01-05T01:41:15Z
    Host:                        Darwin 18.2.0 x86_64
    CMake:                       3.13.2
    CMake generator:             Unix Makefiles
    CMake build tool:            /usr/local/Homebrew/Library/Homebrew/shims/mac/super/gmake
    Configuration:               Release

  CPU/HW features:
    Baseline:                    SSE SSE2 SSE3 SSSE3 SSE4_1 POPCNT SSE4_2
      requested:                 DETECT
      disabled:                  SSE4_1 SSE4_2 AVX AVX2
    Dispatched code generation:  SSE4_1 SSE4_2 FP16 AVX AVX2 AVX512_SKX
      requested:                 SSE4_1 SSE4_2 AVX FP16 AVX2 AVX512_SKX
      SSE4_1 (0 files):          +
      SSE4_2 (0 files):          +
      FP16 (0 files):            + FP16 AVX
      AVX (4 files):             + AVX
      AVX2 (11 files):           + FP16 FMA3 AVX AVX2
      AVX512_SKX (1 files):      + FP16 FMA3 AVX AVX2 AVX_512F AVX512_SKX

  C/C++:
    Built as dynamic libs?:      YES
    C++ Compiler:                /usr/local/Homebrew/Library/Homebrew/shims/mac/super/clang++  (ver 10.0.0.10001145)
    C++ flags (Release):         -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -fdiagnostics-show-option -Wno-long-long -Qunused-arguments -Wno-semicolon-before-method-body -ffunction-sections -fdata-sections  -fvisibility=hidden -fvisibility-inlines-hidden -DNDEBUG  -DNDEBUG
    C++ flags (Debug):           -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -fdiagnostics-show-option -Wno-long-long -Qunused-arguments -Wno-semicolon-before-method-body -ffunction-sections -fdata-sections  -fvisibility=hidden -fvisibility-inlines-hidden -g  -O0 -DDEBUG -D_DEBUG
    C Compiler:                  /usr/local/Homebrew/Library/Homebrew/shims/mac/super/clang
    C flags (Release):           -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -fdiagnostics-show-option -Wno-long-long -Qunused-arguments -Wno-semicolon-before-method-body -ffunction-sections -fdata-sections  -fvisibility=hidden -fvisibility-inlines-hidden -DNDEBUG  -DNDEBUG
    C flags (Debug):             -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -fdiagnostics-show-option -Wno-long-long -Qunused-arguments -Wno-semicolon-before-method-body -ffunction-sections -fdata-sections  -fvisibility=hidden -fvisibility-inlines-hidden ...
(more)
2019-01-29 14:29:45 -0600 received badge  Self-Learner (source)
2019-01-29 14:05:30 -0600 answered a question imshow() Python/macOS not showing the image

Update: So it turned out that it was indeed an installation problem. I managed to uninstall Python 3.6, and then with br

2019-01-24 07:57:55 -0600 commented question imshow() Python/macOS not showing the image

Ok, thanks so much for helping me rule out any mistakes in my openCV code, and giving me another idea what to try! I'll

2019-01-24 07:44:03 -0600 commented question imshow() Python/macOS not showing the image

Er, yes, I did have some weird issues during installation ... I installed with 'brew install opencv' and it got installe

2019-01-24 07:21:53 -0600 received badge  Editor (source)
2019-01-24 07:21:53 -0600 edited question imshow() Python/macOS not showing the image

imshow() Python/macOS not showing the image I'm literally just starting out, but already stuck .. I'm trying to get an i

2019-01-24 07:14:36 -0600 commented question imshow() Python/macOS not showing the image

got the cv2.getBuildInformation()) ... but it's a lot ... is there a better way than pasting the whole lot in a comment

2019-01-24 07:14:25 -0600 commented question imshow() Python/macOS not showing the image

got the cv2.getBuildInformation()) ... but it's a lot ... is there a better way than pasting the whole lot in a comment

2019-01-24 07:08:08 -0600 commented question imshow() Python/macOS not showing the image

got the cv2.getBuildInformation()) ... but it's a lot ... is there a better way than pasting the whole lot in a comment

2019-01-24 07:04:04 -0600 commented question imshow() Python/macOS not showing the image

hm, that doesn't make any difference either ... :-( Sorry - overlooked the C++ question - idk ...

2019-01-24 07:02:36 -0600 commented question imshow() Python/macOS not showing the image

hm, that doesn't make any difference either ... :-( Sorry - overlooked the C++ question - idk ... But the print stateme

2019-01-24 06:56:32 -0600 commented question imshow() Python/macOS not showing the image

hm, that doesn't make any difference either ... :-(

2019-01-24 06:23:34 -0600 commented question imshow() Python/macOS not showing the image

Thanks for looking into this! But no, it's not None: print(img) gives me the correct array, and I can even do cv2.imwrit

2019-01-23 17:49:07 -0600 asked a question imshow() Python/macOS not showing the image

imshow() Python/macOS not showing the image I'm literally just starting out, but already stuck .. I'm trying to get an i