Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

I've read the example has to been fixed:

https://github.com/Itseez/opencv/pull/838/files#r3914912

http://code.opencv.org/issues/2961

https://code.google.com/p/android/issues/detail?id=13966

I've changed my code to this:

public void takePicture(final String fileName) {
    //Log.i(TAG, "Taking picture");
    this.mPictureFileName = fileName;
    // Call to garbage collector to avoid bug http://code.opencv.org/issues/2961 
    System.gc();
    // PictureCallback is implemented by the current class
    mCamera.setPreviewCallback(null);
    mCamera.setOneShotPreviewCallback(null);
    mCamera.takePicture(null, null, this);
}


@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();

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

          fos.write(data);
          fos.close();

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

}

But I have still the same problem: After taken the first picture the screen freezes and no preview is shown.

What can be done to fix the problem?

I've read the example has to been fixed:

https://github.com/Itseez/opencv/pull/838/files#r3914912

http://code.opencv.org/issues/2961

https://code.google.com/p/android/issues/detail?id=13966

I've changed my code to this:

public class JavaCameraViewExtended extends JavaCameraView implements PictureCallback {
public void takePicture(final String fileName) {
    //Log.i(TAG, "Taking picture");
    this.mPictureFileName = fileName;
    // Call to garbage collector to avoid bug http://code.opencv.org/issues/2961 
    System.gc();
    // PictureCallback is implemented by the current class
    mCamera.setPreviewCallback(null);
    mCamera.setOneShotPreviewCallback(null);
    mCamera.takePicture(null, null, this);
}


@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();

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

          fos.write(data);
          fos.close();

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

}
}

But I have still the same problem: After taken the first picture the screen freezes and no preview is shown.

What can be done to fix the problem?

I've read the example has to been fixed:

https://github.com/Itseez/opencv/pull/838/files#r3914912

http://code.opencv.org/issues/2961

https://code.google.com/p/android/issues/detail?id=13966

I've changed my code to this:

public class JavaCameraViewExtended Tutorial3View extends JavaCameraView implements PictureCallback {
public void takePicture(final String fileName) {
    //Log.i(TAG, "Taking picture");
    this.mPictureFileName = fileName;
    // Call to garbage collector to avoid bug http://code.opencv.org/issues/2961 
    System.gc();
    // PictureCallback is implemented by the current class
    mCamera.setPreviewCallback(null);
    mCamera.setOneShotPreviewCallback(null);
    mCamera.takePicture(null, null, this);
}


@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();

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

          fos.write(data);
          fos.close();

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

}
}

But I have still the same problem: After taken the first picture the screen freezes and no preview is shown.

What can be done to fix the problem?