有人可以告诉我我做错了什么,或者举例说明如何在OpenCV4 Android中从灰度垫创建AND DISPLAY直方图?有我的代码......
Vector<Mat> bgr_planes = new Vector<Mat>();
Core.split(cleanFaceMatGRAY, bgr_planes);
MatOfInt histSize = new MatOfInt(256);
final MatOfFloat histRange = new MatOfFloat(0f, 256f);
boolean accumulate = false;
Mat b_hist = new Mat();
Imgproc.calcHist(bgr_planes, new MatOfInt(0),new Mat(), b_hist, histSize, histRange, accumulate);
然后我尝试将其设置为图像视图以查看它:
ivPickedPhoto.setImageBitmap(AppTools.createBitmapFromMat(b_hist, Bitmap.Config.ARGB_8888));
显示方法是我自己创建的:
public class AppTools {
public static Bitmap createBitmapFromMat(Mat mat, Bitmap.Config config) {
Bitmap bmp2 = null;
bmp2 = Bitmap.createBitmap(mat.cols(), mat.rows(), config);
Utils.matToBitmap(mat, bmp2);
return bmp2;
}
这使我在ivPickedPhoto(...)泳道中出错:
12-10 21:12:59.910: E/AndroidRuntime(10301): Caused by: CvException [org.opencv.core.CvException: /home/reports/ci/slave_desktop/50-SDK/opencv/modules/java/generator/src/cpp/utils.cpp:98: error: (-215) src.type() == CV_8UC1 || src.type() == CV_8UC3 || src.type() == CV_8UC4 in function void Java_org_opencv_android_Utils_nMatToBitmap2(JNIEnv*, jclass, jlong, jobject, jboolean)
我想我的问题在于我想要显示直方图的方式...我不能将它转换为bmp。显示直方图的好方法是什么?
答案 0 :(得分:2)
OpenCV Java Documentation表示您传递的Mat
对象应为CV_8UC1, CV_8UC3 or CV_8UC4
类型。 calcHist的文档并未真正指定您应该期望b_Hist
的类型,但因为它抱怨Mat
类型:
error: (-215) src.type() == CV_8UC1 || src.type() == CV_8UC3 || src.type() == CV_8UC4
您应该将其转换为上述三种格式中的任何一种。