Search code examples
pythonopencvmacos-sierra

error after using imshow() in mac


My code:

import cv2
import numpy
import matplotlib

img=cv2.imread('square1.png')
cv2.imshow('FRAME',img)
cv2.waitKey()

Error message:

Traceback (most recent call last):
  File "/Users/tusharsharma/Desktop/image project/test1.py", line 5, in <module> cv2.imshow('FRAME',img)
cv2.error: /Users/travis/build/skvark/opencv-python/opencv/modules/highgui/src/window.cpp:583:
error: (-2) The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Carbon support. 
If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, 
then re-run cmake or configure script in function cvShowImage

OS is macOS Sierra. I had installed OpenCV using homebrew for Python 3.


Solution

  • the main problem was with the configuration of build of OpenCv2 make sure you enter the correct part of your python libraries and Header files for instance the following command will work for OpenCv for Python 3.6.1 cmake -D CMAKE_BUILD_TYPE=RELEASE \ -D PYTHON3_EXECUTABLE=$(which python3) \ -D PYTHON3_INCLUDE_DIR=$(python3 -c "from distutils.sysconfig import get_python_inc; print(get_python_inc())") \ -D PYTHON3_LIBRARY=/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/config-3.4m/libpython3.4.dylib \ -D PYTHON3_LIBRARIES=/Library/Frameworks/Frameworks/Python.framework/Versions/3.4/bin \ -D PYTHON3_INCLUDE_DIR=/Library/Frameworks1/Frameworks/Python.framework/Versions/3.4/Headers \ -D PYTHON3_PACKAGES_PATH=$(python3 -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())") \ -D INSTALL_C_EXAMPLES=OFF -D INSTALL_PYTHON_EXAMPLES=ON \ -D BUILD_EXAMPLES=ON \ -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules ..