当前位置: 首页>>代码示例>>Java>>正文


Java Imgproc.calcHist方法代码示例

本文整理汇总了Java中org.opencv.imgproc.Imgproc.calcHist方法的典型用法代码示例。如果您正苦于以下问题:Java Imgproc.calcHist方法的具体用法?Java Imgproc.calcHist怎么用?Java Imgproc.calcHist使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.opencv.imgproc.Imgproc的用法示例。


在下文中一共展示了Imgproc.calcHist方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: compare_image

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
public void compare_image(BufferedImage img_1, BufferedImage img_2) throws IOException {//Its called by above method compare_image()
    Mat mat_1 = conv_Mat(img_1);
    Mat mat_2 = conv_Mat(img_2);

    Mat hist_1 = new Mat();
    Mat hist_2 = new Mat();

    MatOfFloat ranges = new MatOfFloat(0f, 256f);
    MatOfInt histSize = new MatOfInt(25);

    Imgproc.calcHist(Arrays.asList(mat_1), new MatOfInt(0),
            new Mat(), hist_1, histSize, ranges);
    Imgproc.calcHist(Arrays.asList(mat_2), new MatOfInt(0),
            new Mat(), hist_2, histSize, ranges);

    double res = Imgproc.compareHist(hist_1, hist_2, Imgproc.CV_COMP_CORREL);
    Double d = new Double(res * 100);

    disp_percen(d.intValue());

}
 
开发者ID:javaspecial,项目名称:Face-detection-and-recognition-desktop-application,代码行数:22,代码来源:FaceDetectCropTest.java

示例2: getMedian

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
public static int getMedian(Mat mat) {

        ArrayList<Mat> listOfMat = new ArrayList<>();
        listOfMat.add(mat);
        MatOfInt channels = new MatOfInt(0);
        Mat mask = new Mat();
        Mat hist = new Mat(256, 1, CvType.CV_8UC1);
        MatOfInt histSize = new MatOfInt(256);
        MatOfFloat ranges = new MatOfFloat(0, 256);

        Imgproc.calcHist(listOfMat, channels, mask, hist, histSize, ranges);

        double t = mat.rows() * mat.cols() / 2;
        double total = 0;
        int med = -1;
        for (int row = 0; row < hist.rows(); row++) {
            double val = hist.get(row, 0)[0];
            if ((total <= t) && (total + val >= t)) {
                med = row;
                break;
            }
            total += val;
        }

//        Log.d(TAG, String.format("getMedian() = %d", med));

        return med;
    }
 
开发者ID:Deeplocal,项目名称:android-things-drawbot,代码行数:29,代码来源:LineAlgorithm.java

示例3: getHistAverage

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
/**
 * Get the average hue value of the image starting from its Hue channel
 * histogram
 *
 * @param hsvImg    the current frame in HSV
 * @param hueValues the Hue component of the current frame
 * @return the average Hue value
 */
private double getHistAverage(Mat hsvImg, Mat hueValues) {
    // init
    double average = 0.0;
    Mat hist_hue = new Mat();
    // 0-180: range of Hue values
    MatOfInt histSize = new MatOfInt(180);
    List<Mat> hue = new ArrayList<>();
    hue.add(hueValues);

    // compute the histogram
    Imgproc.calcHist(hue, new MatOfInt(0), new Mat(), hist_hue, histSize, new MatOfFloat(0, 179));

    // get the average Hue value of the image
    // (sum(bin(h)*h))/(image-height*image-width)
    // -----------------
    // equivalent to get the hue of each pixel in the image, add them, and
    // divide for the image size (height and width)
    for (int h = 0; h < 180; h++) {
        // for each bin, get its value and multiply it for the corresponding
        // hue
        average += (hist_hue.get(h, 0)[0] * h);
    }

    // return the average hue of the image
    average = average / hsvImg.size().height / hsvImg.size().width;

    return average;
}
 
开发者ID:Evegen55,项目名称:main_carauto_board,代码行数:37,代码来源:MagicTabController.java

示例4: Hist

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
public static Mat Hist(Mat srcImage){
    Mat dstImage = new Mat();
    Mat grayImage = new Mat();
    Mat dilateImage = new Mat();
    List<MatOfPoint> contours = new ArrayList<MatOfPoint>();

    Mat lut= new Mat(256, 1, CvType.CV_8UC1);

    Imgproc.cvtColor(srcImage, grayImage, Imgproc.COLOR_BGR2GRAY);


    ArrayList<Mat> histsSource  = new ArrayList<Mat>();
    histsSource.add(grayImage);
    Mat hist = new Mat();
    Imgproc.calcHist(histsSource, new MatOfInt(0), new Mat(), hist, new MatOfInt(256), new MatOfFloat(0f, 256f));
    int min=0,max=0;

    for (int i=0;i<hist.size().height;i++){
        if (hist.get(i,0)[0]>0)
        { min=i;
            break;}
    }
    for (int i=(int)(hist.size().height)-1;i>=0;i--){
        if (hist.get(i,0)[0]>0)
        { max=i;
            break;}
    }
    for (int i=0;i<hist.size().height;i++){
        if (i<min){lut.put(i,0,0.0);}
        else if (i>max){lut.put(i,0,255.0);}
        else {lut.put(i,0,255.0*(i-min)/(max-min)+0.5);}


    }


    //for (int i=0;i<lut.size().height;i++){
    //System.out.println(lut.get(i,0)[0]);}
    Core.LUT(grayImage,lut,grayImage);
    return grayImage;


}
 
开发者ID:hgs1217,项目名称:Paper-Melody,代码行数:44,代码来源:ImgTransform.java


注:本文中的org.opencv.imgproc.Imgproc.calcHist方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。