目前,我正在为床上的病人进行面部检测算法。一个摄像头将安装在床边,另一个安装在天花板上。我的想法是在没有找到病人面部时在摄像机之间切换,让我知道病人在哪里看。
我目前的问题所在:
if // face not found in first camera
{
cap.open(1);
//switch to second camera
}
else
{
cap.open(0);
//continue using first camera
}
我不知道哪个条件可以让我切换相机 这是我的完整代码(包括皮肤检测代码)
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);
}
}
答案 0 :(得分:0)
您可以打开两个摄像头(从两个摄像头获取帧),检查患者面部的位置,然后关闭一个摄像头。