Recent

Author Topic: Does anyone have experience using OpenCV in Lazarus?  (Read 7417 times)

Gustavo 'Gus' Carreno

  • Hero Member
  • *****
  • Posts: 1353
  • Professional amateur ;-P
Re: Does anyone have experience using OpenCV in Lazarus?
« Reply #15 on: July 16, 2025, 03:32:19 am »
Hey Y'All,

Was not inserting foot in mouth: https://wiki.freepascal.org/fcl-image

Package fcl-image gives you TIFF... Not sure if 100% supported, cuz there's a section dedicated to https://wiki.freepascal.org/fcl-image that I did not fully read... But the table does list the units to use for https://wiki.freepascal.org/fcl-image...

So, yeah... There's that :D

Cheers,
Gus

xiyi0616

  • Jr. Member
  • **
  • Posts: 64
Re: Does anyone have experience using OpenCV in Lazarus?
« Reply #16 on: July 16, 2025, 03:38:17 am »
Hey Gus

If you have time, you could try it out. I've attached the TIFF file.

[Why aren't attachments directly supported, specifically TIFF files? ]

Cheers
xiyi0616

xiyi0616

  • Jr. Member
  • **
  • Posts: 64
Re: Does anyone have experience using OpenCV in Lazarus?
« Reply #17 on: July 16, 2025, 03:58:05 am »
Hey Gus

Okay, I see that fcl-image has TIFF handling capabilities, I'll give it a try.

Cheers,
xiyi0616

Gustavo 'Gus' Carreno

  • Hero Member
  • *****
  • Posts: 1353
  • Professional amateur ;-P
Re: Does anyone have experience using OpenCV in Lazarus?
« Reply #18 on: July 16, 2025, 04:05:42 am »
Hey xiyi0616,

Okay, I see that fcl-image has TIFF handling capabilities, I'll give it a try.

AWESOME SAUCE!!

Go for it!!

Cheers,
Gus

xiyi0616

  • Jr. Member
  • **
  • Posts: 64
Re: Does anyone have experience using OpenCV in Lazarus?
« Reply #19 on: July 16, 2025, 04:38:35 am »
Hey Y'All

I used the example from https://wiki.freepascal.org/fcl-image, but it seems to have a problem.

Code: Pascal  [Select][+][-]
  1.  
  2. uses
  3.    ...fpImage, fpReadJpeg, fpReadBMP, fpReadPNG, fpReadGIF, fpReadPCX, fpReadTIFF...
  4.  
  5. ......
  6.  
  7. function GetImageSize(const AFileName: String; out ASize: TPoint): Boolean;
  8. var
  9.   stream: TStream;
  10.   readerClass: TFPCustomImageReaderClass;
  11. begin
  12.   Result := false;
  13.   ASize := Point(-1, -1);
  14.   stream := TFileStream.Create(AFileName, fmOpenRead);
  15.   try
  16.     readerClass := TFPCustomImage.FindReaderFromStream(stream);
  17.     if readerClass <> nil then
  18.     begin
  19.       ASize := readerClass.ImageSize(stream);
  20.       Result := true;
  21.     end;
  22.   finally
  23.     stream.Free;
  24.   end;
  25. end;  
  26.  
  27. ......
  28.  
  29. procedure TForm1.BitBtn2Click(Sender: TObject);
  30. var
  31.    asv: TPoint;
  32. begin
  33.   if GetImageSize('/media/xiy0616/Data/xyLazarusPrj/Test/DisplayPicture/000001.tif', asv) then
  34.     Memo1.Lines.Add(IntToStr(asv.X) + ',' + IntToStr(asv.Y));
  35. end;
  36.  
  37. ......
  38.  
  39.  

I get -1, -1 in memo1.

It shouldn't be returning -1, should it?

Does anyone have experience using TIFFs with fcl-image?

xiyi0616

  • Jr. Member
  • **
  • Posts: 64
Re: Does anyone have experience using OpenCV in Lazarus?
« Reply #20 on: July 16, 2025, 08:57:32 am »
Okay, I'm a bit slow.

https://github.com/gidesa/ocvWrapper46

@gidesa
thanks for replay from gidesa

cheers
xiyi0616
« Last Edit: July 16, 2025, 11:42:35 am by xiyi0616 »

gidesa

  • Sr. Member
  • ****
  • Posts: 252
Re: Does anyone have experience using OpenCV in Lazarus?
« Reply #21 on: July 16, 2025, 12:03:14 pm »
Does anyone have experience using TIFFs with fcl-image?

I you want to use fcl-image, instead that Opencv (with or without the wrapper), I suggest you to open a new thread.
Regards

wp

  • Hero Member
  • *****
  • Posts: 13555
Re: Does anyone have experience using OpenCV in Lazarus?
« Reply #22 on: July 16, 2025, 02:32:57 pm »
Hey Y'All

I used the example from https://wiki.freepascal.org/fcl-image, but it seems to have a problem.

Code: Pascal  [Select][+][-]
  1.  
  2. uses
  3.    ...fpImage, fpReadJpeg, fpReadBMP, fpReadPNG, fpReadGIF, fpReadPCX, fpReadTIFF...
  4.  
  5. ......
  6.  
  7. function GetImageSize(const AFileName: String; out ASize: TPoint): Boolean;
  8. var
  9.   stream: TStream;
  10.   readerClass: TFPCustomImageReaderClass;
  11. begin
  12.   Result := false;
  13.   ASize := Point(-1, -1);
  14.   stream := TFileStream.Create(AFileName, fmOpenRead);
  15.   try
  16.     readerClass := TFPCustomImage.FindReaderFromStream(stream);
  17.     if readerClass <> nil then
  18.     begin
  19.       ASize := readerClass.ImageSize(stream);
  20.       Result := true;
  21.     end;
  22.   finally
  23.     stream.Free;
  24.   end;
  25. end;  
  26.  
  27. ......
  28.  
  29. procedure TForm1.BitBtn2Click(Sender: TObject);
  30. var
  31.    asv: TPoint;
  32. begin
  33.   if GetImageSize('/media/xiy0616/Data/xyLazarusPrj/Test/DisplayPicture/000001.tif', asv) then
  34.     Memo1.Lines.Add(IntToStr(asv.X) + ',' + IntToStr(asv.Y));
  35. end;
  36.  
  37. ......
  38.  
  39.  

I get -1, -1 in memo1.

It shouldn't be returning -1, should it?

Does anyone have experience using TIFFs with fcl-image?

The problem in this particular issue is that fcl-image does not implement the required class method InternalSize for every reader class. This was added to the bmp and gif readers of FPC 3.3.1, but for the tiff reader it is still missing (maybe because a tif image can contain several images at various sizes, and there is no way to tell which image should be analyzed).

But nothing's lost: Use subclassing to override the readers and implement the missing method. Give the new classes the same name as the originals, unregister the old readers and register the new ones. Put everything into a separate unit so that you can reuse the solution. The only thing to remember is to put this unit at the end of the uses clause (at least after the fcl readers).

I am attaching such a "fix" unit for the bmp, gif and tiff format (tiff only looking at the 1st image in the file), as well as a little demo application.

If you happen to use fpc3.3.1 I noticed that probably some bugs were introduced when the code was extended for the BigTIFF specification; it seems to me that reading of big-endian tif images ('MM' in header) is broken. But I'll have to investigate it in more detail.
« Last Edit: July 16, 2025, 02:34:56 pm by wp »

xiyi0616

  • Jr. Member
  • **
  • Posts: 64
Re: Does anyone have experience using OpenCV in Lazarus?
« Reply #23 on: July 16, 2025, 03:32:08 pm »

Hello, wp

Thank you for you time. I will use your examples to learn and understand fcl-image. Tks.

Regards

xiyi0616

xiyi0616

  • Jr. Member
  • **
  • Posts: 64
Re: Does anyone have experience using OpenCV in Lazarus?
« Reply #24 on: July 16, 2025, 03:47:39 pm »
Yes, gidesa

Absolutely new thread.

Next, I'm going to learn how to use ocvWrapper as a beginner, just like you mentioned earlier that the other library, lazarusOpenCV, stopped at version 2.4.

Thank you very much.

Regards

xiyi0616

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12898
  • FPC developer.
Re: Does anyone have experience using OpenCV in Lazarus?
« Reply #25 on: July 16, 2025, 04:07:37 pm »
Note also that not all TIFF subtypes  are supported, most notably https://gitlab.com/freepascal.org/fpc/source/-/issues/21871

Another, less relevant TIFF bugreport: https://gitlab.com/freepascal.org/fpc/source/-/issues/41032

xiyi0616

  • Jr. Member
  • **
  • Posts: 64
Re: Does anyone have experience using OpenCV in Lazarus?
« Reply #26 on: July 17, 2025, 02:31:06 am »
Hello, marcov

Thks for Note

xiyi0616

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12898
  • FPC developer.
Re: Does anyone have experience using OpenCV in Lazarus?
« Reply #27 on: July 17, 2025, 11:05:04 am »
000001.tif: TIFF image data, little-endian, direntries=16, height=2400, bps=1, compression=bi-level group 4, PhotometricIntepretation=WhiteIsZero, orientation=upper-left, width=1600

xiyi0616

  • Jr. Member
  • **
  • Posts: 64
Re: Does anyone have experience using OpenCV in Lazarus?
« Reply #28 on: July 17, 2025, 01:51:32 pm »
Yes marcov

LibTiff ?

Cheers,
xiyi0616

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12898
  • FPC developer.
Re: Does anyone have experience using OpenCV in Lazarus?
« Reply #29 on: July 17, 2025, 01:58:08 pm »
Maybe, I have no experience. I never used TIFF much after the FAX era.

I happen to know about the unsupported format because of the bugreport.

 

TinyPortal © 2005-2018