Jump to content
Sign in to follow this  
Mike James

Problems with FMX.CameraComponent Sample

Recommended Posts

Hi,

 

I'm trying out the FMX.CameraComponent Sample with Delphi 10.4 Sydney. The project is the latest download from github.

When running the camera every so often the screen will flash green i.e. blank.

Has anybody else seen this? Is it a problem with the threading that the example is using?

 

Regards, Mike.

Share this post


Link to post
5 hours ago, Rollo62 said:

No problem seen yet, what Platform are you talking about ?

I'ts running on a Samsung a71 (Android 10).

 

Regards, Mike.

Share this post


Link to post

Hi Mike, i have the same problem, but my screen turn black and the app crash, did you solve the problem? thanks

Share this post


Link to post

Since there were several questions that this sample doesn't work, I checked myself again.

Indeed, it seems to be broken, out-of-the-box.

 

I did the following to get it running:

- re-create the project under Rx10.4

- add the Main unit to the project

- check the Project/Forms tab, the main form should be auto-created

- Removing all unnecessary permissions and entitlements, keeping just Camera permission

- For some reason in uMain.pas, this line needed to be added.

  I have not cxhecked the orginal file again, but maybe there was some non-standard form creation.

//21.08.20 added
var
    CameraComponentForm : TCameraComponentForm;

- For testing before, I moved the first creation, until the Camera shall be really started.
  This shouldn't be necessary, but I did that for testing to decouple the actions a little, und keep it in my final.

   That means you have to press START twice,  1. Get Resolutions,  2. Start camera

procedure TCameraComponentForm.FormCreate(Sender: TObject);
begin
//21.08.20  PermissionsService.RequestPermissions([PermissionCamera], AccessCameraPermissionRequestResult, DisplayRationale);


...

procedure TCameraComponentForm.btnStartCameraClick(Sender: TObject);
begin
  //21.08.20 Try  get resolutions here at first
  if cbResolutions.Items.Count = 0 then
      PermissionsService.RequestPermissions([PermissionCamera], AccessCameraPermissionRequestResult,   DisplayRationale)
  else //only then start the camera with 2nd click
      PermissionsService.RequestPermissions([PermissionCamera], ActivateCameraPermissionRequestResult, DisplayRationale);
end;

Et voilâ, camera is working for me.

 

 

I made some comments already, that I think the non-working samples and demos are a MAJOR SHOWSTOPPER,

especially for new customers.

If Embarcadero is making a trial, and CE version, they should better take most care that all samples will run out-of-the-box.

 

If new customers trying new tools are a little bit like me,

I will DROP the new tools immediately if I cannot get the basic demos and hello worlds running without major quirks.

Thats my proof or quality for any software or tool.

 

So its Embarcadero's marketing decision, not mine.

 

 

 

 

 

 

 

 

Edited by Rollo62
  • Like 5

Share this post


Link to post

I've been checking on the net and it seems to be a problem with TCameraComponent and Threading.

I'll guess I'll have to wait for Delphi 10.4.1 or 10.5 :-)

 

Regards, Mike.

Share this post


Link to post

You can try what I explained before.

Has same issues as you described, re-creating solved those issues.

That means very likely the project and its libraries where not updated to 10.4, you can also try project manager "revert to default",

but I always rebuild a new project, which is most reliable.

Has not much to do IMFO with threads.

Share this post


Link to post
On 8/24/2020 at 9:09 AM, Rollo62 said:

You can try what I explained before.

Has same issues as you described, re-creating solved those issues.

That means very likely the project and its libraries where not updated to 10.4, you can also try project manager "revert to default",

but I always rebuild a new project, which is most reliable.

Has not much to do IMFO with threads.

It's good to see someone else having the same problem...

 

https://quality.embarcadero.com/browse/RSP-31238

 

Share this post


Link to post
Guest

hey guys,

if I can talk about access CAM properties: it's always necessary verify the "permissions" same in just "read" a property!

I have a sample in using my Android Moto G4 Android 7.0 Nougat as my "Live-CAM" capturing all video in a "Bitmap" as buffer on event using Thread Current (main) and the app running ok!

 

implementation

{$R *.fmx}

{
  This sample, will use the "TVideoCaptureDevice" (class base to "TCameraComponent") directly!!!
  This class is defined in "FMX.Media.pas"
  //
  TDialogService.ShowMessage() used for dont block main-thread!
}
//
uses
  FMX.DialogService
  {$IF DEFINED(ANDROID)}
    ,
  FMX.Helpers.Android,
  Androidapi.JNI.JavaTypes,
  Androidapi.Helpers,
  Androidapi.JNI.OS
  {$ENDIF}
    ;

//
var
  lMyCAMDevice    : TVideoCaptureDevice;
  lMyCAMPermission: string;
procedure TfrmFormMain.prcCAMDevicesSetting;
{$IF NOT DEFINED(ANDROID)}
var
  DeviceList: TCaptureDeviceList;
  i         : integer;
  {$ENDIF}
