c++ 如何使用OpenCV访问外部网络摄像头?

64jmpszr  于 2022-12-30  发布在  其他
关注(0)|答案(2)|浏览(242)

最大的问题在于,不管我在VideoCapture cap()中输入哪个数字,它总是能找到我笔记本电脑的内部webcap--否则就死定了。我试过进入设备并关闭内部webcap,但效果不大。(顺便说一句,我是这个论坛的新手,所以要温和一点。)
下面是代码(不包括旋转功能。)

int main()
{   
    // NOW WITH WEBCAM INPUT!!
    VideoCapture cap(0);//capture image from webcam
    cap.open(true); 
    Mat image;
    cap>>image; //applying the captured image to Mat image
    //Mat image = imread("Tulips.jpg"); // reading the image
    double degrees; // Number of degrees we want to rotate the image
    double oregoX = image.cols / 2; //X-center of the image
    double oregoY = image.rows / 2; //Y-center of the image

    //user inputs
    cout << "please enter the number of degrees you wish to turn the image" << endl;
    cin >> degrees;

    cout << "\n\nplease enter at which point (X, Y) you want to rotate the image\n(make space not comma)\n" << endl;
    cout << "The center of the image is at " << oregoX << ", " << oregoY << endl;
    cin >> oregoX >> oregoY;

    while (true){
        cap>>image;

        if (!image.data) break;
        if (waitKey(30) >= 0) break;

        cvtColor(image, image, CV_8U); //Converting image to 8-bit
        Mat grayImage; //creating a canvas for the grayscale image
        cvtColor(image, grayImage, CV_RGB2GRAY); //creating the grayscale image

        // Here we create a canvas with the same size as the input image, later to put in the rotated data
        Mat imageOut(grayImage.rows, grayImage.cols, CV_8U);

        Rotation(grayImage, imageOut, degrees, oregoX, oregoY); //Performing the rotation on the image using the Rotation() funcion

        imshow("The Gray Image", grayImage);
        imshow("The rotated image", imageOut);

    }
}
ukdjmx9f

ukdjmx9f1#

设备管理器-〉查找内置网络摄像头-〉禁用内置网络摄像头。默认网络摄像头将成为您以后插入的任何网络摄像头。

mfuanj7w

mfuanj7w2#

VideoCapture cap(1); //capture image from other webcam

相关问题