2
有人可以告訴我我做錯了什麼或給我舉例如何在OpenCV4 Android中從灰度墊創建AND DISPLAY直方圖?這裏是我的代碼...如何在OpenCV4Android中創建和顯示直方圖?
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));
顯示方法,我自己創建:
公共類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)
我想我的問題是我想顯示直方圖的方式...... prolly我不能將其轉換爲bmp。什麼是顯示直方圖的好方法?
嘿,你是如何解決這個問題的? – Solace