我使用OpenCV编写Java程序,用于计算图像的直方图。 计算直方图的类是
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;
}
}
和Main 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);到主类和运行项目我收到此错误消息:
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)
任何人都可以帮助我,这条消息意味着什么,我的代码有问题吗?
谢谢。
答案 0 :(得分:0)
您的本机部分上的 opencv_imgproc248.dll 库看起来有问题,而不是您的代码。