當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。