计算图像直方图的程序

Program to compute Histogram of the image

我在 Java 中有一个使用 OpenCV 的程序,该程序旨在计算图像的直方图。 Class计算直方图是

public class Histogram1D {

   private final int numberOfBins = 256;
   private float minRange = 0.0f;
   private float maxRange = 255.0f;

   public CvHistogram getHistogram(IplImage image, IplImage mask) {
      int dim = 1;
      int[] sizes = new int[numberOfBins];
      int histType = CV_HIST_ARRAY;
      float[][] ranges = new float[(int) minRange][(int) maxRange];
      CvHistogram hist = cvCreateHist(dim, sizes, histType, ranges, 1);
      int accumulate = 0;
      cvCalcHist(new IplImageArray(image), hist, accumulate, mask);
      return hist;
   }

   public float[] getHistogramAsArray(IplImage image) {
      CvHistogram histogram = getHistogram(image, null);
      float[] dest = new float[numberOfBins];
      for (int bin = 0; bin < numberOfBins; bin++) {
         dest[bin] = cvQueryHistValue_1D(histogram, bin);
      }
      cvReleaseHist(histogram);
      return dest;
   }
}

并且主要 class 是

public class Main {

   public static void main(String args[]) {

      Histogram1D h = new Histogram1D();
      IplImage image =  cvLoadImage("data/group.jpg",CV_LOAD_IMAGE_GRAYSCALE);
      float[] histogram = h.getHistogramAsArray(image);     
      int numberOfPixels = image.width() + image.height();
      System.out.println("Number of pixels  : " + numberOfPixels);        
   }
}

我的问题是,当我输入这行代码时: float[] histogram = h.getHistogramAsArray(image);到 Main class 和 运行 项目,我收到此错误消息:

A fatal error has been detected by the Java Runtime Environment:

EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x00007ff9b0613f0e, pid=2744, tid=1072

JRE version: Java(TM) SE Runtime Environment (8.0_20-b26) (build 1.8.0_20-b26)
Java VM: Java HotSpot(TM) 64-Bit Server VM (25.20-b23 mixed mode windows-amd64 compressed oops)
Problematic frame:
C  [opencv_imgproc248.dll+0xc3f0e]

Failed to write core dump. Minidumps are not enabled by default on client versions of Windows

An error report file with more information is saved as:
C:\...........\hs_err_pid2744.log

If you would like to submit a bug report, please visit:
http://bugreport.sun.com/bugreport/crash.jsp
The crash happened outside the Java Virtual Machine in native code.
See problematic frame for where to report the bug.

Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)

任何人都可以帮助我,这条消息是什么意思,请问我的代码哪里有问题?

谢谢。

看起来您的 opencv_imgproc248.dll 库在本机部分有问题,而不是在您的代码中。