本文介绍了安卓:实时图像处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,它接受一个照相机preVIEW,执行对每帧(例如,边缘检测,色彩变化,图像翘曲等)的一些基本的图像处理功能而在实时显示所修改的帧到屏幕。类似纸相机应用程序在Android Market中。

I have an application which takes a camera preview, performs some basic image processing function on every frame (e.g. edge detection, colour change, image warp etc.) and displays the modified frame to the screen in "real time". Similar to the "Paper Camera" app in Android Market.

我的做法摘要:

A summary of my approach:

1:创建一个的FrameLayout两个重叠的意见:

一个SurfaceView传递给Camera.set previewDisplay()。 (传递null将prevent相机preVIEW开始在某些设备上 - 采用的Andr​​oid 4.0之前,要做到这一点OpenCV的)。

A SurfaceView to pass to Camera.setPreviewDisplay(). (Passing null would prevent the camera preview starting on some devices - opencv used to do this before Android 4.0?).

所谓的实时查看延伸查看和实现摄像头。previewCallBack类。这一观点得到帧的摄像头,并修改(如边缘检测)后显示的帧。这个观点是对的SurfaceView之上。

A class called "LiveView" which extends View and implements Camera.PreviewCallBack. This view receives frames from the camera, and displays the frame after modification (e.g. edge detection). This View is on top of the SurfaceView.

2:我叫Camera.set previewCallbackWithBuffer(),使帧发送到我的LiveView

3:实时查看,我把捕获的帧(字节[])的在上previewFrame(),从YUV转换为RGB和执行图像处理功能,并调用postInvalidate()(本YUV2RGB转换和图像处理在本地code完成)

4:在实时查看的的OnDraw()方法中,我创建了修改RGB帧位图(字节[]),并绘制位图的画布

本作品(5fps的和在各种设备之间10fps的),但我想听听别人怎么接触过这个问题,以及如何可以改善。特别是:

This works (between 5fps and 10fps on various devices), but I would like to hear how others have approached this problem, and how it could be improved. In particular:

  • ,我会获得任何性能通过扩展GLSurfaceView而不是视图创建的LiveView类?
  • 这听起来非常低效有两个表面被更新的每一帧。是否有别的选择吗?
  • 要更有效地做到这一点,我要访问摄像机的母语水平? - 我相信的OpenCV采用这种方法

非常感谢

推荐答案

我也做了这样的事情。我做的是延长了摄像头视图。我不认为相机视图每帧更新,但检索。而且只有已更改视图将不得不进行更新。OpenCV的做确实比原生相机更好的工作。导入后 org.opencv.highgui.VideoCapture ,可以使用直接访问摄像机:

I have also done something like this. What I do is extend the Camera View. I don't think the camera view is updated every frame, but retrieved. And only the View that you have changed would have to be updated.OpenCv do does a better job than native camera. After importing org.opencv.highgui.VideoCapture , you can directly access the camera using:

VideoCapture camera;
camera.retrieve(mGrayMat, Highgui.CV_CAP_ANDROID_GREY_FRAME);

要mGrayMat转换为mRgbaMat:(org.opencv.imgproc.Imgproc)

to convert mGrayMat to mRgbaMat: ( org.opencv.imgproc.Imgproc)

Imgproc.cvtColor(mGrayMat, mRgbaMat, Imgproc.COLOR_GRAY2BGRA, 4);

这篇关于安卓:实时图像处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 01:20