Android Question CameraEXClass Camera CameraEX

mast4rbug

Member
Licensed User
Longtime User
Hi. I'm new to the forum and I run the CameraEX Class example (You can find Initial Thread here: https://www.b4x.com/android/forum/t...tends-the-camera-library-functionality.23801/). I know that you can get RAW Camera Preview Data to do some work on the image, (I'm not talking about the JPG file, but the Data ARRAY in RAM to Access the RAW Data) and I wondered if someone know how to acces or what is the name of the Array? I didn't found any example about this on the forum. If someone can give some Hint, It would be really appreciated. Thanks in advance!
Cedric
 

JordiCP

Expert
Licensed User
Longtime User
Using CameraEx library and example, the camera_preview() event gives you a byte array (data) with the preview image in NV21 (YUV) format.

You can do several things with it, directly in B4A, inline Java, existing libs or building your own. But you'll find that the major drawback is speed.

The right choice depends on the kind of processing that you need:
If you need complex custom image processing routines, then I would recommend you to look how to make libraries and if you are good at C/C++, work with the NDK.

Some interesting links:
  • If you have already worked with OpenCV or want to learn --> @DrewG showed how to integrate JavaCV with B4A, here
  • Face detection --> Again OpenCV/JavaCV or google mobile vision API
I think there are also some B4A libraries for real-time effects as color-filtering, brightness, ....
 
Upvote 0

mast4rbug

Member
Licensed User
Longtime User
Thanks a lot! I will check that. And Yes, I prefer RGB than YUV. And the speed is not a real concern, if I can do 15 FPS I'm happy with that, this is for Robot Vision. I Written routines on ATMEGA in C and ASM in the past, but I think the Android plateform will be faster and more flexible.
Cedric
 
Upvote 0

mast4rbug

Member
Licensed User
Longtime User
I had time to try it and it work fine. I just wondered, why the android system can't give the preview array directly in RGB?
Cedric
 
Upvote 0

JordiCP

Expert
Licensed User
Longtime User
In fact some cameras can, but it depends on each device. Some can give RGB, JPEG, or other formats, but you there is not guarantee that all devices will support it.
It can be checked with "getSupportedPreviewFormats" method in camera object. You will need reflection or JavaObject to use this

The reason for working with NV21 for the preview is that this is the only format (and thus the default) which has to be supported by all android devices.
 
Upvote 0

mast4rbug

Member
Licensed User
Longtime User
I'm working with your NV21toRGB, it works fine, but there is something that I do not understand. In one of your example that I use, you have an array named "myPreviewRGBArray" that return from the call of "nv21toRGB.Proceed".
I see that you use INT instead of Bytes. What is the reason for that? I mean, RGB is 8 bit per color. Another thing, when I check myPreviewRGBArray.lenght, it return 1310720, this is the result for my display (1280x1024 = 1310720) But normally, it's supposed to be the size *3 for R G and B? can you explain to me what I do not understand here?
Thanks!
Cedric
 
Upvote 0

JordiCP

Expert
Licensed User
Longtime User
Well, in fact NV21toRGB should be named NV212RGBA, since it uses 4 bytes per pixel, RGBA (although alpha channel is always 255 in this case)

So, each pixel (which is 4 bytes), is stored as an int (32 bit) in memory. This is the format used for RGBA bitmaps, which is the default for B4A (android allows more formats)

To access each color plane (R,G,B) you can mask and shift each of the ints --> Bit.ShifRight(Bit.And( value, 0x00FF0000),16) and so on.

But this will surely slow your process. If you see it is too slow, tell me and I can modify the lib to give separated planes (I will have time for it in a couple of days)
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…