在 mac 中使用 imshow() 后出错
error after using imshow() in mac
我的代码:
import cv2
import numpy
import matplotlib
img=cv2.imread('square1.png')
cv2.imshow('FRAME',img)
cv2.waitKey()
错误信息:
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 是 macOS Sierra。我已经使用自制软件为 Python 3.
安装了 OpenCV
您可以查看这些教程来解决安装 OpenCV 3
for Python 3
for macOS
的问题。
- macOS: Install OpenCV 3 and Python 3.5
- Install OpenCV 3 on macOS with Homebrew (the easy way)
- Resolving macOS, OpenCV, and Homebrew install errors
希望对您有所帮助。
主要问题是 OpenCv2 的构建配置确保您输入 python 库和头文件的正确部分
例如,以下命令适用于 Python 3.6.1 的 OpenCv
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 ..
我的代码:
import cv2
import numpy
import matplotlib
img=cv2.imread('square1.png')
cv2.imshow('FRAME',img)
cv2.waitKey()
错误信息:
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 是 macOS Sierra。我已经使用自制软件为 Python 3.
安装了 OpenCV您可以查看这些教程来解决安装 OpenCV 3
for Python 3
for macOS
的问题。
- macOS: Install OpenCV 3 and Python 3.5
- Install OpenCV 3 on macOS with Homebrew (the easy way)
- Resolving macOS, OpenCV, and Homebrew install errors
希望对您有所帮助。
主要问题是 OpenCv2 的构建配置确保您输入 python 库和头文件的正确部分
例如,以下命令适用于 Python 3.6.1 的 OpenCv
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 ..