如何获得来自OpenCV的机器人的字节[]垫目标? [英] How to get the Mat object from the Byte[] in openCV android?

查看:148
本文介绍了如何获得来自OpenCV的机器人的字节[]垫目标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作与Android的OpenCV库。我有一个实现 PictureCallBack

I am working with OpenCV library in Android. I have a class which implements PictureCallBack.

覆盖方法 onPictureTaken()是下面给出,

     @Override
public void onPictureTaken(byte[] data, Camera camera) {
    Log.i(TAG, "Saving a bitmap to file");
    // The camera preview was automatically stopped. Start it again.
    mCamera.startPreview();
    mCamera.setPreviewCallback(this);

    // Write the image in a file (in jpeg format)
    try {
        FileOutputStream fos = new FileOutputStream(mPictureFileName);
        fos.write(data);
        fos.close();

    } catch (java.io.IOException e) {
        Log.e("PictureDemo", "Exception in photoCallback", e);
    }
}

至于我想在图像处理进一步保存和重新加载图像代替使用的图像数据。

As I want image data to be used further in image processing in stead of saving and reloading the image.

什么是最有效的方法从字节数组获取垫目标? 我已经尝试这些方法:

What is the most efficient way for getting the Mat object from the Byte array? I have already tried these approaches:

  1. 不知道发生了什么事的形象。

  1. Don't know what happened to the image.

板M =新垫();    m.put(0,0,数据);

Mat m=new Mat(); m.put(0,0,data);

转换为位图,然后使用 bitmapToMat() 在这种情况下,红色变成蓝色。

Converting to Bitmap then use bitmapToMat() In this case , red color becomes blue .

我也没有拯救供将来使用的图像中的任何问题,但是这导致了我,因为尚未生成的文件还没有一个例外,当我使用previously存储的图像。

I also don't have any problem in saving the image for future use,but this leads me an exception because the file not have been generated yet, when I am using the previously stored image.

推荐答案

您必须指定宽度图像/垫和渠道的深度和高度。

You have to specify width and height of the image/Mat and channels depth.

Mat mat = new Mat(width, height, CvType.CV_8UC3);
mat.put(0, 0, data);

请确保您使用的是正确类型的垫子。也许你的数据不是3个字节的RGB格式,你应该使用其他类型的如 CvType.CV_8UC1
祝你好运!

Make sure you are using correct type of Mat. Maybe your data is not in 3 bytes RGB format and you should use another type e.g. CvType.CV_8UC1.
Good luck!

这篇关于如何获得来自OpenCV的机器人的字节[]垫目标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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