Search code examples
c++opencv3.0macos-sierra

Opencv & OSX: USB camera acess


I checked all related questions, and answer are all out-dated (C API) or not relevant/without real answer.

Opencv version 3.0 (via homebrew).

OS: OSX Sierra

Opencv is running smoothly, except for VideoCapture::VideoCapture(int device).

No matter the parameter I try, Videocapture allways take the iSight camera.

Am I missing something?

*note: Im not a developer, just trying to have fun *


Solution

  • As a OSX user and Opencv user, troubles with OSX & opencv are more than reccurent.

    (I'm not stalking you but following your progression).

    There is a trick/fix for your issue.

    You just need to disable and re-enable the iSight camera to get access to which ever camera you want afterward.

    Step 0:

    Create a backup of your OSX install (You should always have one)

    Step 1:

    Desactivate the SIP, this is something you should never do if you aren't sure of what you are doing but there is no other choices. Reboot your mac, during boot press command+R. Once the UI has loaded, go in the top bar and choose utilty->terminal and type:

    csrutil disable; reboot
    

    this will desable your SIP and reboot your mac into "normal" mode.

    Step2:

    sudo chmod a-r /System/Library/Frameworks/CoreMediaIO.framework/Versions/A/Resources/VDC.plugin/Contents/MacOS/VDC
    sudo chmod a-r /System/Library/PrivateFrameworks/CoreMediaIOServicesPrivate.framework/Versions/A/Resources/AVC.plugin/Contents/MacOS/AVC
    sudo chmod a-r /System/Library/QuickTime/QuickTimeUSBVDCDigitizer.component/Contents/MacOS/QuickTimeUSBVDCDigitizer
    sudo chmod a-r /Library/CoreMediaIO/Plug-Ins/DAL/AppleCamera.plugin/Contents/MacOS/AppleCamera
    sudo chmod a-r /Library/CoreMediaIO/Plug-Ins/FCP-DAL/AppleCamera.plugin/Contents/MacOS/AppleCamera
    

    Step3: (optional) test in opencv, you should get an error when trying cv::VideoCapture cap(0); error is a block of text telling you have no camera/drivers, its normal.

    Step4: reboot

    Step5:

    sudo chmod a+r /System/Library/Frameworks/CoreMediaIO.framework/Versions/A/Resources/VDC.plugin/Contents/MacOS/VDC
    sudo chmod a+r /System/Library/PrivateFrameworks/CoreMediaIOServicesPrivate.framework/Versions/A/Resources/AVC.plugin/Contents/MacOS/AVC
    sudo chmod a+r /System/Library/QuickTime/QuickTimeUSBVDCDigitizer.component/Contents/MacOS/QuickTimeUSBVDCDigitizer
    sudo chmod a+r /Library/CoreMediaIO/Plug-Ins/DAL/AppleCamera.plugin/Contents/MacOS/AppleCamera
    sudo chmod a+r /Library/CoreMediaIO/Plug-Ins/FCP-DAL/AppleCamera.plugin/Contents/MacOS/AppleCamera
    

    Step6:

    Retest in opencv; unplug your usb camera try: cv::VideoCapture cap(1); error output should tell you that you have a range of 0-0 in cv::VideoCapture instead of the 0-1 that xcode is telling you by default.

    Congratulation you can now access USB/webcam in opencv on Xcode and Sierra.

    Step7:(optional BUT HIGLY recommanded)

    Reactivate your SIP (if you arent sure of what you are doing in the terminal/download on your mac DO IT). Reboot your mac press command+R and once the UI is here choose Utility->Terminal and type:

    csrutil enable;
    

    THEN create a new restauration point of your mac ("OSX Serra - date - Opencv access Webcam" or whatever with an EXPLICIT name).

    Then in terminal type:

    reboot
    

    Step8: Enjoy.

    Once you have an opencv setup running and if you don't use Objective-C/iDevice programming you should avoid to update Xcode anymore has it tend to break opencv install pretty hard