简体   繁体   English

OpenCV C++ MacOS Monterey 上的 VideoCapture 不工作

[英]OpenCV C++ VideoCapture on MacOS Monterey Not working

Hi I'm using M1 Macbook Pro 2021 with Monterey OS.您好,我正在使用 M1 Macbook Pro 2021 和 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.我一直在尝试在 Visual Studio Code 上将我的 mac 的内部网络摄像头与 OpenCV C++ VideoCapture class 一起使用,但我不断收到这个奇怪的错误。 I've given both terminal and iTerm access to the Camera on my Mac's Preferences, but it still keeps giving me this error.我已经在我的 Mac 的首选项中授予了终端和 iTerm 对相机的访问权限,但它仍然不断给我这个错误。 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

I ran this code on my macbook pro m1 14" and it was working, I had to change:我在我的 macbook pro m1 14" 上运行了这段代码,它正在工作,我不得不改变:

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).虽然它可以工作(0是内置网络摄像头的索引)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM