0

Currently, I am working on a face detection algorithm for patients in bed. One camera will be set up next to the bed, and the other on the ceiling. My idea is to switch between cameras when the patient's face is not found, allowing me to have an idea on where the patient is looking at.

My current problem area is right here:

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

I have no idea which if condition to use which will allow me to switch cameras This is my code in full(which includes codes for skin detection as well)

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

}
bashrc
  • 4,725
  • 1
  • 22
  • 49
John
  • 1
  • 1

1 Answers1

0

You can open both cameras (get frames from both), check where is the patient's face and them turn off one camera.

Andrey Smorodov
  • 10,649
  • 2
  • 35
  • 42