C++ 当满足条件时,如何在两个网络摄像头(连接到计算机)之间切换?
目前,我正在为卧床病人设计一种人脸检测算法。一个摄像头将安装在床边,另一个安装在天花板上。我的想法是在找不到患者的脸时切换摄像机,让我知道患者在看什么 我目前的问题区域就在这里:C++ 当满足条件时,如何在两个网络摄像头(连接到计算机)之间切换?,c++,opencv,webcam,face-detection,C++,Opencv,Webcam,Face Detection,目前,我正在为卧床病人设计一种人脸检测算法。一个摄像头将安装在床边,另一个安装在天花板上。我的想法是在找不到患者的脸时切换摄像机,让我知道患者在看什么 我目前的问题区域就在这里: if // face not found in first camera { cap.open(1); //switch to second camera } else { cap.open(0); //continue using first camera } 我不知道使用哪种条件
if // face not found in first camera
{
cap.open(1);
//switch to second camera
}
else
{
cap.open(0);
//continue using first camera
}
我不知道使用哪种条件可以让我切换摄像头
这是我的完整代码(包括皮肤检测代码)
intmain(){
Mat图像;
视频捕捉帽;
封盖套件(CV、封盖、支架、宽度640);
封盖套件(CV、封盖、支柱、框架、高度,480);
上限开放(0);
//创建用于人脸检测的级联分类器对象
层叠式分级机;
//使用haarcascade_frontalface_alt.xml库
face_cascade.load(“haarcascade_frontalface_alt.xml”);
//设置视频捕获设备并将其链接到第一个捕获设备
视频捕获设备;
captureDevice.open(0);
//设置捕获过程中使用的图像文件
网框;
matgrayscaleframe;
//namedWindow(“窗口”,1);
//创建一个窗口以显示结果
namedWindow(“输出捕获”,1);
而(1)
{
尝试
{
cap>>图像;
CVT颜色(图像、灰度、CV_bgr2灰色);
均衡器历史(GrayScaleName,GrayScaleName);
//将捕获的图像转换为灰度并进行均衡
CVT颜色(图像、灰度、CV_bgr2灰色);
均衡器历史(GrayScaleName,GrayScaleName);
//创建向量数组以存储找到的面
向量面;
//找到面并将其存储在向量数组中
face_cascade.detectMultiScale(灰度图像,faces,1.1,3,CV_HAAR_FIND_最大对象| CV_HAAR_SCALE_图像,大小(30,30));
//为原始图像上向量数组中找到的所有面绘制一个矩形
对于(int i=0;i
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);
}
}