如何使用 OpenCV 访问外部网络摄像头? [英] How do I access an external webcam with OpenCV?

查看:60
本文介绍了如何使用 OpenCV 访问外部网络摄像头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

The big problem lies in the fact that the code, no matter which number I type in to VideoCapture cap(), it will always find the internal webcap of my laptop - Or die trying. I have tried going in to devices and deactivated the internal one, but it did little good. (By the way, I'm new at this forum, so be gentle.)

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

Here's the code ( Not including the Rotation function.)

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

}

}

推荐答案

设备管理器 -> 定位内部网络摄像头 -> 禁用内部网络摄像头.默认网络摄像头将成为您插入的任何网络摄像头之后.

Device manager -> Locate internal webcam -> Disable internal webcam. The default webcam will then become whichever webcam that you plug in afterwards.

这篇关于如何使用 OpenCV 访问外部网络摄像头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