Issues with Camera Preview


Last Updated:

  1. ophanin

    ophanin Member This Topic's Starter

    Joined:
    Jun 14, 2010
    Messages:
    20
    Likes Received:
    0
    Hi all,

    I am currently trying to develop on a Motorola Droid for a project, and I am trying to use the camera preview and its callback for taking the images directly from the feed.

    This has not been as straightforward as I thought it should be, mostly due to the preview being in the YUVSP420 (at least, I believe so) format. After searching through a lot of the developer resources, I found some conversion code posted by (who I believe was) an Android Engineer, which would convert the raw image to a RGB, but I cannot seem to get this to work correctly. I get a very warped image, with the colors very far off. I think this may be due to using the wrong resolution for the conversion.

    My question here, mostly, is does anyone have any suggestions? Also, is there an easy way to find what resolution an image is from the previewCallback? I can post more specific code and values, if they are necessary, I just do not have it running right now.
     

    Advertisement
  2. IanGClifton

    IanGClifton Well-Known Member

    Joined:
    Feb 7, 2010
    Messages:
    111
    Likes Received:
    19
    What are you trying to accomplish with the callback? It seems like using camera.takePicture() would be a better choice if you're working with the image data in most cases. That'd let you specify the jpeg callback, which gives you a much more easily used format.
     
  3. ophanin

    ophanin Member This Topic's Starter

    Joined:
    Jun 14, 2010
    Messages:
    20
    Likes Received:
    0
    My application is more real time. I first investigated taking the picture itself, but the lag will be a bit much for me to handle (in in the end, the plan is to make a disability assistance program for people with limited vision).

    So, in essence, I looked into picture taking, but it wouldn't serve my needs.
     
  4. IanGClifton

    IanGClifton Well-Known Member

    Joined:
    Feb 7, 2010
    Messages:
    111
    Likes Received:
    19
    Would it help to call setPreviewFormat(ImageFormat.JPEG) to work with JPEG data instead of the default NV21? (You could also try ImageFormat.RGB_565)
     
  5. dev47

    dev47 Member

    Joined:
    Apr 13, 2010
    Messages:
    17
    Likes Received:
    5
    Check out the Camera.Parameters class (acquire via Camera.getParameters())
    You can check/set preview (including callback) sizes etc
     
  6. ophanin

    ophanin Member This Topic's Starter

    Joined:
    Jun 14, 2010
    Messages:
    20
    Likes Received:
    0
    The preview format is only available in FroYo, but I was able to find a workaround from a post by a Google engineer. Hopefully, when I finally get FroYo on my dev phone, it'll be a much quicker process! :)
     
  7. Androidneer

    Androidneer New Member

    Joined:
    Jul 5, 2010
    Messages:
    3
    Likes Received:
    0
    Hi All,
    Am a newbie. I am able to get the preview frames supposedly in YCrDr420 format. I am not sure despite setting setpreviewformat as JPEG, the call back byte[] will be JPEG or YCrDr420.

    Now, I neeed to convert this in to JPEG? Any help is appreciated.Thanks
     
  8. ophanin

    ophanin Member This Topic's Starter

    Joined:
    Jun 14, 2010
    Messages:
    20
    Likes Received:
    0
    They come normally in the YUV420 format, that's just how the camera takes them. I am unsure of how it handles it when the format is changed (I haven't been able to try it in 2.2).

    The easiest way to find out if it's coming is probably to just use the BitmapFactory.decodeByteArray method. Since it's (at least should be) coming in as JPEG, the BitmapFactory should recognize it and convert it.
     
  9. Androidneer

    Androidneer New Member

    Joined:
    Jul 5, 2010
    Messages:
    3
    Likes Received:
    0
    Thanks for the quick reply. my code is as follows::

    mCamera.setPreviewCallback(new PreviewCallback()
    {
    public void onPreviewFrame(byte[] _data, Camera _camera)
    {

    Bitmap bmp = BitmapFactory.decodeByteArray(_data,0, _data.length);

    imv = (ImageView)findViewById(R.id.ImageView01);
    imv.setImageBitmap(bmp);
    System.out.println("bmp painted ");


    }
    });


    } catch (Exception exception) {
    mCamera.release();
    mCamera = null;
    // TODO: add more exception handling logic here
    }
    }

    i am getting the bitmap, and i need to set it in Image view. How do i accomplish this?
    thanks.
     
  10. ophanin

    ophanin Member This Topic's Starter

    Joined:
    Jun 14, 2010
    Messages:
    20
    Likes Received:
    0
    Can do something like this, with an ImageView (ImageView01) in your layout

    ImageView image = (ImageView) findViewById(R.id.ImageView01);
    Bitmap newImage = BitmapFactory.decodeByteArray(_data,0, _data.length);
    image.setImageBitmap(newImage);

    May have to change a little based on your program, but that's the basic idea
     
  11. Rev0lucian

    Rev0lucian Member

    Joined:
    Jul 8, 2010
    Messages:
    12
    Likes Received:
    0

Share This Page

Loading...