我正在尝试绘制面部轮廓并将其叠加在网络摄像头图像之上。
但是到最后,我认为我以错误的方式使用addWeighted
,因为我的程序崩溃了。
你能否帮我理解我在imshow
和addWeighted
做错了什么?
int main( int argc, const char** argv )
{
VideoCapture camera;
camera.open(0);
if( !camera.isOpened() )
{
cerr << "Could not access the camera!" << endl;
return 1;
}
while( true )
{
Mat cameraFrame;
camera >> cameraFrame;
if( cameraFrame.empty() )
{
cerr << "Could not grab a camera frame!" << endl;
return 1;
}
Mat gray;
cvtColor( cameraFrame, gray, CV_BGR2GRAY );
Size size = cameraFrame.size();
Mat faceOutline = Mat::zeros( size, CV_8UC3 ); // Draw a black canvas.
Scalar color = CV_RGB( 255, 255, 0 ); // Yellow
int thickness = 4;
ellipse( faceOutline, Point(320, 240), Size(320, 240), 0, 0, 360, color, thickness, CV_AA );
addWeighted( gray, 1.0, faceOutline, 0.7, 0, gray, CV_8UC3 );
imshow( "final image", gray );
char keypress = waitKey(20);
if( keypress == 27 ) break;
}
}
答案 0 :(得分:1)
为什么不直接将椭圆绘制到cameraFrame中?
椭圆(cameraFrame,Point(320,240),尺寸(320,240),0,0,360,颜色,厚度,CV_AA);
如果您想使用addWeighted,
addWeighted(cameraFrame,0.7,faceOutline,0.3,0,cameraFrame);
答案 1 :(得分:1)
答案 2 :(得分:1)
这很好用:
int main( int argc, const char** argv )
{
VideoCapture camera;
camera.open(0);
if( !camera.isOpened() )
{
cerr << "Could not access the camera!" << endl;
return 1;
}
while( true )
{
Mat cameraFrame;
camera >> cameraFrame;
if( cameraFrame.empty() )
{
cerr << "Could not grab a camera frame!" << endl;
return 1;
}
Mat gray;
cvtColor( cameraFrame, gray, cv::COLOR_BGR2GRAY );
Size size = cameraFrame.size();
Mat faceOutline = Mat::zeros( size, CV_8UC3 ); // Draw a black canvas.
Scalar color = Scalar( 255, 255, 0 ); // Yellow
int thickness = 4;
cvtColor( gray, gray, cv::COLOR_GRAY2BGR );
ellipse( faceOutline, Point(320, 240), Size(320, 240), 0, 0, 360, color, thickness );
addWeighted( gray, 1.0, faceOutline, 0.7, 0, gray, CV_8UC3 );
imshow( "final image", gray );
char keypress = waitKey(20);
if( keypress == 27 ) break;
}
}