Lazarus

Programming => Packages and Libraries => Topic started by: Jurassic Pork on March 07, 2016, 11:40:04 am

Title: OpenCV with Lazarus
Post by: Jurassic Pork on March 07, 2016, 11:40:04 am
hello,
here is a starting point to use opencv with Lazarus.
Not sure that works with all the functions of Opencv, but works with the lkdemo  ( video motion tracking)
OpenCV.pas needs to be checked because it is a version for 2.1 version of Opencv and i use it with version 3.0 of Opencv ( I have done some changes for that works).
OpenCV.pas needs some changes to work with Linux.
Lkdemo Lazarus project :
In attachment lkdemo project for Lazarus
 Download opencv 3.0 for windows from here (http://sourceforge.net/projects/opencvlibrary/files/opencv-win/3.0.0/opencv-3.0.0.exe/download)
Extract the  dlls  \opencv-3.0.0.exe\opencv\build\x86\vc12\bin\*.dll (choose the right folder for your O.S ex : x86 -> 32 bits , vc12 -> visual c++ dlls  version 12)  from opencv-3.0.0.exe with 7z  in your project folder.
 you must change this line in unit1.pas -> choose a video file or capture from CAM
 
Code: Pascal  [Select][+][-]
  1.  //      capture := cvCaptureFromCAM(0);
  2.         capture := cvCaptureFromFile(PChar('f:\temp\videos\test.mp4'));

tested with Lazarus 1.6 Windows 32 bits and Opencv 3.0.

Thanks to Giandomenico (http://gidesa.altervista.org/camshiftdemo.php)   
Enjoy !
Title: Re: OpenCV with Lazarus
Post by: zbyna on April 18, 2016, 09:12:33 pm
My small contribution:
https://github.com/zbyna/opencv-lazarus
 :)
Title: Re: OpenCV with Lazarus
Post by: six1 on January 09, 2018, 02:19:42 pm
My small contribution (Face detect, working Sample!):
http://www.mediafire.com/file/3t2a024nacfwx0k/Laz_OpenCV_Face_Detect.zip

You have to download OpenCV 2.4.13.5 https://opencv.org/releases.html
Extract following Libs from opencv\build\x86\vc14\bin\ into Programs dir:

opencv_calib3d2413.dll
opencv_contrib2413.dll
opencv_core2413.dll
opencv_features2d2413.dll
opencv_highgui2413.dll
opencv_imgproc2413.dll
opencv_legacy2413.dll
opencv_nonfree2413.dll
opencv_objdetect2413.dll
opencv_photo2413.dll
opencv_video2413.dll

Have fun, Michael
Title: Re: OpenCV with Lazarus
Post by: Mike.Cornflake on January 19, 2018, 04:10:58 am
Ooh.  OpenCV has been on my TODO list for a while.  Many thanks for posting this...
Title: Re: OpenCV with Lazarus
Post by: six1 on January 22, 2018, 02:05:23 pm
Hi Mike,
it seems to be a long way...  ::)

Meanwhile i've modified Delphi components to work with Lazarus.

After many fixes and few improvements, most of it is working, but there are a few problems left to do...
(ocvView is now working after many hours of debuging, but videosource must be set at runtime! see LazSample in Samle folder on github)

look at github, for latest changes of my OpenCV Fork

https://github.com/six1/Laz_OpenCV_2


best, Michael
Title: Re: OpenCV with Lazarus
Post by: Lotiara on February 08, 2018, 06:53:25 am
Thank you six1

Just installed your fork.
Impossible to make it work so I've installed Lazarus x86.
Now it's moment to start playing with the lib, I want to detect a car position in a
parking, I need to know the exact location (don't know if it's possible as I need to convert
the pitcure/video position to a real position), any clue on how to do this would be appreciated.
Good Job
Bye
Title: Re: OpenCV with Lazarus
Post by: six1 on February 08, 2018, 01:34:00 pm
Hi Lotiara,
with my experiences on OpenCV, that would be not that easy...
First you have to make a Haar Detection File. Therfore you need Pictures from Cars in the View you want to recognize later on..

I would give it a try with Motion Detection... this is working stable an accurate.
If you got my Sample working, select "Motion Detection" in Combobox and see, what's going on.  :)

Best, Michael
Title: Re: OpenCV with Lazarus
Post by: m4u_hoahoctro on May 17, 2018, 06:14:05 pm
hello,
here is a starting point to use opencv with Lazarus.
Not sure that works with all the functions of Opencv, but works with the lkdemo  ( video motion tracking)
OpenCV.pas needs to be checked because it is a version for 2.1 version of Opencv and i use it with version 3.0 of Opencv ( I have done some changes for that works).
OpenCV.pas needs some changes to work with Linux.
Lkdemo Lazarus project :
In attachment lkdemo project for Lazarus
 Download opencv 3.0 for windows from here (http://opencv.org/downloads.html)
Extract the  dlls  \opencv-3.0.0.exe\opencv\build\x86\vc12\bin\*.dll (choose the right folder for your O.S ex : x86 -> 32 bits , vc12 -> visual c++ dlls  version 12)  from opencv-3.0.0.exe with 7z  in your project folder.
 you must change this line in unit1.pas -> choose a video file or capture from CAM
 
Code: Pascal  [Select][+][-]
  1.  //      capture := cvCaptureFromCAM(0);
  2.         capture := cvCaptureFromFile(PChar('f:\temp\videos\test.mp4'));

tested with Lazarus 1.6 Windows 32 bits and Opencv 3.0.

Thanks to Giandomenico (http://gidesa.altervista.org/camshiftdemo.php)   
Enjoy !

I followed your instruction (using CAM), but on my DELL Inspirion 14 series 3000, I just see the flash light, I dont see anything in app window
Title: Re: OpenCV with Lazarus
Post by: dimonsky on July 08, 2018, 10:34:34 am
Could you please help:

CPP code reads picture correctly:
Code: Pascal  [Select][+][-]
  1. cv::Mat img;
  2. img = imread("/home/pi/MyPrograms/cxx/Where.png", IMREAD_UNCHANGED);

but Lazarus reads wrong number of rows (just toooo big value). Cols number is OK:
Code: Pascal  [Select][+][-]
  1. var
  2. img:PCvMat;
  3. ...
  4. img:=cv_imread(pchar('/home/pi/MyPrograms/cxx/Where.png'),CV_LOAD_IMAGE_UNCHANGED);

what is the reason??

I run code on Raspbery pi with the attached interface header.
Title: Re: OpenCV with Lazarus
Post by: Edson on July 14, 2018, 01:04:52 am
Just to note all the codes for "OpenCV.pas" I've seen here are using the directives:

Code: Pascal  [Select][+][-]
  1. {$ifndef V3 AND $ifndef V2}

But I've found this is not working the proper way.

I've replaced it with:

Code: Pascal  [Select][+][-]
  1. {$if not Defined(V3) AND Not Defined(V2)}

and it works OK.
Title: Re: OpenCV with Lazarus
Post by: Edson on July 29, 2018, 08:21:11 am
but Lazarus reads wrong number of rows (just toooo big value). Cols number is OK:
Code: Pascal  [Select][+][-]
  1. var
  2. img:PCvMat;
  3. ...
  4. img:=cv_imread(pchar('/home/pi/MyPrograms/cxx/Where.png'),CV_LOAD_IMAGE_UNCHANGED);

what is the reason??

I run code on Raspbery pi with the attached interface header.

It's probably your structure TIplImage has not the correct size.  Check the size of the fields of the records. I've tested your code in Ubuntu and it works OK.
Title: Re: OpenCV with Lazarus
Post by: Edson on July 29, 2018, 07:03:25 pm
My small collaboration: https://github.com/t-edson/MiOpenCV
Fixed to work in Lazarus 1.8 for Windows and Linux.
Title: Re: OpenCV with Lazarus
Post by: Edson on August 03, 2018, 11:04:09 pm
Other contribution for Linux/Windows: https://github.com/t-edson/LazarusOpenCV
Title: Re: OpenCV with Lazarus
Post by: Jurassic Pork on September 08, 2021, 07:14:21 am
hello,
Another possibility -->  Python4Lazarus  opencv-python
requirements :
Python4Lazarus package
A python embedded distribution  with same "version" of your lazarus project ( 32 bits , 64 bits)
pip python utility to get modules, libraries from the pypi repository
knowlege of python language.
pros :
fast
use the last version of opencv  (embedded in opencv-python library)
can use existing python scripts with small changes (to communicate with lazarus).
in attachment example of demo project to use opencv to detect stop panels in an image using  Haar feature-based cascade classifier.
the result of python script is displayed in a Timage component.
Lazarus 2.0.12  64 bits - Windows  10 - python 3.9 - opencv 4.5.3   
Time to detect the panels : 0.062 s

Friendly, J.P
Title: Re: OpenCV with Lazarus
Post by: avra on September 09, 2021, 01:22:31 am
Nice. However native usage of OpenCV 4.xx without Python would require C bindings around C++ as found here:
https://github.com/aferust/opencvd
https://github.com/hybridgroup/gocv
TinyPortal © 2005-2018