opencv光影删除法去除背景

#include "qtest1105.h"
#include
#include
#include
#include
#include
#include
#include
using namespace std;
using namespace cv;


Mat img = imread("C:\\Users\\hasee\\Desktop\\test.jpg");
Mat removeLight(Mat imge,Mat pattern,int method);
Mat calculateLightPattern(Mat img);



int main()
{
Mat pattern = calculateLightPattern(img);
imshow("pattern--light", pattern);


Mat re_light = removeLight(img,pattern,1);
imshow("remove--light",re_light);



//createButton("ss", showHistoCallback, NULL, QT_PUSH_BUTTON, 0);
//createButton("直方图均衡化",equlizeCallback,NULL,QT_PUSH_BUTTON,0);



waitKey(0);
return 0;
}
Mat removeLight(Mat imge, Mat pattern, int method) {
Mat aux;
if (method==1) {
Mat img32, pattern32;
imge.convertTo(img32,CV_32F);
pattern.convertTo(pattern32,CV_32F);
aux = 1 - (img32 / pattern32);


aux = aux * 255;


aux.convertTo(aux,CV_8U);
}
else {
aux = pattern - imge;
}
return aux;
}


Mat calculateLightPattern(Mat img) {
Mat pattern;
blur(img,pattern,Size(img.cols/3,img.cols/3));
return pattern;
}

你可能感兴趣的:(opencv+vs2015)