gpt4 book ai didi

python - 打开CV libgtk2.0-dev和pkg-config报错mac

转载 作者:太空宇宙 更新时间:2023-11-03 23:14:17 24 4
gpt4 key购买 nike

您好,我是 OpenCV 的新手,我正在尝试获取 OpenCV 演示代码以在我的 Mac 上运行模糊检测,但每次运行代码时都会出错。

这是我尝试运行的代码:

    # import the necessary packages
from imutils import paths
import argparse
import cv2

def variance_of_laplacian(image):
# compute the Laplacian of the image and then return the focus
# measure, which is simply the variance of the Laplacian
return cv2.Laplacian(image, cv2.CV_64F).var()


# construct the argument parse and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--images", required=True,
help="path to input directory of images")
ap.add_argument("-t", "--threshold", type=float, default=100.0,
help="focus measures that fall below this value will be considered 'blurry'")
args = vars(ap.parse_args())
# loop over the input images
for imagePath in paths.list_images(args["images"]):
# load the image, convert it to grayscale, and compute the
# focus measure of the image using the Variance of Laplacian
# method
image = cv2.imread(imagePath)
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
fm = variance_of_laplacian(gray)
text = "Not Blurry"

# if the focus measure is less than the supplied threshold,
# then the image should be considered "blurry"
if fm < args["threshold"]:
text = "Blurry"

# show the image
cv2.putText(image, "{}: {:.2f}".format(text, fm), (10, 30),
cv2.FONT_HERSHEY_SIMPLEX, 0.8, (0, 0, 255), 3)
cv2.imshow("Image", image)
key = cv2.waitKey(0)

我通过执行来运行代码:

python detect_blur.py --images images

这是我的终端输出:

OpenCV Error: Unspecified error (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 cvShowImage, file /Users/travis/build/skvark/opencv-python/opencv/modules/highgui/src/window.cpp, line 583
Traceback (most recent call last):
File "detect_blur.py", line 37, in <module>
cv2.imshow("Image", image)
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

我已经安装了 GTK+ 和 pkg-config,但我仍然遇到同样的错误。我不确定下一步该怎么做。我相当有信心问题不在于代码,而在于安装

这是我安装 OpenCV 所遵循的教程 http://www.pyimagesearch.com/2016/12/19/install-opencv-3-on-macos-with-homebrew-the-easy-way/

最佳答案

您可能正在使用 opencv-python ,它不支持很多功能。您必须卸载 opencv-python,然后重新安装或重建 OpenCV。

pip uninstall opencv-python

在 mac OS 上,您可以重新安装 OpenCV

brew uninstall opencv3
brew install opencv3 --with-ffmpeg -v

确保您使用的是正确的 Python,您可能使用 brew、pyenv 或 anaconda 安装了不同版本的 Python。通过执行此检查 which python :

which python

其中 /usr/local/bin/python 来自 brew,您将通过路径中显示的关键字了解其他内容。

关于python - 打开CV libgtk2.0-dev和pkg-config报错mac,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42964766/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com