Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
New Contributor
andy-playbook
Posts: 5
Registered: ‎01-08-2013
My Device: Playbook 16GB
My Carrier: Other
Accepted Solution

Camera API Viewfinder callback image format

Hi,

 

I'm trying to set the frame type in the viewfinder_callback to be RGB888 so that I can perform some basic processing. However, in the code below, camera_set_photovf_property returns EINVAL for every format apart from NV12.

 

err = camera_set_photovf_property( handle, CAMERA_IMGPROP_FORMAT, CAMERA_FRAMETYPE_RGB888);

    if(err != CAMERA_EOK)
    {
    	fprintf(stderr, "Unable to set property. Error: %d %d\n", err, EINVAL);
}

 Are the frame types limited to NV12 or am I doing something wrong?

 

Thanks,

 

Andy

 

Please use plain text.
BlackBerry Development Advisor
smcveigh
Posts: 668
Registered: ‎11-29-2011
My Device: developer
My Carrier: other

Re: Camera API Viewfinder callback image format

you can query available frametypes using camera_get_photovf_frame_types() and other similar functions:

http://developer.blackberry.com/native/reference/bb10/com.qnx.doc.camera.lib_ref/topic/camera_get_ph...

 

NV12 is the only supported format for the photo viewfinder presently though.  if you need RGB, you will have to convert the image format yourself or use the video viewfinder.  If you need to be able to capture photos though, you will have to stick with the photo vf.

 

What sort of processing do you need to do?

 

Please use plain text.
New Contributor
andy-playbook
Posts: 5
Registered: ‎01-08-2013
My Device: Playbook 16GB
My Carrier: Other

Re: Camera API Viewfinder callback image format

Thanks for the very helpful response.

 

Essentially, I'm trying to detect an object in the viewfinder. If that object is detected, more processing will be done on that object.

For the sake of an example, this principle is the same as some of the QR code reader mobile apps (I'm not trying to decode barcodes).

 

I have tried the video viewfinder and camera_get_videovf_frame_types() and this also appears to only support NV12.

I will try converting to RGB and check if it is possible to do the processing with NV12.

 

Thanks again!

Please use plain text.
New Contributor
andy-playbook
Posts: 5
Registered: ‎01-08-2013
My Device: Playbook 16GB
My Carrier: Other

Re: Camera API Viewfinder callback image format

Update:

 

Conversion from NV12 is not suitable for this application.

 

Is there a better way to get RGB888 images?

Please use plain text.
BlackBerry Development Advisor
smcveigh
Posts: 668
Registered: ‎11-29-2011
My Device: developer
My Carrier: other

Re: Camera API Viewfinder callback image format

If you are doing something like barcode scanning, and don't care about what colour things are, then NV12 is perfect as it provides a grayscale bitmap in the Y plane.  Quite often the first step in object recognition is to reduce an RGB image to grayscale, which is just extra work in that case.

 

I thought we had RGB support in the video viewfinder already for PlayBook, but it's possible that is only working on BB10 right now.  It may not have been backported to 2.1 yet.

 

Is conversion not feasible because it takes too long?  Have you considered reducing the video vf resolution?  Internally on BB10, we do the conversion as a screen blit from the NV12 buffer to an RGBA buffer, but this cannot be done in the application context without an additional memcpy().  If you're interested in going that route, you just need to allocate 2 pixmaps.. one NV12 and one RGBA, and the do a memcpy() from the camera_buffer_t->framebuf into your NV12 pixmap followed by a blit into the RGBA pixmap.

 

Cheers,
Sean

Please use plain text.
BlackBerry Development Advisor
smcveigh
Posts: 668
Registered: ‎11-29-2011
My Device: developer
My Carrier: other

Re: Camera API Viewfinder callback image format

[ Edited ]

update: it looks like there may be a bug in camera_get_videovf_frametypes()... try configuring it anyways and see what happens...

 

camera_set_videovf_property(handle,
    CAMERA_IMGPROP_FORMAT, CAMERA_FRAMETYPE_RGB8888,
    CAMERA_IMGPROP_CREATEWINDOW, 0);

Note there is currently a restriction that you cannot have a visible viewfinder in RGB mode.  This is just some legacy that we will be cleaning up in the future.  You would have to implement your own display code.

 

Cheers,

Sean

 

Please use plain text.
New Contributor
andy-playbook
Posts: 5
Registered: ‎01-08-2013
My Device: Playbook 16GB
My Carrier: Other

Re: Camera API Viewfinder callback image format

Thanks Sean, that's useful. Interesting that this works with RGB8888 and not RGB888.

 

It sounds like I need to wait a little while for this to work the way I would like.

In the mean time, I think should be able to test some of what I am doing with greyscale, detect the object and then use camera_take_photo() to get a different image format for further processing (on or off the device).

 

Thanks again,

 

Andy

 

Please use plain text.
BlackBerry Development Advisor
smcveigh
Posts: 668
Registered: ‎11-29-2011
My Device: developer
My Carrier: other

Re: Camera API Viewfinder callback image format

yup.. that's the approach I would go with for now.  cool.

 

RGB888 is a bit of a weird format, as it is not word-aligned, so is usually slower to process than RGB8888.

Please use plain text.