B4A Library Advanced Camera Library V1.00

UPDATE! - Zoom, Current & Supported - Advanced Camera Library V2.00

Hello everyone!

B4X:
Sub Globals
Dim camera1 As AdvancedCamera ' New lib
End Sub


I'm glad to announce my fourth library! :D
This library is a modification of the existing camera library with more options.
So the standard procedures of the camera still apply.
Basic4android - Camera

You can find the Advanced Camera Library in the attachements.
To use: Extract and Copy the Advanced Camera.xml and Advanced Camera.jar to the library folder in "Anywhere Software\Basic4android\Libraries".

.:!BIG UPDATE!:.
Advanced Camera Library has been updated to version 2.0 with tons of new features!
See post #19
http://www.b4x.com/forum/52479-post19.html


.:Index:.


[1] Flashlight
[2] Camera's
[3] Orientation
[4] Pictures
[5] Antibanding
[6] Colour Effects
[7] Focus Mode
[8] Scene Mode
[9] White Balance


So, let's start

1) Flashlight

a.
"FlashAuto": Enables the flashlight to turn on automatically.
B4X:
Camera1.FlashAuto()

b.
"FlashOn": Turns the flashlight on.
B4X:
Camera1.FlashOn()

c.
"FlashOff": Turns the flashlight off.
B4X:
Camera1.FlashOff()

2) Camera's

a.
"CameraBack": Sets the back camera as primary camera.
B4X:
Camera1.CameraBack()

b.
"CameraFront": Sets the front camera as primary camera.
B4X:
Camera1.CameraPortrait()

3) Orientation

a.
"OriLandscape": Sets the orientation to landscape mode.
B4X:
Camera1.OriLandscape()

b.
"OriPortrait": Sets the orientation to portrait mode.
B4X:
Camera1.OriPortrait()

4) Pictures

a.
"PictureSize": Sets the size of the picture in pixels.
The parameters must be modified before Camera1.StartPreview.
B4X:
Camera1.PictureSize(480,320)

b.
"Quality": Sets the quality of the JPEG picture. Range between 0 - 100, with 100 being the best.
The parameters must be modified before Camera1.StartPreview.
B4X:
Camera1.Quality = 100

5) Antibanding

"setAntibanding": Sets the Antibanding. This is used to remove noises like when you take a picture of a monitor/television screen.
  • ANTIBANDING_50HZ: Sets the antibanding to 50Hz.
  • ANTIBANDING_60HZ: Sets the antibanding to 60Hz.
  • ANTIBANDING_AUTO: Sets the antibanding to automatic mode.
  • ANTIBANDING_OFF: Sets the antibanding off.
B4X:
Camera1.setAntibanding = "ANTIBANDING_AUTO"

6) Colour Effects

a.
"setEffect": Sets the color effect of your picture.
  • AQUA
  • BLACKBOARD
  • MONO
  • NEGATIVE
  • NONE
  • POSTERIZE
  • SEPIA
  • SOLARIZE
  • WHITEBOARD
B4X:
Camera1.setEffect = "SEPIA"

7) Focus Mode

"setFocusMode": Sets the focus mode of your picture.
  • MACRO: Close-up.
  • INFINITY: Far distance.
  • FIXED: If the camera has auto-focus, this mode can fix the focus.
  • AUTO: Auto-focus mode.
  • EDOF: Focusing is done digitally and continuously.
B4X:
Camera1.setFocusMode = "MACRO"

8) Scene Mode

"setSceneMode": Sets the scene mode of your picture.
  • ACTION: Take photos of fast moving objects.
  • AUTO: Scene mode is off.
  • BEACH: Take pictures on the beach.
  • CANDLELIGHT: Capture scenes lit by candles.
  • FIREWORKS: Take pictures of fireworks.
  • LANDSCAPE: Take pictures on distant objects.
  • NIGHT: Take photos at night.
  • PARTY: Indoor low-light shot.
  • PORTRAIT: Take people pictures.
  • SNOW: in the snow.
  • STEADYPHOTO: Avoid blurry pictures (handshake).
  • SUNSET: Take Sunset photos.
  • THEATRE: Take photos in a theater.
B4X:
Camera1.setScene = "BEACH"

9) White Balance

"setWhiteBalance": Sets the white balance of your picture.
  • AUTO
  • CLOUDY_DAYLIGHT
  • DAYLIGHT
  • FLUORESCENT
  • INCANDESCENT
  • SHADE
  • TWILIGHT
  • WARM_FLUORESCENT
B4X:
Camera1.setWhiteBalance = "WARM_FLUORESCENT"


If there are any bugs, questions or features you want to add to the library, please post them on this forum.

Credits and feedback are really much appreciated!

Thank you very much!

XverhelstX

Full example:

B4X:
'Activity module
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.
   
End Sub

Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.
   
   Dim camera1 As AdvancedCamera
   Dim Panel1 As Panel
   
End Sub

Sub Activity_Create(FirstTime As Boolean)
    
   Activity.LoadLayout("Menu")
   activity.AddMenuItem("Take Picture","mnuTakePicture")
   activity.AddMenuItem("Set Effect","mnuSetEffect")
   activity.AddMenuItem("Flash On","mnuFlashOn")
   activity.AddMenuItem("Focus Mode","mnuFocusMode")
   
