imshow should open a window
python process running but no window shows
def show_image(image):
cv2.imshow(mat=image, winname="tt")
# Wait for a key press to exit
cv2.waitKey()
# Close all windows
cv2.destroyAllWindows()
Mac OS Big Sur 11.0.1
opencv-python 4.4.0.46
Tested with 4.4.0.44 - OK
Tested with 4.4.0.40 - OK
Please post the output of cv2.getBuildInformation().
Same issue here on my end.
`'\nGeneral configuration for OpenCV 4.4.0 =====================================\n
Version control: 4.4.0-dirty\n\n
Platform:\n
Timestamp: 2020-11-02T22:28:03Z\n
Host: Darwin 17.7.0 x86_64\n
CMake: 3.18.2\n
CMake generator: Unix Makefiles\n
CMake build tool: /usr/bin/make\n
Configuration: Release\n\n
CPU/HW features:\n
Baseline: SSE SSE2 SSE3 SSSE3 SSE4_1\n
requested: DETECT\n
Dispatched code generation: SSE4_2 FP16 AVX AVX2 AVX512_SKX\n
requested: SSE4_1 SSE4_2 AVX FP16 AVX2 AVX512_SKX\n
SSE4_2 (1 files): + POPCNT SSE4_2\n
FP16 (0 files): + POPCNT SSE4_2 FP16 AVX\n
AVX (4 files): + POPCNT SSE4_2 AVX\n
AVX2 (29 files): + POPCNT SSE4_2 FP16 FMA3 AVX AVX2\n
AVX512_SKX (4 files): + POPCNT SSE4_2 FP16 FMA3 AVX AVX2 AVX_512F AVX512_COMMON AVX512_SKX\n\n
C/C++:\n
Built as dynamic libs?: NO\n
C++ standard: 11\n
C++ Compiler: /usr/local/opt/ccache/libexec/clang++ (ver 9.1.0.9020039)\n
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-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 -O3 -DNDEBUG -DNDEBUG\n
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-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\n
C Compiler: /usr/local/opt/ccache/libexec/clang\n
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-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 -O3 -DNDEBUG -DNDEBUG\n
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-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\n
Linker flags (Release): -Wl,-dead_strip \n
Linker flags (Debug): -Wl,-dead_strip \n
ccache: YES\n
Precompiled headers: NO\n
Extra dependencies: -framework OpenCL /Applications/Xcode-9.4.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/System/Library/Frameworks/Accelerate.framework -lm -ldl ade Qt5::Core Qt5::Gui Qt5::Widgets Qt5::Test Qt5::Concurrent openjp2\n
3rdparty dependencies: ittnotify libprotobuf zlib libjpeg-turbo libwebp libpng libtiff IlmImf quirc ippiw ippicv\n\n
OpenCV modules:\n
To be built: calib3d core dnn features2d flann gapi highgui imgcodecs imgproc ml objdetect photo python3 stitching video videoio\n
Disabled: world\n
Disabled by dependency: -\n
Unavailable: java js python2 ts\n
Applications: -\n
Documentation: NO\n
Non-free algorithms: NO\n\n
GUI: \n
QT: YES (ver 5.13.2)\n
QT OpenGL support: NO\n
Cocoa: YES\n
VTK support: NO\n\n
Media I/O: \n
ZLib: build (ver 1.2.11)\n
JPEG: build-libjpeg-turbo (ver 2.0.5-62)\n
WEBP: build (ver encoder: 0x020f)\n
PNG: build (ver 1.6.37)\n
TIFF: build (ver 42 - 4.0.10)\n
JPEG 2000: OpenJPEG (ver 2.3.1)\n
OpenEXR: build (ver 2.3.0)\n
HDR: YES\n
SUNRASTER: YES\n
PXM: YES\n
PFM: YES\n\n
Video I/O:\n
DC1394: NO\n
FFMPEG: YES\n
avcodec: YES (58.91.100)\n
avformat: YES (58.45.100)\n
avutil: YES (56.51.100)\n
swscale: YES (5.7.100)\n
avresample: YES (4.0.0)\n
GStreamer: NO\n
AVFoundation: YES\n\n
Parallel framework: GCD\n\n
Trace: YES (with Intel ITT)\n\n
Other third-party libraries:\n
Intel IPP: 2020.0.0 Gold [2020.0.0]\n
at: /private/var/folders/nz/vv4_9tw56nv9k3tkvyszvwg80000gn/T/pip-req-build-b4ibzwe2/_skbuild/macosx-10.13-x86_64-3.8/cmake-build/3rdparty/ippicv/ippicv_mac/icv\n
Intel IPP IW: sources (2020.0.0)\n
at: /private/var/folders/nz/vv4_9tw56nv9k3tkvyszvwg80000gn/T/pip-req-build-b4ibzwe2/_skbuild/macosx-10.13-x86_64-3.8/cmake-build/3rdparty/ippicv/ippicv_mac/iw\n
Lapack: YES (/Applications/Xcode-9.4.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/System/Library/Frameworks/Accelerate.framework -lm -ldl)\n
Eigen: YES (ver 3.3.8)\n
Custom HAL: NO\n
Protobuf: build (3.5.1)\n\n
OpenCL: YES (no extra features)\n
Include path: NO\n
Link libraries: -framework OpenCL\n\n
Python 3:\n
Interpreter: /Users/travis/build/skvark/opencv-python/venv/bin/python (ver 3.8.6)\n
Libraries: /Library/Frameworks/Python.framework/Versions/3.8/lib/libpython3.8.dylib (ver 3.8.6)\n
numpy: /private/var/folders/nz/vv4_9tw56nv9k3tkvyszvwg80000gn/T/pip-build-env-gccf63s_/overlay/lib/python3.8/site-packages/numpy/core/include (ver 1.17.3)\n
install path: python\n\n
Python (for build): /System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7\n\n
Java: \n
ant: NO\n
JNI: /Applications/Xcode-9.4.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/System/Library/Frameworks/JavaVM.framework/Headers /Applications/Xcode-9.4.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/System/Library/Frameworks/JavaVM.framework/Headers /Applications/Xcode-9.4.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/System/Library/Frameworks/JavaVM.framework/Headers\n
Java wrappers: NO\n
Java tests: NO\n\n
Install to: /private/var/folders/nz/vv4_9tw56nv9k3tkvyszvwg80000gn/T/pip-req-build-b4ibzwe2/_skbuild/macosx-10.13-x86_64-3.8/cmake-install\n-----------------------------------------------------------------\n\n'`
Thanks, that looks ok. I'm pretty sure this issue has something to do with the Qt version. Qt 5.13.2 ships with current wheels, and based on some fast research, also other projects have had similar issues with it on Big Sur.
To fix this problem, Qt needs to be probably upgraded to 5.15. However, 5.15 has another issue that I cannot fix easily because I do not own a Mac. For more information, see https://github.com/skvark/opencv-python/issues/376. I have asked for help on that issue but nobody seems to be interested so don't hold on your breath waiting for a fix. If there isn't enough interest I will probably drop Qt support from the macOS builds because maintaining it is such a PITA.
Temporary solution is to use opencv-python-headless. Despite its name, it has Cocoa-based GUI functionality enabled since it cannot be disabled in OpenCV macOS builds. Please note that the Cocoa backend is more limited so you can't use all GUI methods which you can use with Qt.
Edit: To add, I have no idea why 4.4.0.40 and 4.4.0.44 work and 46 doesn't. 4.4.0.40 should not be working (at least not on Catalina) unless Apple fixed something in Big Sur.
I also got this problem, but seemed to have solved it on Mac. I compiled OpenCV 4.5.0 from source and made sure to build the Python binding for Python 3. It was quite a pain to make sure that OpenCV doesn't instead build binding for Python 2.7 that comes with MacOS. Here is how to make sure that a Python 3 binding is built:
cd opencv-4.5.0 # Or whichever other version
mkdir build
cd build
BUILD_opencv_python3:BOOL=ON
BUILD_opencv_python2:BOOL=OFF
PYTHON3_EXECUTABLE:FILEPATH=/Users/<username>/anaconda3/bin/python3
PYTHON3_INCLUDE_DIR:PATH=/Users/<username>/anaconda3/include/python3.8
PYTHON3_NUMPY_INCLUDE_DIRS:PATH=/Users/<username>/anaconda3/lib/python3.8/site-packages/numpy/core/include
PYTHON3_DEFAULT_EXECUTABLE:FILEPATH=/Users/<username>/anaconda3/bin/python3
Then click "Configure". CMake will fill in many other variables. It will find Python 2, but you should see that it uses Python 3. If it does use the Python 3 you specified, then click "Generate".
sudo make -j3 # j is for number of processes; there are many files to compile so multithreading helps
sudo make install
These really helped: https://docs.opencv.org/4.5.0/d0/db2/tutorial_macos_install.html
https://answers.opencv.org/question/221044/option-build_opencv_python3-missing-from-cmake-gui/
https://stackoverflow.com/questions/42638342/cannot-install-opencv-3-1-0-with-python3-cmake-not-including-or-linking-python
The problem seems to be with Qt. With pip's precompiled OpenCV 4.4.0.46, I got an error like this You might be loading two sets of Qt binaries into the same process (plus more words in a little paragraph) in the Python console when calling cv2.imshow when running Python in the terminal and no window would show (nothing responds when it's run in PyCharm). I have compiled OpenCV from source for C++ before though without caring about the Python binding (which I installed with pip instead) and the equivalent C++ code worked totally fine. When I compiled OpenCV from source, it was probably able to identify the correct Qt or Cocoa.
By default, OpenCV is installed into /usr/local. I tried to get it to install into /Users/<username>/anaconda3, while import cv2 would work, this interfered with compiling C++ code that uses OpenCV. So I still installed it into /usr/local and copied the cv2 directory of the Python binding (you will see where it is in the make install output in the terminal) into /Users/<username>/anaconda3/lib/python3.8/site-packages. Then both import cv2 and the C++ interface would work. I got cv2.imshow to show the image in a window when running Python in the terminal. For PyCharm projects, I made the global packages available to the virtual env like this: https://stackoverflow.com/questions/52921165/make-a-pycharm-project-inheriting-global-site-packages-after-creating-the-proje (Mac has different interface; go to PyCharm > Preferences) Well, maybe that defeated the purpose of virtual env. Manually copying cv2 to the site-packages of the virtual env also works. Not the most elegant solution, but it worked.
@lambdamoses This repository exists to avoid all that manual stuff you did... If you read the manual build section in README, you can do all that with just a few commands: https://github.com/skvark/opencv-python#manual-builds
For 4.5.0:
git clone --recursive https://github.com/skvark/opencv-python.gitcd opencv-pythonpip wheel . --verboseFor 4.4.0 which is the latest release in PyPI:
pip install --no-binary opencv-python opencv-pythonThese commands will compile this package from sources. Just make sure you use correct pip, Python version is decided via it.
But the easiest way is probably pip install opencv-python-headless if you can stay at 4.4.0.
I was facing the same issue. @skvark's solution for 4.5.0 worked for me
The most recent release (4.5.1.48) drops Qt support on macOS and should fix this issue. If you need Qt support, consider contributing.
@skvark's solution for 4.5.0 worked for me too! Thank you!
Tested with OpenCV-Python 4.5.1, works without issues.
Most helpful comment
@lambdamoses This repository exists to avoid all that manual stuff you did... If you read the manual build section in README, you can do all that with just a few commands: https://github.com/skvark/opencv-python#manual-builds
For 4.5.0:
git clone --recursive https://github.com/skvark/opencv-python.gitcd opencv-pythonpip wheel . --verboseFor 4.4.0 which is the latest release in PyPI:
pip install --no-binary opencv-python opencv-pythonThese commands will compile this package from sources. Just make sure you use correct
pip, Python version is decided via it.But the easiest way is probably
pip install opencv-python-headlessif you can stay at 4.4.0.