我在Android中使用JavaCV。
在我的代碼,我已經創建了一個對象進行比較的圖像對象,並使用(OpenCV的食譜
http://code.google.com/p/javacv/source/browse/OpenCV2_Cookbook/src/opencv2_cookbook/chapter04/ImageComparator.scala?repo=examples
http://code.google.com/p/javacv/wiki/OpenCV2_Cookbook_Examples_Chapter_4類)一ImageComparator。如果我使用SD卡上的文件,比較器正在工作。Android JavaCV從相機創建IplImage以使用ColorHistogram
File referenceImageFile = new File(absPath1); // Read an image.
IplImage reference = Util.loadOrExit(referenceImageFile,CV_LOAD_IMAGE_COLOR);
comparator = new ImageComparator(reference);
comparator = new ImageComparator(reference);
但是從Camera Preview中,當我創建IplImage時它不起作用。在比較「分數」計算過程中,我得到以下異常。
score = referenceComparator.compare(grayImage)/ imageSize; java.lang.RuntimeException:/home/saudet/android/OpenCV-2.4.2/modules/core/src/convert.cpp:1196:error:(-215)i < src.channels()in function void cvSplit()對於CameraPreview我使用FacePreview中的代碼來創建IplImage.But它在grayScale中創建圖像。
int f = SUBSAMPLING_FACTOR;
if (grayImage == null || grayImage.width() != width/f
|| grayImage.height() != height/f) {
grayImage = IplImage.create(width/f, height/f, IPL_DEPTH_8U, 1);
}
int imageWidth = grayImage.width();
int imageHeight = grayImage.height();
int dataStride = f * width;
int imageStride = grayImage.widthStep();
ByteBuffer imageBuffer = grayImage.getByteBuffer();
for (int y = 0; y < imageHeight; y++) {
int dataLine = y * dataStride;
int imageLine = y * imageStride;
for (int x = 0; x < imageWidth; x++) {
imageBuffer.put(imageLine + x, data[dataLine + f * x]);
}
}
如何從相機創建Color IplImage以與ImageComparator一起使用?