我正在尝试使用 Opencv 找出 2 个图像之间的区别。代码如下:
#include "cv.h"
#include "highgui.h"
#include <stdio.h>
#include<iostream>
int main()
{
char a,b;
cv::Mat frame;
cv::Mat frame2;
VideoCapture cap(0);
if(!cap.isOpened())
{
cout<<"Camera is not connected"<<endl;
getchar();
exit(0);
}
Mat edges;
namedWindow("Camera Feed",1);
cout<<"Ready for background?(y/Y)"<<endl;
cin>>a;
if(a=='y'||a=='Y')
{
cap>>frame;
cv::cvtColor(frame,frame,CV_RGB2GRAY);
cv::GaussianBlur(frame,frame,cv::Size(3,3),2.00,0,BORDER_DEFAULT);
}
cout<<"Ready for foreground?(y/Y)"<<endl;
cin>>b;
if(b=='y'||b=='Y')
{
cap>>frame2;
cv::cvtColor(frame2,frame2,CV_RGB2GRAY);
cv::GaussianBlur(frame2,frame2,cv::Size(3,3),2.00,0,BORDER_DEFAULT);
}
cv::absdiff(frame,frame2,frame);
imwrite("img_bw.jpg",frame);
return 0;
}
代码运行良好,但输出不像我想要的那样完全黑白。我哪里错了?