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;
上面的代码用于在opencv4android中对灰度图像进行二值化处理,但是直到知道这对我不起作用,我才复制here上面的代码,在上面的代码中,我尝试:
如果您有什么建议,请告诉我。我不知道上面的代码我错了什么,这没有错误,但是当我安装应用程序并运行它时,它始终强制关闭。
这是来自app的logcat:
FATAL EXCEPTION:Thread-10 java.lang.UnsupportedOperationException:Mat数据类型不兼容:0 org.opencv.core.Mat.get(Mat.java:2042)at org.opencv.samples.imagemanipulations.ImageManipulationsView .processFrame(ImageM anipulationsView.java:158)org.opencv.samples.imagemanipulations.SampleCvViewBase.run(SampleCvViewBase.java:99)at org.opencv.samples.imagemanipulations.ImageManipulationsView.run(ImageManipulati onsView.java: 195)在java.lang.Thread.run(Thread.java:1019)