0

I am trying to load an image into a bitmap so I can make some processing on tha cameraframe, but I keep getting bmp == null when I try to use the static image. Here is my code:

public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
        String path = Environment.getExternalStorageDirectory().getAbsolutePath();
        File file = new File(path,"/myopencv/myimage.bmp");
    if (file.exists()) {
        objectbmp = BitmapFactory.decodeFile(path);
        object = new Mat();
        Log.e("Get frame","next line generates the error: bmp == null");
        Utils.bitmapToMat(objectbmp, object);
       }
  }

So I used Eclipse to open my DDMS towards my physical device. I created a new folder myopencv inside /storage/sdcard0/. Then I placed the myimage.bmp file there using Eclipses tool (Push a file onto the device). So the file clearly exists. Also I test for it, to see if the file exists, and it seems to exist. So why is it null? How can I make this work properly?

4

1 回答 1

0

如果您的文件确实存在,我只猜测objectbmp是无效的。文档说:

bmp - 是“ARGB_8888”或“RGB_565”类型的有效输入位图对象。

为什么不使用Highgui.imread?文档说:

从文件加载图像。

函数 imread 从指定文件加载图像并返回。如果无法读取图像(由于丢失文件、权限不正确、格式不支持或无效),该函数返回一个空矩阵(Mat.data==NULL)。目前,支持以下文件格式:

Windows 位图 - *.bmp、*.dib(始终支持) JPEG 文件 - *.jpeg、*.jpg、*.jpe(参见注释部分) JPEG 2000 文件 - *.jp2(参见注释部分) 便携式网络图形- *.png(请参阅 注释部分)便携式图像格式 - *.pbm、*.pgm、*.ppm(始终支持)太阳光栅 - *.sr、*.ras(始终支持)TIFF 文件 - *.tiff、 *.tif(见注释部分)

于 2015-02-28T17:09:36.567 回答