ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 LoadFromUrl
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

ChBoe

Germany
3 Posts

Posted - Oct 13 2022 :  05:12:26  Show Profile  Reply
Hello to all,

I've written a class in a rest service with Delphi XE11 which grabs pictures from IP-Kameras every time we scale a truck.
I call the camera via URL and get back the image.
Problem is, it works fine a few times then it stops working. Stop's working means the LoadFromURL method gives me back a "false". I don't know what's the reason for this problem.


The TImageEnView Object will be created the first time when the method to grab the picture is called and lives as long as the service is running. I don't know if there somethings should be freed between the calls or why it works only for a few times.
Maybe someone have a idea what goes wrong here.

Any help would be helpful.

Best Regards,

Chris


Following the actual code with TImageEnView:


var
 FImageView : TImageEnView;

begin
    if not assigned(FImageView) then
        FImageView := TImageEnView.create(NIL);
    with Kamera.CameraList do
      begin
        for i := 0 to count-1 do
        begin
          sURL := copy(Kamera.CameraList[i],Pos('=',Kamera.CameraList[i]) + 1,length(Kamera.CameraList[i])- 
          Pos('=',Kamera.CameraList[i])+1);          
          bOK:= FImageView.IO.LoadFromURL(sURL);
          if (bOK = true) then
          begin
            Log('dograb','Image of camera ' + inttostr(i+1) + ' - Download successful.');
            sFilename:= CreateFileName(sWeighingNo,iPosnr,Kamera,i+1);         
            FImageView.IO.SaveToFileJpeg(sPath + sFilename);          
            // Replace Src of the images inside the template.
            lstTemplate.text:= ReplaceStr(lstTemplate.Text,sBild,sFilename);
          end
          else
          begin
            Log('dograb','No image from camera ' + inttostr(i+1) + ' (IP: ' + sIP + ''').');
          end;
        end;
      end;
      // replace text in template
      lstTemplate.text:= ReplaceStr(lstTemplate.Text,'Scale/WS',sScaleNr + '/' + sWeighingNo + '/' + inttostr(iPosnr));
      lstTemplate.SaveToFile(sPath + 'viewpicture.html');
      Log('dograb','Viewpicture.html erzeugt.');
    end;
    ... freeing camera and list objects ...
end;


xequte

38690 Posts

Posted - Oct 13 2022 :  16:14:53  Show Profile  Reply
Hi

LoadFromURL uses the method IEGetFromURL which itself uses Windows methods retrieve the file.

You might want to localize IEGetFromURL (take it from iexBitmaps.pas) to add debugging to see why the connection or download fails. Perhaps the server is rejecting the frequent connections, for example.

https://www.imageen.com/help/IEGetFromURL.html

Nigel
Xequte Software
www.imageen.com
Go to Top of Page

ChBoe

Germany
3 Posts

Posted - Oct 17 2022 :  13:46:01  Show Profile  Reply
Hi Nigel,

I've done so far. I get a image and a "ERROR connecting to: ..." at the same time. How to debug this method? The method gives me back a boolean like the normal LoadFromURL.
My call to the camera gives me a snapshot in .jpg format. I dont know if this works when the method works with a stream.

Best Regards,

Chris



Chris
Go to Top of Page

xequte

38690 Posts

Posted - Oct 17 2022 :  20:36:40  Show Profile  Reply
Hi Chris

What line is it failing on in IEGetFromURL()?

Nigel
Xequte Software
www.imageen.com
Go to Top of Page

ChBoe

Germany
3 Posts

Posted - Nov 03 2022 :  02:31:51  Show Profile  Reply
Hi Nigel,

as we do not have the sourcecode I'm not able to see what goes on inside the component. For testing purposes I've changed to use idHTTP from Indy and a TJpegImage to do the job. At the first request I get allways a #53 error. When I repeat the request I get the image, don't know why.
No idea what's the reason for this behaviour but it works. I catch the error and do a recursive call to the same method.
I've written a program using the TImagenIO component in XE and use the LoadFromURL method which runs since years without any problems at 5 truck-scales.
Do you know what the #53 error means?

My actual workaround:


procedure TGrabPicture.GetImage(sURL: string; var idHTTP: TidHTTP; var JPG:
    TJpegImage);
var
  MS: TMemoryStream;
begin
  MS := TMemoryStream.Create();
  try
    try
      IdHTTP.Get(sURL, MS);
      sleep(200);
      MS.Seek(0,soFromBeginning);
      JPG.LoadFromStream(MS);
    except
      on E: EInvalidGraphic do
      begin
        FreeAndNil(MS);
        getImage(sURL, idHTTP,jpg);
      end;
    end;
  finally
    FreeAndNil(MS);
  end;
end;


Chris
Go to Top of Page

xequte

38690 Posts

Posted - Nov 03 2022 :  23:18:39  Show Profile  Reply
Hi Chris

I don't know Indy. You might need to ask on an Indy forum.



Nigel
Xequte Software
www.imageen.com
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: