Joon
Joon

Reputation: 1

OpenCV C++ VideoCapture on MacOS Monterey Not working

Hi I'm using M1 Macbook Pro 2021 with Monterey OS. I've been trying to use my mac's internal webcam with OpenCV C++ VideoCapture class on Visual Studio Code, but i keep getting this weird errors. I've given both terminal and iTerm access to the Camera on my Mac's Preferences, but it still keeps giving me this error. This is my Code,

#include <iostream>
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;

void camera_in()
{
    VideoCapture cap;
    cap.open(2, CAP_AVFOUNDATION);

    if (!cap.isOpened())
    {
        cerr << "Camera open failed!" << endl;
        return;
    }

    cout << "Frame width: " << cvRound(cap.get(CAP_PROP_FRAME_WIDTH)) << endl;
    cout << "Frame height: " << cvRound(cap.get(CAP_PROP_FRAME_HEIGHT)) << endl;

    Mat frame, inversed;
    while (true)
    {
        cap >> frame;
        if (frame.empty())
            break;
        
        inversed = ~frame;

        imshow("frame", frame);
        imshow("inversed", inversed);
        
        if (waitKey(10) == 27)
            break;
    }
    destroyAllWindows();
}

int main()
{
    camera_in();
}

And this is the error i get from executing it.

2022-08-05 18:15:01.284398+0900 video[7664:45504] [plugin] AddInstanceForFactory: No factory registered for id <CFUUID 0x10b54c320> F8BB1C28-BAE8-11D6-9C31-00039315CD46
2022-08-05 18:15:01.291647+0900 video[7664:45504]  HALC_ProxyObjectMap::_CopyObjectByObjectID: failed to create the local object
2022-08-05 18:15:01.291664+0900 video[7664:45504]  HALC_ShellDevice::RebuildControlList: couldn't find the control object
2022-08-05 18:15:01.316885+0900 video[7664:45504] [plugin] AddInstanceForFactory: No factory registered for id <CFUUID 0x10c50bb40> 30010C1C-93BF-11D8-8B5B-000A95AF9C6A

Upvotes: 0

Views: 1179

Answers (1)

jonny-sexton
jonny-sexton

Reputation: 11

I ran this code on my macbook pro m1 14" and it was working, I had to change:

cap.open(2, CAP_AVFOUNDATION);

to:

cap.open(0, CAP_AVFOUNDATION);

for it to work though (0 is the index of the built in webcam).

Upvotes: 1

Related Questions