2017-03-22 93 views
1

您好我對OpenCV相當陌生,我試圖在我的Mac上獲取OpenCV演示代碼模糊檢測,但每次運行時都會出現錯誤碼。打開CV libgtk2.0-dev和pkg-config錯誤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/

回答

0

你可能會使用opencv-python,它不支持許多功能的教程。您必須卸載opencv-python,然後重新安裝或重建OpenCV。

pip uninstall opencv-python 

在Mac OS上,您可以重新安裝的OpenCV與

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

確保您使用的是正確的Python,你可能有不同版本的Python有兩種釀造,pyenv,或蟒蛇安裝。檢查which python您是通過執行此使用:

which python 

其中/usr/local/bin/python是釀造的,你就會知道在路徑中提到的關鍵字等。