zoukankan      html  css  js  c++  java
  • 【20160924】GOCVHelper 图像增强部分(4)

    //使得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=Wi<roi.colsi+=W) {
                for (int j=Hj<roi.rowsj+=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-Wii<=iii++) {
                        for (int jj=j-Hjj<=jjj++) {
                            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中扒出来的。
     
     
     





  • 相关阅读:
    内容居中
    ajax验证登录注册
    html5 图片转为base64格式异步上传
    关于iframe的滚动条,如何去掉水平滚动条或垂直滚动条
    oracle数据库操作(未封装)
    oracle数据库操作(结合读取.ini文件操作)
    读取xml文件的方法
    线程练习
    TypeError: the JSON object must be str, not 'bytes'报错问题解决
    python datetime.datetime is not JSON serializable 报错问题解决
  • 原文地址:https://www.cnblogs.com/jsxyhelu/p/5907545.html
Copyright © 2011-2022 走看看