baharsan
baharsan

Reputation: 181

What Default Type Mat Image OpenCV4Android?

ImageManipulationsActivity.VIEW_MODE_BINARY:
capture.retrieve(mRgba, Highgui.CV_CAP_ANDROID_COLOR_FRAME_RGBA);

Mat binary = new Mat();
Imgproc.cvtColor(mRgba,binary, Imgproc.COLOR_RGBA2GRAY, 4);

int size = (int) binary.total() * binary.channels();
double[] buff = new double[size];
binary.get(0, 0, buff);

for(int i = 0; i < size; i++)
{
    buff[i] = (buff[i] >= 0) ? 1 : 0;
}

Mat bv = new Mat(binary.size(), CvType.CV_8U);
bv.put(0, 0, buff);

Imgproc.cvtColor(binary, mRgba, Imgproc.COLOR_GRAY2RGBA, 4);

break;

Above code is used for binarize gray image in opencv4android, but until know that's not work for me, i copy above code from here, in above code, i try :

  1. Retrive Mat Image using : capture.retrieve
  2. Convert Image to Grayscale using Imgproc.cvtColor
  3. Binarize using Java Primitive Array like above code
  4. Then Convert back from gray to rgba
  5. Show result using Bitmap bmp

If you have something to suggest, please tell me. I don't know what i wrong from above code, it's no error, but when i install the app and run it, it always forceclose.

this is logcat from app :

FATAL EXCEPTION: Thread-10 java.lang.UnsupportedOperationException: Mat data type is not compatible: 0 at org.opencv.core.Mat.get(Mat.java:2042) at org.opencv.samples.imagemanipulations.ImageManipulationsView.processFrame(ImageM‌​anipulationsView.java:158) at org.opencv.samples.imagemanipulations.SampleCvViewBase.run(SampleCvViewBase.java‌​:99) at org.opencv.samples.imagemanipulations.ImageManipulationsView.run(ImageManipulati‌​onsView.java:195) at java.lang.Thread.run(Thread.java:1019)

Upvotes: 2

Views: 3786

Answers (1)

baharsan
baharsan

Reputation: 181

The Default Type of Mat is CV_8UC1 whether single channels or 3 channels (BGR) -Basic Structure OpenCV-

Upvotes: 3

Related Questions