End Sub

Sub Activity_Resume
   
   camera1.Initialize(panel1, "Camera1")
   
End Sub

Sub Activity_Pause (UserClosed As Boolean)
   camera1.StopPreview
   camera1.Release
End Sub

Sub mnuFlashOn_Click

camera1.FlashOn()
End Sub

Sub mnuSetEffect_Click

Camera1.setEffect = "SEPIA"

End Sub

Sub Camera1_Ready (Success As Boolean)
   If success Then
      Camera1.StartPreview
      
   Else
      ToastMessageShow("Cannot open camera.", True)
   End If
End Sub

Sub Camera1_PictureTaken (Data() As Byte)
   camera1.StartPreview
   Dim out As OutputStream
   out = File.OpenOutput(File.DirRootExternal, "Image.jpg", False)
   out.WriteBytes(data, 0, data.Length)
   out.Close
   ToastMessageShow("Image saved: " & File.Combine(File.DirRootExternal, "Image.jpg"), True)

   
End Sub

Sub mnuTakePicture_Click
   
   camera1.TakePicture
   
End Sub

Sub mnuFocusMode_Click
   
   camera1.setFocusMode = "MACRO"
   
End Sub
 

Attachments

  • ACL4.4.zip
    364.7 KB · Views: 1,947
  • ACL4.5.zip
    33.5 KB · Views: 1,392
  • ACL4.6.zip
    359.4 KB · Views: 4,877
Last edited:

alfcen

Well-Known Member
Licensed User
Longtime User
Hi XverhelstX,

Today, I tried your library for the first time - fine job - no problems whatsoever encountered. Portrait and landscape modes are working flawlessly.

Sample screen: http://www.requio.com/b4aforum/gauges.png

Now a nasty question, if part of the Android system, is there any way to read the camera's focal length, chip X/Y dimensions or field of view? Such data will help measure size of and distances to bodies with the camera.

Cheers
Robert
 

Silentsea

Member
Licensed User
Longtime User
Hi XverhelstX,

I really need some help to get the flash working. Some ideas on my question? I tried some other market apps, for example with torch options, these worked as aspected.

Silentsea
 

XverhelstX

Well-Known Member
Licensed User
Longtime User
Hey everyone,

First of all, I'm sorry I didn't reply. I was on vacation and didn't check B4A a lot.
So it's time for a new update!

The following things are added to version 3.4!

Silentsea: - Added FlashTorch, FlashOn. (See which one works for your device. it should be FlashOn)

alfcen: - Added FocalLength, HorizontalViewAngle, VerticalViewAngle

Neotechni: - Now you can show an inputlist with all supported modes that the device can handle:
The problem was related that I had to use .Equal instead of "==" in Java

B4X:
Sub mnuList_Click
'Declare the variables.
Dim strColourEffect As String
Dim strSelectedItem As String
Dim arrayColourEffects() As String
Dim List1 As List

strColourEffect = camera1.SupportedColourEffect 'Gets all the supported effects from the device
strColourEffect = strColourEffect.SubString2(1,strColourEffect.Length-1) ' Removes the '[' and ']' at the beginning and the end of the string
arrayColourEffects = Regex.Split(", ",strColourEffect) ' Splits all the items with ', ' (space included) and puts it in an arrayDim List1 As List
      List1.Initialize
      For i = 0 To arrayColourEffects.Length-1 ' adds the items to the list. (.Length shows how many items there are)
       List1.Add(arrayColourEffects(i)) 'Add the items
      Next
      
      Dim reslist As Int
      reslist = InputList(List1, "Select Colour Effect.", -1) 'show list with the items.
      For i = 0 To arrayColourEffects.Length-1 ' works with the items
          If reslist = i Then
         strSelectedItem = list1.Get(i)
         If strSelectedItem.ToUpperCase = "SEPIA" Then
         Msgbox(strSelectedItem,strSelectedItem.Length) 'Displays the item. 
         End If
         camera1.ColourEffect = strSelectedItem.ToUpperCase 'Sets the value. Uppercase it to work with the Advanced Camera Library.
         End If
      Next
End Sub

Other things:

- ExposureCompensation
- ISO Value
- SupportedPreviewFpsRange
- PreviewFpsRange (int min, int max)
- AppTrial (has nothing to do with the Camera, but I didn't want to make a new lib for it :p used for my upcoming tutorial)
- PictureOnCurrentFrame(int Width, int Height, int Quality) (worked long on this)

Now you are able to take a picture on the current frame without Camera_TakePicture

Call PictureOnCurrentFrame and Eventname__PreviewTaken() will be called.

Sub Camera1_PreviewTaken (PictureFrame() As Byte)

- decodeYUV420SP(int[] rgb, byte[] yuv420sp, int width, int height)
converts raw data to jpg
- and a lot more! (i think :s)


Two things that are added but doesn't work yet :p
- detectFaces
- Video Recorder

If you have more questions, feel free to ask or you want some more things added.

XverhelstX
 
Last edited:

Silentsea

Member
Licensed User
Longtime User
Hi XverhelstX,

hope you had a nice vacation. Thanks For updating AND sharing. Flash mode now works for me :). You really helped me out! :sign0060:

