OpenCV的与Android捕获映像 [英] OpenCV with Android Capture Images

查看:201
本文介绍了OpenCV的与Android捕获映像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是捕捉图片的最佳途径Android和与OpenCV的处理呢? 我应该使用的表面观由于这里还是应该使用OpenCV的摄像头为OpenCV的样本?我怎么可以加载所拍摄的图像,并将其转换为太? 在此先感谢

 私人PictureCallback mPicture =新PictureCallback(){

        @覆盖
    公共无效onPictureTaken(byte []的数据,摄像头摄像头){

        文件PictureFile的= getOutputMediaFile(MEDIA_TYPE_IMAGE);
        如果(PictureFile的== NULL){
            Log.d(E,
                    错误创建的媒体文件,检查存储权限);
            返回;
        }

        尝试 {

            FileOutputStream中FOS =新的FileOutputStream(PictureFile的);
            fos.write(数据);
            fos.close();
            // processImage来();
        }赶上(FileNotFoundException异常E){
            Log.d(E,找不到文件:+ e.getMessage());
        }赶上(IOException异常E){
            Log.d(E,访问文件时出错:+ e.getMessage());
        }
    }
 

解决方案

在OpenCV的样品有一个CameraBridgeViewBase,有助于捕捉,处理和显示的相机preVIEW结果(低清晰度的图像连续的数据流)

如果你想处理有更高的分辨率单捕获,你应该使用类似的东西来onPictureTaken()。然后你就可以读取图像使用<一个href="http://docs.opencv.org/java/org/opencv/highgui/Highgui.html#imread%28java.lang.String%29">Highgui.imread()并对其进行处理。

您也可以避免写入和读出到文件从数据数组<一个创建位图href="http://developer.android.com/reference/android/graphics/BitmapFactory.html#de$c$cByteArray%28byte%5B%5D,%20int,%20int,%20android.graphics.BitmapFactory.Options%29">BitmapFactory.de$c$cByteArray()然后将位图转换为使用垫<一href="http://docs.opencv.org/java/org/opencv/android/Utils.html#bitmapToMat%28android.graphics.Bitmap,%20org.opencv.core.Mat%29">Utils.bitmapToMat()

What is the best way to capture images in android and process them with opencv ? should i use the surface view As here or i should use the opencv camera as in opencv samples ? and how can i load the captured image and convert it to Mat? Thanks in advance

 private PictureCallback mPicture = new PictureCallback() {

        @Override
    public void onPictureTaken(byte[] data, Camera camera) {

        File pictureFile = getOutputMediaFile(MEDIA_TYPE_IMAGE);
        if (pictureFile == null) {
            Log.d("E",
                    "Error creating media file, check storage permissions ");
            return;
        }

        try {

            FileOutputStream fos = new FileOutputStream(pictureFile);
            fos.write(data);
            fos.close();
            //processImage();
        } catch (FileNotFoundException e) {
            Log.d("E", "File not found: " + e.getMessage());
        } catch (IOException e) {
            Log.d("E", "Error accessing file: " + e.getMessage());
        }
    }

解决方案

In the OpenCV samples there is a CameraBridgeViewBase that helps in capturing, processing and showing the results of the camera preview (continuous stream of lower resolution images).

If you want to process a single capture with more resolution, you should use something similar to onPictureTaken(). Then you can read the image using Highgui.imread() and process it.

You could also avoid writing and reading to a file by creating a Bitmap from the data array with BitmapFactory.decodeByteArray() and then converting the Bitmap to a Mat using Utils.bitmapToMat()

这篇关于OpenCV的与Android捕获映像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