//使得rect区域半透明
Mat translucence(Mat src,Rect rect,int idepth){
Mat dst = src.clone();
Mat roi = dst(rect);
roi += cv::Scalar(idepth,idepth,idepth);
return dst;
}
将选择的区域打上变成半透明。虽然这只是一个简单的函数,但是使用起来灵活多变。
比如说,可以将图像某个区域变成半透明,然后在上面写字,这样起到强化作用;
也可以将一个区域图片在半透明和不透明之间切换,起到强掉作用。
//使得rect区域打上马赛克
Mat mosaic(Mat src,Rect rect,int W,int H){
Mat dst = src.clone();
Mat roi = dst(rect);
for (int i=W; i<roi.cols; i+=W) {
for (int j=H; j<roi.rows; j+=H) {
uchar s=roi.at<uchar>(j-H/2,(i-W/2)*3);
uchar s1=roi.at<uchar>(j-H/2,(i-W/2)*3+1);
uchar s2=roi.at<uchar>(j-H/2,(i-W/2)*3+2);
for (int ii=i-W; ii<=i; ii++) {
for (int jj=j-H; jj<=j; jj++) {
roi.at<uchar>(jj,ii*3+0)=s;
roi.at<uchar>(jj,ii*3+1)=s1;
roi.at<uchar>(jj,ii*3+2)=s2;
}
}
}
}
return dst;
}
将选择的区域打上马赛克,也就是常见的所谓打码。
//基于颜色直方图的距离计算
double GetHsVDistance(Mat src_base,Mat src_test1){
Mat hsv_base;
Mat hsv_test1;
/// Convert to HSV
cvtColor( src_base, hsv_base, COLOR_BGR2HSV );
cvtColor( src_test1, hsv_test1, COLOR_BGR2HSV );
/// Using 50 bins for hue and 60 for saturation
int h_bins = 50; int s_bins = 60;
int histSize[] = { h_bins, s_bins };
// hue varies from 0 to 179, saturation from 0 to 255
float h_ranges[] = { 0, 180 };
float s_ranges[] = { 0, 256 };
const float* ranges[] = { h_ranges, s_ranges };
// Use the o-th and 1-st channels
int channels[] = { 0, 1 };
/// Histograms
MatND hist_base;
MatND hist_test1;
/// Calculate the histograms for the HSV images
calcHist( &hsv_base, 1, channels, Mat(), hist_base, 2, histSize, ranges, true, false );
normalize( hist_base, hist_base, 0, 1, NORM_MINMAX, -1, Mat() );
calcHist( &hsv_test1, 1, channels, Mat(), hist_test1, 2, histSize, ranges, true, false );
normalize( hist_test1, hist_test1, 0, 1, NORM_MINMAX, -1, Mat() );
/// Apply the histogram comparison methods
double base_test1 = compareHist( hist_base, hist_test1, 0 );
return base_test1;
}
基于颜色直方图的增强算法是一种经典的图像增强算法。这里提供了opencv实现。这个部分应该是从gimp中扒出来的。