Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5

Python on Mac cannot access the webcam

#1
Exclamation 
I'm trying to control the offline robot using input from the camera. The program works well on my windows system. However, the program is not running on my Mac. It is able to open a video file though

import cv2

cap = cv2.VideoCapture(0)
#cap = cv2.VideoCapture('/Users/riddhamanna/Documents/RoboDK/ymaze.mp4')

while(True):
    ret, img = cap.read()
    cv2.imshow('frame',img)
    if cv2.waitKey(1) & 0xFF == 27:#ord('q'):
        break

cap.release()
cv2.destroyAllWindows()
print("Hello World!")


Attached Files Thumbnail(s)
       
#2
This issue is related to OpenCV. I believe the id of your camera is invalid.

More information about error codes on Windows here:
https://docs.microsoft.com/en-us/windows...des--0-499-

I'm moving this thread to the general questions section.
#3
(07-25-2020, 05:34 PM)Albert Wrote: This issue is related to OpenCV. I believe the id of your camera is invalid.

More information about error codes on Windows here:
https://docs.microsoft.com/en-us/windows...des--0-499-

I'm moving this thread to the general questions section.

The same code is running perfectly from the python shell on mac. It is just not running from inside RoboDK.

I do not have the problem on windows.
#4
This problem is related to different Python versions.

On Mac, RoboDK uses Python 2.7 by default (Mac's built-in Python version). You can use your default Python 3 version by just entering python3 as the Python interpreter path (in Tools-Options-Python).
#5
Did that. I have the latest versions installed. Not working. The same program can access videos from a file though. I guess on Mac it is some permissions issue. RoboDK cannot access the webcam. Can you kindly look into this?

"Python script failed returning 6"
Error code 6 is a SIGABRT error. Apparently the system is running into a fatal error and causing the program to abort().
#6
(07-27-2020, 03:39 PM)Albert Wrote: This problem is related to different Python versions.

On Mac, RoboDK uses Python 2.7 by default (Mac's built-in Python version). You can use your default Python 3 version by just entering python3 as the Python interpreter path (in Tools-Options-Python).

I haven't been able to solve this. The problem persists even with the latest RoboDK, and trying out every possible modification. I have also moved from the free version to a paid version.
The same program runs on a windows system, but not on a mac. Also, the same code is running from the mac terminal, but not from inside RoboDK, so clearly this is a problem with RoboDK. Maybe it does not have permission to access the macbook camera? Kindly try to resolve this.

Here is the code:
import cv2

cap = cv2.VideoCapture(0) #this does not work on roboDK
#cap.set(cv2.CAP_PROP_FRAME_WIDTH, 640)
#cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 480)

#cap = cv2.VideoCapture('/Users/riddhamanna/Documents/RoboDK/ymaze.mp4') #This works on roboDK

while(True):
    ret, img = cap.read()
    cv2.imshow('frame',img)
    if cv2.waitKey(1) & 0xFF == 27:#ord('q'):
        break

cap.release()
cv2.destroyAllWindows()
print("Hello World!")


Attached Files Thumbnail(s)
       
#7
Apparently you need to add something like this:

<key>NSCameraUsageDescription</key>
<string>RoboDK needs camera permissions</string>

to the info.plist file of RoboDK. But this is also not working. Basically, you need to modify the RboDK app to ask for permission to use the system camera/any camera on the MacOS. Can you kindly make this change in any future update?
  




Users browsing this thread:
1 Guest(s)