Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/321.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在onPictureTaken之后获取黑色预览和图像_Java_Android_Opencv_Image Processing - Fatal编程技术网

Java 在onPictureTaken之后获取黑色预览和图像

Java 在onPictureTaken之后获取黑色预览和图像,java,android,opencv,image-processing,Java,Android,Opencv,Image Processing,我正在尝试开发一个应用程序,可以自动裁剪使用opencv检测到的卡片边缘 Here in this function i am doing the following : 1) 将字节数组(即数据)转换为位图,然后转换为Mat 2) 裁剪卡的所需部分并重新调整其大小 3) 将mat转换回字节数组 4) 将修改后的字节数组保存在文件中(jpg) } 图片保存在内存中,但预览和图像都是空白的。保存的文件也需要大约3.5 Mb,这可能是什么原因? 提前谢谢 检查onPictureTaken方法中的

我正在尝试开发一个应用程序,可以自动裁剪使用opencv检测到的卡片边缘

 Here in this function i am doing the following :
1) 将字节数组(即数据)转换为位图,然后转换为Mat

2) 裁剪卡的所需部分并重新调整其大小

3) 将mat转换回字节数组

4) 将修改后的字节数组保存在文件中(jpg)

}

图片保存在内存中,但预览和图像都是空白的。保存的文件也需要大约3.5 Mb,这可能是什么原因?
提前谢谢

检查
onPictureTaken
方法中的
data==null
BitmapFactory.Options opts=new BitmapFactory.Options();位图位图=位图工厂.decodeByteArray(数据,0,数据长度,opts)
尝试使用这些行从数据中解码位图。@如果避免了前3步,则图像会正确保存,并带有拍摄的照片d
camera.stopPreview()
camera.startPreview()
Mat Mat=新Mat()之前此行..@ELITE对不起,这两种方法都可以检查
onPictureTaken
方法中的
data==null
BitmapFactory.Options opts=new BitmapFactory.Options();位图位图=位图工厂.decodeByteArray(数据,0,数据长度,opts)
尝试使用这些行从数据中解码位图。@如果避免了前3步,则图像会正确保存,并带有拍摄的照片d
camera.stopPreview()
camera.startPreview()
Mat Mat=新Mat()之前这行..@ELITE对不起,两个力都没用
@Override
public void onPictureTaken(byte[] data, Camera camera) {
    Mat mat=new Mat();
    Bitmap bmp = BitmapFactory.decodeByteArray(data, 0, data.length);
    Utils.bitmapToMat(bmp, mat);   //converting a mat to bitmap

    Mat matCrop = mat.submat((int)p1.y,(int)p2.y,(int)p3.x,(int)p4.x);//surely no issues here

    Imgproc.resize(matCrop, matCrop, mat.size());

    byte[] imageInBytes = new byte[(int)(matCrop.total() * matCrop.channels())];
    mat.get(0, 0, imageInBytes);
    data=imageInBytes;

            try {
        FileOutputStream fos = new FileOutputStream(mPictureFileName);
        fos.write(data);
        fos.close();
    } catch (java.io.IOException e) {}