Live camera image

barx

Well-Known Member
Licensed User
Longtime User
Good morning (or afternoon / evening)

Is it possible to show a live camera image on the screen? Basically wanting to point camera and show image with 'something' overlaid on top with a panel.

Thanks
 

Roeschti

Member
Licensed User
Longtime User
Of course, why not?

Example: Panel for cam preview, a transparent label on it for showing additional informations or what ever you want.

Dim cam As Camera
Dim pnlCam As Panel




Sub cam_Ready(Success As Boolean)
If Success Then
cam.StartPreview
lblAddInfos.Text = " Howdie partner "
Else
ToastMessageShow("Cannot open camera.", True)
End If
End Sub


Sub Activity_Resume
cam.Initialize(pnlCam, "cam")
End Sub

Sub Activity_Pause (UserClosed As Boolean)
cam.Release
End Sub
 
Upvote 0

barx

Well-Known Member
Licensed User
Longtime User
Just didn't know if it was possible or not. Never played with camera stuff. Will have a play with your code a little later tonight. Thank you very much.
 
Upvote 0

barx

Well-Known Member
Licensed User
Longtime User
ok, I've actually just this and it worked..... to an extent. The image is sideways. Looks mind boggling especially when you move the phone about.

Move it physically up and down and the image moves left and right:sign0094:
 
Upvote 0

barx

Well-Known Member
Licensed User
Longtime User
The working sample. Run on a Desire Z. Just off to read what I can about the camera lib, see if it sheds on light...

B4X:
'Activity module
Sub Process_Globals
   
End Sub

Sub Globals
   Dim Cam As Camera
   Dim pnlCam As Panel

End Sub

Sub Activity_Create(FirstTime As Boolean)
   pnlCam.Initialize("pnlCam")
   Activity.AddView(pnlCam, 10dip, 10dip, Activity.Width - 20dip, Activity.Height - 20dip)
   Cam.Initialize(pnlCam, "Cam")
      
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)
   Cam.Release
End Sub

Sub Cam_Ready (Success As Boolean)
   If Success Then
      Cam.StartPreview
   Else
      ToastMessageShow("Cannot open camera", True)
   End If
End Sub
 
Upvote 0

barx

Well-Known Member
Licensed User
Longtime User
Ha, well bless me. Sorry for being a lazy noob. First paragraph of camera library explanation explained 'Landscape only'

:sign0104::sign0013:
 
Upvote 0

barx

Well-Known Member
Licensed User
Longtime User
True, very true.

Next query, I've now stumbled upon the Advanced Camera Library :sign0008: and nearly wet my pants.

My current issue, I need to display the image in the correct aspect ratio. If I set the holding panel to 100%x, 100%y to full screen the camera image is stretched. Ok, I thought, lets increase the panel height off screen (doesn't matter about a bit of cropping) to get it right.....

So, I declare a variable to hold the image ratio from the camer and set it with

B4X:
Ratio = Cam.CurrentPictureSizeWidth / Cam.CurrentPictureSizeHeight

Then, adjust the height of panel to 100%x / Ratio.

It's still a streched a bit. Tried with full screen and hide title options.

Any ideas how to get image to show none stretched 100% width?

Thanks.

Current code

B4X:
'Activity module
Sub Process_Globals
   
End Sub

Sub Globals
   Dim Cam As AdvancedCamera
   Dim isLandscape As Boolean
   Dim Ratio As Float
   Dim pnlCam As Panel
   Dim pnlLadder As Panel
   Dim pnlDropLine As Panel
   
   Dim imgLadder As ImageView
   Dim imgDropLine As ImageView
   
   'Dim seekMover As SeekBar
   
End Sub

Sub Activity_Create(FirstTime As Boolean)
   
   If Activity.Width > Activity.Height Then
      isLandscape = True
   Else
      isLandscape = False
   End If
   pnlCam.Initialize("pnlCam")
   'seekMover.Initialize("seekMover")
   Activity.AddView(pnlCam, 0, 0, 100%x, 100%y)
   
   'Activity.AddView(seekMover, 10dip, Activity.Height - 50dip, Activity.Width - 20dip, 40dip)
      
End Sub

Sub Activity_Resume
   Cam.Initialize(pnlCam, "Cam")
End Sub

Sub Activity_Pause (UserClosed As Boolean)
   Cam.Release
End Sub

Sub Cam_Ready (Success As Boolean)
   If Success Then
      
      Cam.StartPreview
      Ratio = Cam.CurrentPictureSizeWidth / Cam.CurrentPictureSizeHeight
      pnlCam.Height = pnlCam.Width / Ratio
      Log("Aspect Ratio set to - " & Ratio)
   Else
      ToastMessageShow("Cannot open camera", True)
   End If
End Sub
 
Upvote 0

Roeschti

Member
Licensed User
Longtime User
Well, the best way would be to get the aspect ratio from native camera resolution. This information is often hard to find. The second way wich works for me is get the correct aspect ratio from a truely supported format like 720p.

So 1280×720 is the resolution, the aspect ratio would be 1280:720 = 1.7777 what's the same as 16:9

Maybe this helps you too
 
Upvote 0
Top