Converting histogram Mat to BitMap - Getting OpenCV Error (src.type() == CV_8UC1 || src.type() == CV_8UC3 || src.type() == CV_8UC4)
I am trying to calculate the histogram from this image and trying to convert it to a Bitmap and display it.
And I am getting the following error. The question is why, and how can I fix it?
06-26 14:07:18.972: E/cv::error()(1278): OpenCV Error: Assertion failed (src.type() == CV_8UC1 || src.type() == CV_8UC3 || src.type() == CV_8UC4) in void Java_org_opencv_android_Utils_nMatToBitmap2(JNIEnv *, jclass, jlong, jobject, jboolean), file /hdd2/buildbot/slaves/slave_ardbeg1/50-SDK/opencv/modules/java/generator/src/cpp/utils.cpp, line 98
06-26 14:07:18.992: A/libc(1278): Fatal signal 11 (SIGSEGV) at 0x997fcff4 (code=2), thread 1278 (tests.testfive)
Following is the relevant part of my code.
//Get the image from file path
rgbaMat = new Mat();
rgbaMat = Highgui.imread(filePath);
Bitmap objectSubmatBitmap = Bitmap.createBitmap(rgbaMat.cols(), rgbaMat.rows(), Bitmap.Config.ARGB_8888);
Utils.matToBitmap(rgbaMat, objectSubmatBitmap);
imageViewOne.setImageBitmap(objectSubmatBitmap);
//Preprocessing - color space conversion
Imgproc.cvtColor(rgbaMat, rgbaMat, Imgproc.COLOR_BGR2RGB);
Mat hsvMat = new Mat();
Imgproc.cvtColor(rgbaMat, hsvMat, Imgproc.COLOR_RGB2HSV);
//Calculate Histogram
List<Mat> sourceImageList = new ArrayList<Mat>();
sourceImageList.add(hsvMat);
Mat histogram = new Mat();
//histogramMat.convertTo(histogramMat, CvType.CV_8UC1);
Imgproc.calcHist(sourceImageList, new MatOfInt(2), new Mat(), histogram, new MatOfInt(256),
new MatOfFloat(0f, 256f));
//Highgui.imwrite("/mnt/sdcard/histogram.bmp", histogram);// check
Bitmap histogramBitmap =
Bitmap.createBitmap(histogram.cols(), histogram.rows(), Bitmap.Config.ARGB_8888);
Utils.matToBitmap(histogram, histogramBitmap);
imageViewOne.setImageBitmap(histogramBitmap);