But now there is a little other problem. My old code didn't work any longer, I think others also. Have you changed something on the StartPreview method? After taking a picture another start preview will not invalidate the panel until I reinitialize the whole cam object. Your example code on the first page will not work as aspected also (same problem as mentioned).

Please have a look and thanks in advance!

Silentsea
 

alfcen

Well-Known Member
Licensed User
Longtime User
ACL.FocalLength, ACL.ViewAngles

Hi XverhelstX

You must have had a great summer vacation.
Works like a charm. Had only low hopes for such data being avaible in the system.
Thanks so much for making it so easy to read these parameters.

Cheers
Robert
 

alfcen

Well-Known Member
Licensed User
Longtime User
Hi again

Just came across a minor issue. Don't know whether the bug is in the lib or in my head, the latter strongly assumed.

In ToggleCamera_Click the preview can be stopped but the attempt to restart the preview throws a Nullpointer Exception.

It works with the official Camera library.

B4X:
Sub Globals
   Dim Camera1 As AdvancedCamera
   Dim Panel1 As Panel
        Dim preview as Boolean
End Sub

Sub Camera1_Ready (Success As Boolean)
   If success Then
      Camera1.StartPreview
   Else
      ToastMessageShow("Camera not currently available.", True)
   End If
End Sub

Sub Activity_Resume
   Camera1.Initialize(Panel1, "Camera1")
End Sub

Sub Activity_Pause (UserClosed As Boolean)
   Camera1.StopPreview
   Camera1.Release
End Sub

Sub ToggleCamera_Click
   preview = Not(preview)
   If preview = True Then
      Camera1.StartPreview
   Else
      Camera1.StopPreview
   End If
End Sub
 

XverhelstX

Well-Known Member
Licensed User
Longtime User
I will fix it in the next version.

I finally succeeded in the face detection!! :D
I used a picture with 43 faces and it detected all 43 faces :D! woot !
So happy now xD
It also get the confidence, eye distance, and the mid point.
See attachements.

XverhelstX
 

Attachments

  • faces_2004W_comp1.jpg
    faces_2004W_comp1.jpg
    84.1 KB · Views: 241
  • sprite0_facedetect1313247027345.jpg
    sprite0_facedetect1313247027345.jpg
    27.8 KB · Views: 235

XverhelstX

Well-Known Member
Licensed User
Longtime User
Okee
I will try to release it later this day.
Anything particular you want to add with it?
Note that it is not possible to get the faces from your camera.
You have to select a face from your directory.

XverhelstX
 
Last edited:

XverhelstX

Well-Known Member
Licensed User
Longtime User
Advanced Camera Library 4.0 is now available.

- Alfcen:

*
Just came across a minor issue. Don't know whether the bug is in the lib or in my head, the latter strongly assumed.

In ToggleCamera_Click the preview can be stopped but the attempt to restart the preview throws a Nullpointer Exception.

It works with the official Camera library.

This should be fixed, could you test it.

*
A small issue has been fixed with landscape and portrait.
Devices with android 2.1 crashes when using OriPortrait. (my xperia x10 crashed)
This can be fixed by using the phone library and get the sdk version.
if the SDK version is 7 (android 2.1) or 8 (2.2, don't know if it crashes here, haven't tested), you can now use OriPortraitAPI7.

*
Face Detection has now been added.
All instructions are in the app.
Use Camera1.detectFaces to get the faces.
Use Camera.Face... to work with them.

Example:

B4X:
Camera1.detectFaces("facedetected1.jpg",btmp,btmp.Width,btmp.Height,4)
Msgbox(Camera1.FaceFound,"found faces")
Msgbox(Camera1.FaceConfidence,"Confidence")
Msgbox(Camera1.FaceEyesDistance,"Eyes distance")
Msgbox(Camera1.FaceMidPointX,"MidPointX")
Msgbox(Camera1.FaceMidPointY,"MidPointY")
Msgbox(Camera1.pose(Camera1.EULER_X),"Euler_X")


Cheerz,
XverhelstX
 
Last edited:

myriaddev

Active Member
Licensed User
Longtime User
no Zoom in V4.0

Great Lib! I have much of acl 4.0 working such as SupportedFocusMode, isZoomSupported... The pics are great. I can not get any other Zoom functions to compile. They may not be in xml file.
Keep up the great work!,
Jerry
 
Last edited:

alfcen

Well-Known Member
Licensed User
Longtime User
Hi XverhelstX

Good knowing that the bug wasn't in my brain :sign0089:

Hey, congratulations on your latest achievements. 100% face recognition is probably rare.

Can't wait for the eye distance feature :sign0060:

Thanks to Focal length and View angles many interesting features are now within range.

Cheers
Robert
 

alfcen

Well-Known Member
Licensed User
Longtime User
Hi again

Just downloaded Ver 4.0,
The preview issue is resolved, but I fail to find Focallength and Viewangles :BangHead:
 
Top