* * *

Author Topic: OpenCV with Lazarus  (Read 5821 times)

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 682
OpenCV with Lazarus
« on: March 07, 2016, 11:40:04 am »
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
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   
Enjoy !
« Last Edit: March 07, 2016, 11:53:57 am by Jurassic Pork »


  • New member
  • *
  • Posts: 46
Re: OpenCV with Lazarus
« Reply #1 on: April 18, 2016, 09:12:33 pm »


  • New member
  • *
  • Posts: 43
Re: OpenCV with Lazarus
« Reply #2 on: January 09, 2018, 02:19:42 pm »
My small contribution (Face detect, working Sample!):

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


Have fun, Michael


  • Hero Member
  • *****
  • Posts: 1183
Re: OpenCV with Lazarus
« Reply #3 on: January 19, 2018, 04:10:58 am »
Ooh.  OpenCV has been on my TODO list for a while.  Many thanks for posting this...
Lazarus Trunk/FPC Trunk on Linux & Windows [7, 8.1]
  Have you tried searching this forum or the wiki?:   http://wiki.lazarus.freepascal.org/Alternative_Main_Page
  BOOKS! (Free and otherwise): http://wiki.lazarus.freepascal.org/Pascal_and_Lazarus_Books_and_Magazines


  • New member
  • *
  • Posts: 43
Re: OpenCV with Lazarus
« Reply #4 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


best, Michael
« Last Edit: January 22, 2018, 03:36:57 pm by six1 »


  • Newbie
  • Posts: 1
Re: OpenCV with Lazarus
« Reply #5 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


  • New member
  • *
  • Posts: 43
Re: OpenCV with Lazarus
« Reply #6 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



Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus