I am trying to process the image as soon as the picture is taken, i.e. in the onPictureTaken() . As far as I understand, I have to convert the byte array to the OpenCV matrix, but the whole application freezes when I try to do this. Basically everything I did was the following:
@Override public void onPictureTaken(byte[] bytes, Camera camera) { Log.w(TAG, "picture taken!"); if (bytes != null) { Bitmap image = BitmapFactory.decodeByteArray(bytes, 0, bytes.length); Mat matImage = new Mat();
Does anyone know why it freezes and how to solve it?
Note. I used the OpenCV4Android 3 tutorial as a basis.
Update 1: I also tried evaluating the bytes (without any success) as follows:
Mat mat = Imgcodecs.imdecode( new MatOfByte(bytes), Imgcodecs.CV_LOAD_IMAGE_UNCHANGED );
Update 2: Presumably this should work, but it is not for me.
Mat mat = new Mat(1, bytes.length, CvType.CV_8UC3); mat.put(0, 0, bytes);
And this option was not:
Bitmap image = BitmapFactory.decodeByteArray(bytes, 0, bytes.length); Mat mat = new Mat(image.getHeight(), image.getWidth(), CvType.CV_8UC1); mat.put(0, 0, bytes);
Update 3: This also did not work for me:
Mat mat = new MatOfByte(bytes);