簡體   English   中英

如何使用OpenCV訪問外部攝像頭?

[英]How do I access an external webcam with OpenCV?

最大的問題在於,無論我在VideoCapture cap()中鍵入哪個數字,代碼都將始終能找到筆記本電腦的內部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);

}

}

設備管理器->查找內部網絡攝像頭->禁用內部網絡攝像頭。 然后,默認網絡攝像頭將成為您隨后插入的任何網絡攝像頭。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM