Recent

Author Topic: OpenCV - how begin?  (Read 1953 times)

krolikbest

  • Full Member
  • ***
  • Posts: 246
OpenCV - how begin?
« on: November 18, 2019, 03:07:51 pm »
Hello,

would like to write an application whose aim is to move a 2D device according to the changes in the tracked object. First part is to use some tracking way and here I thought about OpenCV
Application will be working on Windows7. What version of OpenCV do you recommend and are there some help according to installation, use etc (examples to learn) ?


del

  • Sr. Member
  • ****
  • Posts: 258
Re: OpenCV - how begin?
« Reply #1 on: November 18, 2019, 09:59:15 pm »
I'm gonna start playing with OpenCV in two or three weeks. The latest C++ incarnation. I love Lazarus so the challenge is to interact with OpenCV from Pascal. Here's a chunk of code I use in a wxWidgets app.

Code: C  [Select][+][-]
  1.   cv::Mat curr = imread(WX2CV(inFile.GetFullName()), cv::IMREAD_COLOR);
  2.   cv::Mat currG;
  3.   cv::cvtColor(curr, currG, cv::COLOR_BGR2GRAY);
  4.   cv::Mat flow;
  5.   double polySig = polyN * 1.2 / 8.0;
  6.  
  7.   cv::calcOpticalFlowFarneback(currG, prevG, flow, pyrScale, pyrLevs, winSize,
  8.     iterations, polyN, polySig, flags);
  9.  
  10.   cv::Mat normFlow = NormalizeFlow(flow);
  11.  

Basically the routine reads in a sequence of video frames and maps the motion vectors between them. The trick is gonna be to pass a pointer / buffer from Pascal to my small custom OpenCV "library", and use one of the buffer-based Mat constructors to create a full-blown Mat object. I'll actually do all the I/O in Pascal  - that way I have better control over the buffer. That's the idea, anyway. There's a Delphi repository that interfaces with the old deprecated C-based OpenCV. I don't know if that would help you or not.

krolikbest

  • Full Member
  • ***
  • Posts: 246
Re: OpenCV - how begin?
« Reply #2 on: November 19, 2019, 08:15:20 pm »
Thank for an answer. Because I'm completely in the mist in this subject, below is what I've done so far:
I've read this thread: https://forum.lazarus.freepascal.org/index.php?topic=31851.0 and especially took into consideration this work https://github.com/t-edson/LazarusOpenCV. However had to install ffmpeg (add it to windows path) and in order to run examples from last link had to copy a few files into program directory :
- msvcp140.dll
- concrt140.dll
- vcruntime140.dll
Completely no idea what these files are for.I focused on FaceDetect and finally run this example. Other will be checked soon.

del

  • Sr. Member
  • ****
  • Posts: 258
Re: OpenCV - how begin?
« Reply #3 on: November 19, 2019, 09:42:07 pm »
The old C-based image structure - IplImage - is still supported for backward compatibility. There's probably not much (relatively) that you can do with it these days, nor would want to do with it. But it sounds like it could be an excellent vehicle to move data back and forth between Pascal and C++. I could take existing Pascal - IplImage - C interfacing and "upgrade" the IplImage inside the C++ library to a modern cv::Mat. Then do all the processing, then finally "downgrade" (flatten?) it back into the IplImage for the trip home: C - IplImage - Pascal.

krolikbest

  • Full Member
  • ***
  • Posts: 246
Re: OpenCV - how begin?
« Reply #4 on: November 19, 2019, 09:56:10 pm »
Just now I'm digging into that: https://stackoverflow.com/questions/3232022/opencv-iplimage-versus-mat-which-to-use. It seems that I'm basing on an older ver but I don't mind me. Want only some basics functionality.

del

  • Sr. Member
  • ****
  • Posts: 258
Re: OpenCV - how begin?
« Reply #5 on: November 20, 2019, 03:15:17 am »
It's a good experience - you're way ahead of me.  :) And nobody ever caught cooties from learning a little C++.

 

TinyPortal © 2005-2018