我想每40ms灰度减去两个图像,我从两个摄像头每40ms捕获两个图像,然后将两个图像大小设置为(高度= 480,宽度= 640),之后转换为灰度。 但是当我对两个图像使用减法(absdiff)时,我得到了"运行时错误"。 我注意到当我显示两个图像的大小时,我得到了两个灰度图像大小的无与伦比的结果。
src_gray1 cols is: =640 src_gray1 rows is: =480 src_gray1.size =0x28fd5c
src_gray2 cols is: =640 src_gray2 rows is: =480 src_gray2.size =0x28fdcc
在Header中声明: cv :: Mat edges1,src_gray1,edges2,src_gray2,src_gray3;
我的问题:减法方法中的问题,是大小 灰度Mat是问题?,我如何设置相同的属性 两个图像来克服它。
我使用Qt 5.5.0,我的代码在这里:
void MainWindow::on_pushButton_pressed()
{
timer_40_ms->start();
timer2_40_ms->start();
cap1.open(0);
if( !cap1.isOpened() )
{
std::cout<<"Camera1 did not open";
return;
}
cap2.open(1);
if( !cap2.isOpened() )
{
std::cout<<"Camera2 did not open";
return;
}
cap1.set(CV_CAP_PROP_FRAME_HEIGHT,480);
cap1.set(CV_CAP_PROP_FRAME_WIDTH,640);
cap2.set(CV_CAP_PROP_FRAME_HEIGHT,480);
cap2.set(CV_CAP_PROP_FRAME_WIDTH,640);
}
void MainWindow::ProcessFrame()
{
cv::Mat frame1;
ii++;
ui->textEdit->setText(QString::number(ii));
cap1 >> frame1;
cvtColor(frame1, src_gray1, CV_BGR2GRAY);
std::cout<<"src_gray1 cols is:"<<" ="<<src_gray1.cols<<" "<<"src_gray1 rows is:"<<" ="<<src_gray1.rows<<" "<<"src_gray1.size ="<<src_gray1.size<<'\n';
}
void MainWindow::ProcessFrame2()
{
cv::Mat frame2;
ii2++;
cap2 >> frame2;
cvtColor(frame2, src_gray2, CV_BGR2GRAY);
ui->textEdit_3->setText(QString::number(ii2));
absdiff(src_gray1,src_gray2,src_gray3);
cv::imshow( "CAM2 Video Labeler", src_gray3 );
std::cout<<"src_gray2 cols is:"<<" ="<<src_gray2.cols<<" "<<"src_gray2 rows is:"<<" ="<<src_gray2.rows<<" "<<"src_gray2.size ="<<src_gray2.size<<'\n';
}
答案 0 :(得分:0)
问题是在ProcessFrame()之前调用ProcessFrame2(),谢谢@dan Masek寻求帮助:
void MainWindow::on_pushButton_pressed()
{
timer_40_ms->start();
timer2_40_ms->start();
cap1.open(0);
if( !cap1.isOpened() )
{
std::cout<<"Camera1 did not open";
return;
}
cap2.open(1);
if( !cap2.isOpened() )
{
std::cout<<"Camera2 did not open";
return;
}
cap1.set(CV_CAP_PROP_FRAME_HEIGHT,480);
cap1.set(CV_CAP_PROP_FRAME_WIDTH,640);
cap2.set(CV_CAP_PROP_FRAME_HEIGHT,480);
cap2.set(CV_CAP_PROP_FRAME_WIDTH,640);
}
void MainWindow::ProcessFrame()
{
cv::Mat frame1;
ii++;
ui->textEdit->setText(QString::number(ii));
cap1 >> frame1;
cvtColor(frame1, src_gray1, CV_BGR2GRAY);
absdiff(src_gray1,src_gray2,src_gray3);
cv::imshow( "CAM2 Video Labeler", src_gray3 );
std::cout<<"src_gray1 cols is:"<<" ="<<src_gray1.cols<<" "<<"src_gray1 rows is:"<<" ="<<src_gray1.rows<<" "<<"src_gray1.size ="<<src_gray1.size<<'\n';
}
void MainWindow::ProcessFrame2()
{
cv::Mat frame2;
ii2++;
cap2 >> frame2;
cvtColor(frame2, src_gray2, CV_BGR2GRAY);
ui->textEdit_3->setText(QString::number(ii2));
std::cout<<"src_gray2 cols is:"<<" ="<<src_gray2.cols<<" "<<"src_gray2 rows is:"<<" ="<<src_gray2.rows<<" "<<"src_gray2.size ="<<src_gray2.size<<'\n';
}