We are using an LG Optimus speed and are trying to obtain an image from the camera with our own activity. The Code we are using to do so is:
GetImage(new PictureCallback(){
#Override
public void onPictureTaken(byte[] data, Camera camera) {
camera.startPreview();
bmp = BitmapConversion.convertBmp(data));
}
});
...
public static void GetImage(final PictureCallback jpgCallback) {
GetCamera().autoFocus(new AutoFocusCallback(){
#Override
public void onAutoFocus(boolean success, Camera camera) {
if(success)
GetCamera().takePicture(null, null, jpgCallback);
else
GetImage(jpgCallback);
}
});
}
The images have a considerable worse quality than the images obatained with the native android camera app. Here are 2 example pictures, both taken with a resolution of 640x480 an magnified. As you can see the left picture taken with the native app looks "cleaner" than the right taken with our own application.
Any Ideas?
You don't know what the native app is doing in terms of configuring the camera before taking the image and post-processing after taking the image.
There are many settings available on the camera which are well documented and should be investigated.
You should also be aware that vastly different results exist on using the same method but with the slightest variation in light and focus.
Try looking into the autofocus settings and perhaps do something on autofocus callback.
When comparing the two methods make sure your camera is balanced on something rather than handheld and ensure that the distance and light levels are identical.
Related
I am developing an android application in which the camera preview is shown at all times. When the user wants, he can take a picture of that preview with the takePicture (), and apply different filters that picture.
The problem is that when I take a picture with takePicture () method, the picture freezes for a while and I want this freeze-frame remains as long as the user wants to apply the necessary filters, and when he wants, return to preview mode the camera immediately.
I am using the OpenCV library and specifically the JavaCameraView class to get the parameters of the camera and then take the pictures I want.
mCamera.takePicture(null,null,new Camera.PictureCallback() {
#Override
public void onPictureTaken(byte[] data, Camera myCamera) {
if(data != null){
bm = BitmapFactory.decodeByteArray(data, 0, data.length);
Log.i(TAG, "Caracteristicas de la foto: "+bm.getWidth()+"x"+bm.getHeight());
mCamera.startPreview();
}
}
};
In the onPictureTaken () method I store the image into a bitmap, and then to draw it on a canvas with the resolution of the camera. This will be done in CameraBridgeViewBase class.
Thank you in advance!
You can restart preview immediately from onPictureTaken() callback. The trick is that you put the ImageView that displays the captured image on top of the SurfaceView where you display live preview. Now, it's enough to imageView.setVisibility(View.GONE) and your preview will be immediately live.
In my Android app I want to take a photo. I have Samsung galaxy Gio (Android 2.3.3) and I was simply using camera.takePicture(null, null, Activity.this);, in my Activity I implemented PictureCallback method and everything was fine until I checked my app on Sony Xperia S (Android 4.0), on this phone the preview didn't freeze however it took a photo, so I add camera.stopPreview() function after taking a picture and now it was working fine on Xperia S but on my Samsung GIO after implementing this my screen after taking a photo goes black, does anyone have idea how to solve it ? Thanks for help
Here is my code:
When user clicks framelayout I use:
case R.id.camera_preview:
camera.takePicture(null, null, Activity.this);
break;
And in Activity i implemented picturecallback method:
public void onPictureTaken(byte[] data, Camera arg1) {
imageData = data;
cam_preview.stopPreview();
}
I'm not saving image immediately because I'm giving user choice to save or not to save a picture
From http://developer.android.com/reference/android/hardware/Camera.html#takePicture(android.hardware.Camera.ShutterCallback, android.hardware.Camera.PictureCallback, android.hardware.Camera.PictureCallback, android.hardware.Camera.PictureCallback):
"Preview will be stopped after the image is taken; callers must call startPreview() again if they want to re-start preview or take more pictures."
So according to this the picture callback should be as follow:
public void onPictureTaken(byte[] data, Camera arg1) {
imageData = data;
cam_preview.startPreview();
}
From my current search, Android camera intent can not specify pictureSize.
Since my app needs to be fast, I do not want to save a large size picture in sd card, then load it to a small size of Bitmap. I think it takes time. Plus, I need a gray scale image, rather than a color Bitmap. I know how to convert them, but again it takes time.
I plan to take a picture at a specified size, and directly process the Y part (gray scale) in the YUV data in the memory.
So does that mean I have to write my own camera app using camera API?
Are there any good examples?
Many examples I checked so far often do not consider autofocus.
I add features in XML file:
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
I add the auto focus mode to the camera parameter.
parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO);
But it does not work.
So I add autofocus command immediately before camera press button.
preview.camera.autoFocus(myAutoFocusCallback);
preview.camera.takePicture(shutterCallback, rawCallback, jpegCallback);
But the autofocus takes some time, and until the preview becomes clear, the take pictures has been performed.
Plus, I also want it to autofocus even if I do not press the camera button.
How can I put autofocus nicely in it?
Are there any good examples?
Thanks.
The Android Developers Guide has a tutorial on making a camera app: http://developer.android.com/guide/topics/media/camera.html#custom-camera
You don't need to add both the camera and the camera.autofocus features in the manifest. The latter implies the first - though it's not really a problem.
FOCUS_MODE_AUTO does not mean it the cameras will focus continuously, just that it will use autofocus at some point (instead of manual focus) by a callback function. You'll need FOCUS_MODE_CONTINUOUS_PICTURE if you want the camera focusing by itself. It's explained in the documentation.
As for taking pictures before the camera is focused: try calling takePicture() from inside your autoFocusCallback like this:
private AutoFocusCallback myAutoFocusCallback = new AutoFocusCallback() {
#Override
public void onAutoFocus(boolean success, Camera camera) {
if (success) {
camera.takePicture(shutterCallback, rawCallback, jpegCallback);
}
}
};
I am taking a picture in Android (2.3 and greater) that takes a picture using camera.takePicture(). It works great, but I get weird behavior on different devices. On my Nexus One, the image I captured stays frozen for a few seconds before reverting to the preview. On my Transformer, it reverts to the preview almost immediately.
For now, a workaround would be to call camera.stopPreview() in the onShutter() event, but that's still a bit weird, since it's not showing the photo you took, it's showing what the preview saw a split second after you took the picture. On the Transformer, you can even see it "freeze-move-freeze" as it freezes for a split second after taking the picture, starts moving again, then gets to onShutter and freezes when I call stopPreview().
Does anyone know of a setting somewhere, or some code I could call, that would tell the camera how long to hold onto that image before restarting the preview? Or better yet, have it not automatically release the preview at all, and wait until I call startPreview?
on my devices I have to restart the preview manually, it doesn't start up itself after taking a picture. I use a picture callback like
camera.takePicture(null, null, takePictureCallback);
and the callback is
private Camera.PictureCallback takePictureCallback = new Camera.PictureCallback() {
#Override
public void onPictureTaken(byte[] data, Camera cam) {
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
if (camera != null) {
camera.startPreview();
}
canTakePicture = true;
}
}, PHOTO_PREVIEW_LENGTH);
new PhotoProcessor(activity, targetUri).execute(data);
}
};
PhotoProcessor saves the image, PHOTO_PREVIEW_LENGTH is the length in ms for how long is the captured image shown.
I am creating an Android app to do some image processing techniques with the camera and it needs to be fast. This is the pseudo-code of how the entire system works:
1. loop while not finished
1.1 get image frame
1.2 process image for object detection
2. end loop
I actually have questions on the basics of the Camera class:
Is previewing the perceived image from the camera faster than no previews at all? The former means using SurfaceView to preview the image.
Let's say from the takePicture() method, can the image data array be obtained without the previews?
My real question is, what is the best way to obtain the image data (say, byte[] array) quickly and iteratively after processing the image (as stated on top)?
I planned to use takePicture() method to get the image data, but I need your opinion if this is the only way or if there other better ways.
You can setup a SurfaceView as the Camera's preview display and get the data of every preview frame using the PreviewCallback. This would be better than using takePicture if you don't need the high resolution that takePicture captures. In other words, if you want to capture images of lower quality at a faster rate, use PreviewCallback... if you want to capture images of higher quality at a very slow rate, use takePicture.
As for your questions, I don't think you can take pictures without using a preview display, but i could be wrong.
class MainActivity extends Activity implements Camera.PreviewCallback, SurfaceHolder.Callback {
...
public void surfaceCreated(SurfaceHolder holder) {
camera = Camera.open();
camera.setPreviewCallback(this);
...
}
public void onPreviewFrame(byte[] data, Camera camera) {
// image data contained in data... do as you wish
}
}