首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >当满足条件时,如何在两个网络摄像头(连接到计算机)之间切换?

当满足条件时,如何在两个网络摄像头(连接到计算机)之间切换?
EN

Stack Overflow用户
提问于 2015-12-31 18:56:02
回答 1查看 196关注 0票数 0

目前,我正在研究一种针对卧床病人的人脸检测算法。一台摄像机将安装在床边,另一台安装在天花板上。我的想法是在找不到病人的脸时切换相机,这样我就可以知道病人在看什么地方。

我目前的问题就在这里:

代码语言:javascript
复制
if // face not found in first camera
{
    cap.open(1);
    //switch to second camera
}
else 
{
    cap.open(0);
    //continue using first camera
}

我不知道该使用哪个if条件来切换摄像头,这是我的完整代码(包括皮肤检测的代码)

代码语言:javascript
复制
int main() {
    Mat image;

    VideoCapture cap;
    cap.set(CV_CAP_PROP_FRAME_WIDTH, 640);
    cap.set(CV_CAP_PROP_FRAME_HEIGHT, 480);
    cap.open(0);

    //create the cascade classifier object used for the face detection
    CascadeClassifier face_cascade;
    //use the haarcascade_frontalface_alt.xml library
    face_cascade.load("haarcascade_frontalface_alt.xml");

    //setup video capture device and link it to the first capture device
    VideoCapture captureDevice;
    captureDevice.open(0);

    //setup image files used in the capture process
    Mat captureFrame;
    Mat grayscaleFrame;

    //namedWindow("window", 1);
    //create a window to present the results
    namedWindow("outputCapture", 1);

    while (1)
    {

        try
        {
            cap >> image;

            cvtColor(image, grayscaleFrame, CV_BGR2GRAY);
            equalizeHist(grayscaleFrame, grayscaleFrame);


            //convert captured image to gray scale and equalize
            cvtColor(image, grayscaleFrame, CV_BGR2GRAY);
            equalizeHist(grayscaleFrame, grayscaleFrame);

            //create a vector array to store the face found
            std::vector<Rect> faces;

            //find faces and store them in the vector array
            face_cascade.detectMultiScale(grayscaleFrame, faces, 1.1, 3, CV_HAAR_FIND_BIGGEST_OBJECT | CV_HAAR_SCALE_IMAGE, Size(30, 30));

            //draw a rectangle for all found faces in the vector array on the original image
            for (int i = 0; i < faces.size(); i++)
            {
                Point pt1(faces[i].x + faces[i].width, faces[i].y + faces[i].height);
                Point pt2(faces[i].x, faces[i].y);

                rectangle(image, pt1, pt2, cvScalar(0, 255, 0, 0), 1, 8, 0);

                if // face not found in first camera
                {
                    cap.open(1);
                    //switch to second camera
                }
                else {
                    cap.open(0);
                    //continue using first camera
                }
            }

            //print the output
            imshow("outputCapture", image);

            SkinDetector mySkinDetector;

            Mat skinMat;

            cap.read(image);

            //show the current image
            imshow("Original Image", image);

            skinMat = GetSkin(image);

            imshow("Skin Image", skinMat);
        }
        catch (Exception& e)
        {
            const char* err_msg = e.what();
            std::cout << "exception caught: imshow:\n" << err_msg << std::endl;


        }
        waitKey(33);
    }

}
EN

回答 1

Stack Overflow用户

发布于 2016-01-03 20:34:17

你可以打开两个摄像头(从两个摄像头获取图像),检查病人的脸在哪里,然后他们关闭一个摄像头。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34545367

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档