OpenCV Python Scripts Mac “aborts”

天大地大妈咪最大 提交于 2019-11-26 23:33:02

问题


So I'm just trying to run the basic OpenCV program

    import numpy as np
    import cv2

    cap = cv2.VideoCapture(0)

    while(True):
        # Capture frame-by-frame
        ret, frame = cap.read()

        # Our operations on the frame come here
        gray = cv2.cvtColor(frame, cv2.COLOR_BGR2BGRA)

        # Display the resulting frame
        cv2.imshow('frame',frame)
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break

    # When everything done, release the capture
    cap.release()
    cv2.destroyAllWindows()

But for some reason when I try to run it (with python 2 or 3) I get this weird abort statement

    [1]    74309 abort      python3 index.py

(I'm guessing the 5 digit number is the PID) However, it does work if I pass in a path to an already existing video in the VideoCapture function. I am a beginner in all of this so I'm not really sure what the problem is

Thanks :)


回答1:


I found the solution! I tried running the script using the default terminal that comes with mac and it worked :) So it seems there was some weird issue with the third party terminal (iTerm) I was using




回答2:


You have to authorize iTerm to access the camera (in System Preferences). By default, neither Terminal nor iTerm has this permission. macOS Mojave just asks to allow iTerm and your Python program works fine! It's not a problem with iTerm, or maybe was a problem.



来源:https://stackoverflow.com/questions/52634009/opencv-python-scripts-mac-aborts

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!