我想在OnCameraFrame中绘制关键点,但我得到一个错误,有人可以帮助我吗?我把我的代码放在下面:
代码:
MatOfKeyPoint points = new MatOfKeyPoint();
Mat mat = (Mat) inputFrame;
FeatureDetector fast = FeatureDetector.create(FeatureDetector.FAST);
fast.detect(mat, points);
Scalar redcolor = new Scalar(255,0,0);
Mat mRgba= mat.clone();
Imgproc.cvtColor(mat, mRgba, Imgproc.COLOR_RGBA2RGB,4);
Core.line(mRgba, new Point(100, 100), new Point(300,300), new Scalar(0, 0, 255));
Features2d.drawKeypoints(mRgba, points, mRgba, redcolor, 3);
return mRgba;
我的LogCat是这样的:
11-26 16:22:49.305: D/JavaCameraView(22620): Starting processing thread
11-26 16:22:51.615: I/Choreographer(22620): Skipped 182 frames! The application may be doing too much work on its main thread.
11-26 16:22:51.735: D/JavaCameraView(22620): Preview Frame received. Frame size: 1382400
11-26 16:22:51.735: I/ActivityManager(22620): Timeline: Activity_idle id: android.os.BinderProxy@428db6c0 time:135999496
11-26 16:22:51.755: W/dalvikvm(22620): threadid=13: thread exiting with uncaught exception (group=0x41875e48)
11-26 16:22:51.755:E / AndroidRuntime(22620):致命异常:Thread-35591 11-26 16:22:51.755:E / AndroidRuntime(22620):进程:com.nummist.secondsight,PID:22620 11-26 16:22:51.755:E / AndroidRuntime(22620):java.lang.ClassCastException:org.opencv.android.JavaCameraView $ JavaCameraFrame无法强制转换为org.opencv.core.Mat 11-26 16:22:51.755:E / AndroidRuntime(22620):at com.nummist.secondsight.CameraActivity.onCameraFrame(CameraActivity.java:373) 11-26 16:22:51.755:E / AndroidRuntime(22620):at org.opencv.android.CameraBridgeViewBase.deliverAndDrawFrame(CameraBridgeViewBase.java:387) 11-26 16:22:51.755:E / AndroidRuntime(22620):at org.opencv.android.JavaCameraView $ CameraWorker.run(JavaCameraView.java:328) 11-26 16:22:51.755:E / AndroidRuntime(22620):at java.lang.Thread.run(Thread.java:841) 11-26 16:22:51.775:D / JavaCameraView(22620):收到预览帧。尺寸:1382400 11-26 16:22:51.795:D / JavaCameraView(22620):断开与摄像头的连接 11-26 16:22:51.795:D / JavaCameraView(22620):通知线程 11-26 16:22:51.795:D / JavaCameraView(22620):为线程作弊
在粗体上是红色的LogCat消息
答案 0 :(得分:0)
我不确定,但我认为你必须使用:
MatOfKeyPoint points = new MatOfKeyPoint();
Mat mat = inputFrame.rgba();
FeatureDetector fast = FeatureDetector.create(FeatureDetector.FAST);
fast.detect(mat, points);
Scalar redcolor = new Scalar(255,0,0);
Mat mRgba= mat.clone();
Imgproc.cvtColor(mat, mRgba, Imgproc.COLOR_RGBA2RGB,4);
Core.line(mRgba, new Point(100, 100), new Point(300,300), new Scalar(0, 0, 255));
Features2d.drawKeypoints(mRgba, points, mRgba, redcolor, 3);
return mRgba;