First time here? Check out the FAQ!
1

How to authorize the camera on MacBook?

I am learning a bit of OpenCV and have a simple program that grabs images off the Macbook camera and does simple motion detection. I can run it in iTerm2 fine and it works but it fails as "not authorized" when run under Wing debug.

Is there a way to authorize the Wing debug to acess the camera? [OS=Big Sur (11.3 Beta (20E5196f))]

Here is what I see in the Debug I/O window:

OpenCV: not authorized to capture video (status 0), requesting... /Applications/WingPro.app/Contents/Resources/bootstrap/launch-env.sh: line 10: 44258 Abort trap: 6 ${WING_ACTIVATE_PYTHON} "$@"

Bill Waggoner's avatar
145
Bill Waggoner
asked 2021-03-15 11:12:35 -0600, updated 2021-03-15 11:16:00 -0600
edit flag offensive 0 remove flag close merge delete

Comments

If you open macOS System Preferences and go to Security & Privacy and then under the Privacy tab select Camera, is anything listed as having requested access? Usually a dialog should pop up but if you denied access then I think it lists the app here. Note that it may list Python and not OpenCV but I'm not sure.

Wingware Support's avatar Wingware Support (2021-03-15 12:16:40 -0600) edit

No, that's the first place I looked and there is nothing requested. Neither python nor Wing is listed, checked or unchecked. However, iTerm2 IS listed and checked because when I first ran the app it did request access to the camera with a pop-up dialog.

When I import cv2 and cap=cv2.VideoCapture(0) in the Python Shell window I also get the failure:

Python 3.9.2 (default, Feb 24 2021, 13:26:09) [Clang 12.0.0 (clang-1200.0.32.29)] Type "help", "copyright", "credits" or "license" for more information. import cv2 cap = cv2.VideoCapture(0) OpenCV: not authorized to capture video (status 0), requesting... aborted (disconnected)

That fails and I get a python crash notifiecation:

``` Process: Python [22125] Path: /usr/local/Cellar/python@3.9/3.9.2_1/... Identifier: Python Version: 3.9.2 (3.9.2) Code Type: X86-64 (Native) Parent Process: WingPro [21954] Responsible ... (more)

Bill Waggoner's avatar Bill Waggoner (2021-03-16 11:50:19 -0600) edit

macOS uses the .app that launches your script as the application that needs permission, so it would be iTerm2 when laughing from it and Wing when debugging (or executing) from Wing. A dialog asking for permission should be displayed the first time the .app tries to use the camera, but apparently this doesn't always work. A way to reset the permissions is explained at https://apple.stackexchange.com/quest...

Wingware Support's avatar Wingware Support (2021-03-16 12:51:00 -0600) edit

Well, that didn't change anything. I used tccutil to reset Camera for com.wingware.wingpro and it reported success. But I still get the python failure and no prompt for authorizing the Camera. I did restart Wing after doing the reset ...

Bill Waggoner's avatar Bill Waggoner (2021-03-16 19:03:16 -0600) edit

Does it work if you use an external console? The OS may determine that the requesting app is the terminal in this case.

Wingware Support's avatar Wingware Support (2021-03-17 10:09:46 -0600) edit
add a comment see more comments

1 Answer

1

I see the same problems that you do. Two workarounds:

1) Use an external console by using the Options button in the Debug I/O tool, selecting Configure External Console, and enabling the external console. This allows access to the camera in a program being debugged but not the Python Shell tool, assuming access is allowed in the terminal.

2) Run Wing from a terminal window via a /Applications/WingPro.app/Contents/Resources/wing command line (or the equivalent). In this case, Wing seems to inherit access permissions from the terminal application, at least under macOS 11.2.2

We'll try to fix the permissions issue in a future Wing release.

Wingware Support's avatar
4.2k
Wingware Support
answered 2021-03-18 09:50:57 -0600
edit flag offensive 0 remove flag delete link

Comments

Thanks, I'll use one of those methods until you can (if you can ... Apple, you know ...) get it fixed.

OK, I tried External Console, configuring that isn't completely obvious but I was able to get a session started. But, just to throw a Monkey Wrench into the works, I use a Virtual Environment and this debug doesn't appear to activate it. Is there documentation on that? Otherwise I'll run Wing from my iTerm2 session when I need to do debugging inside Wing.

Nevermind ... I found the virtualenv workaround in the Help. I am using the venv's python executable in the Project Properties setting and it's working fine ... Thanks!

Bill Waggoner's avatar Bill Waggoner (2021-03-23 21:20:54 -0600) edit

Yes, setting Python Executable to Command Line and using the venv's Python is the way to go in this case due to the awkwardness of starting the process in the external console combined with the awkwardness of activating the env. We'll try to fix that.

I suspect the OpenCV crash is not Apple's fault and if it didn't crash you would get a dialog asking permission to use the camera, with app probably set to the Python you are using. It must be OpenCV making some sort of environment assumptions but I'm not sure what. I'm not sure why terminal environment (e.g. setting TERM differently, or whatever it is) would change anything relevant to what OpenCV does.

Wingware Support's avatar Wingware Support (2021-03-24 07:58:27 -0600) edit
add a comment see more comments

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss.

Add Answer