begin
  {$IF DEFINED(ANDROID)}
  cmbboxCAMDevices.Visible := False;
  try
    // Normally, there is only 1 cam in Mobile!
    //
    // NOTE: any try to read or change any property from CAM, NEEDS "permissions"!!!
    lMyCAMDevice := TCaptureDeviceManager.Current.DefaultVideoCaptureDevice;
    //
    lMyCAMDevice.OnSampleBufferReady := prcCAMSampleBufferReady; // showing our video on TImage
    //
    // DONT TRY READ or CHANGE any property from CAMDevice here!!!
    // Like: Start or Stop, Quality, IsDefault, etc...
    // Only later your "permissions" to be given by user!!!
  except
    on E: Exception do
      prcMyLog('Error CAM definition' + #13#10 + E.Message);
  end;
  {$ELSE}
  DeviceList := TCaptureDeviceManager.Current.GetDevicesByMediaType(TMediaType.Video);
  //
  for i := 0 to (DeviceList.Count - 1) do
    cmbboxCAMDevices.Items.Add(DeviceList[i].Name);
  {$ENDIF}
end;

 

procedure TfrmFormMain.prcCAMStartCapture;
begin
  if not(lMyCAMDevice = nil) then
  begin
    // to Mobile (Android), change properties from CAMERA, needs permission!
    {$IF DEFINED(ANDROID)}
    if PermissionsService.IsPermissionGranted(lMyCAMPermission) then   //  <----- reading or changing the properties by CAM
    {$ENDIF}
    begin
      try
        lMyCAMDevice.StopCapture; // to avoid any error below
        //
        lMyCAMDevice.Quality := TVideoCaptureQuality.PhotoQuality;
        //
        lMyCAMDevice.StartCapture; // starting video capture!
        //
        prcMyLog('CAM device = Capture stated!');
        prcMyLog('CAM ' + fncMyIIF(lMyCAMDevice.IsDefault, 'is', 'is not') + ' Default');
        prcMyLog('CAM ' + fncMyIIF(lMyCAMDevice.HasFlash, 'has', 'has not') + ' Flash');

      except
        on E: Exception do
          prcMyLog('Error Start CAM' + #13#10 + E.Message);
      end;
    end
    {$IF DEFINED(ANDROID)}
    else
      TDialogService.ShowMessage('Then CAM device needs your permission to access it!');
    {$ENDIF}
  end
  else
    TDialogService.ShowMessage('None CAM device defined!');
end;

 

...

procedure TfrmFormMain.sbtnCAMStartCameraClick(Sender: TObject);
begin
  {$IF DEFINED(ANDROID)}
  PermissionsService.RequestPermissions( { }
  [lMyCAMPermission],                    { }
  prcPermissionsResulted,                { }
  prcDisplayRationale                    { = nil, if you DONT WANT show any message! }
  );
  {$ELSE}
  prcCAMStartCapture; // MSWindows or macOS
  {$ENDIF}
end;

initialization

lMyCAMDevice := nil;
{$IF DEFINED(ANDROID)}
lMyCAMPermission := JStringToString(TJManifest_permission.JavaClass.CAMERA);
{$ENDIF}

finalization

end.

hug

Edited by Guest

Share this post


Link to post

It's possible that sometimes CameraComponent's SampleBufferReady event is fired up while previous call to DisplayCameraPreviewFrame has not completed/returned (e.g. GUI updating is slower than camera's frame rate), thus imgCameraView.Bitmap is changed in the middle of its display. It's quite simple to test this hypothesis on your device with few extra lines of code. I did test on my Note 20 phone but it is way to fast ... 🙂

Share this post


Link to post
Guest

look my sample about this, where I use my phone as my CAM online capture with TImage as target

 

 

Share this post


Link to post

I've worked with the TCameraComponent a lot and not seen the green flashes. I'm curious what phones it is failing on.

On 8/21/2020 at 4:39 AM, Rollo62 said:

I think the non-working samples and demos are a MAJOR SHOWSTOPPER,

especially for new customers.

 Please do report other non-working samples and demos on Quality Portal. I agree they should all work.

Share this post


Link to post

@Jim McKeeth

Sorry Jim, I do not have much time right now.

 

What I can say in general, I think the problem with the demos is that they were not set up in a proper folder representation.

Like

/Packages/Rx1033

/Packages/Rx1041

/Packages/Rx1032

/Src

 

So that all different versions are nicely separated, and no IDE .dproj conversion is needed when opening with the wrong version.

I think that is usually most of the time the provblem, that opening an older .dproj file with the newer IDE,

but the IDE is not 100% able to convert and all parameters correctly (its simply too complex).

 

A better library-structure would help to keep the samples up-to-date, and also to see whats already upgraded, and whats not.

I came back to this topic triggered from the nice article here.

Maybe the demos has to be seen as part of the library too ( so do I ) ?

 

 

 

 

Edited by Rollo62

Share this post


Link to post

I can confirm that the update fixes the Green-flashing on my FMX.CameraComponent app.

 

Thanks to one and all...

 

-<mike>-

  • Like 1

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×