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

时间:2011-11-01 13:45:48

标签: c++ visual-studio-2010 opencv

最大的问题在于代码,无论我输入哪个数字到VideoCapture cap(),它总会找到我的笔记本电脑的内部网络摄像头 - 或者试死。 我已尝试进入设备并停用内部设备,但是 它没什么用。 (顺便说一句,我是这个论坛的新人,所以要温柔。)

这是代码(不包括旋转功能。)

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);

}

}

2 个答案:

答案 0 :(得分:2)

设备管理器 - &gt;找到内部网络摄像头 - &gt;禁用内部网络摄像头。 默认网络摄像头将成为您插入的网络摄像头 之后。

答案 1 :(得分:-1)

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