Recent

Author Topic: Is it possible to Capture video and modify it before display in Windows (SOLVED)  (Read 5372 times)

Dzandaa

  • Sr. Member
  • ****
  • Posts: 332
  • From C# to Lazarus
(Lazarus version 2.2.4 and FPC 3.2.2 Windows)

Hi everybody,

Is it possible to capture a frame in real time from a webcam and modify it before display using or any Windows video class.

Or is there any other library I can use to perform that task?

I have created a 3D scanner with a camera and 4 lasers.

Working fine in Linux, but I want to also use in in Windows.

In Linux, I use TSdpoVideo4L2 to capture and modify a frame.

I can read an USB webcam in Windows using TVideoWindow, TFilterGraph and TFilter,
but I don't know if it is possible to change the frame before the display, F.E: detect objects.

Example welcome :)

Thank you.

B->


« Last Edit: June 19, 2024, 12:09:21 pm by Dzandaa »
Regards,
Dzandaa

d2010

  • New Member
  • *
  • Posts: 37
If you need capture Video, before you this question online,
- then you must teach DirectX , and you search
  the multiple files with directx.pas
After you learn DirectX , in 2..3 years, then you will understand your question and complexity your question; otherwise ...

You request a answer from your cat pet:
-- Dear my cat do you understand how my Win98 work inside him?

gidesa

  • Jr. Member
  • **
  • Posts: 96
Hello, you can use the Opencv library that has functions to open a webcam or video file stream, and process single frames.
In my repository there are a wrapper to Opencv  and examples for FPC/Lazarus.
The demo Camshiftdemo just open a webcam stream, and does some processing on frames.
Demo dnnObjectdetection and dnnObjectdetection2 detect objects using a specialized neural network.
Note that Opencv exists also for Linux, and the wrapper compiles on Linux, too (and also on MacOS).
So using Opencv + wrapper you could have a single video capture code on Windows and Linux.

https://github.com/gidesa/ocvWrapper46


« Last Edit: March 31, 2024, 05:33:28 pm by gidesa »

wadu

  • Newbie
  • Posts: 1
How can I adjust frames taken from a webcam in real-time before showing them on Windows, similar to what I do with TSdpoVideo4L2 in Linux for identifying objects in my 3D scanner? Are there specific Windows video classes suitable for this task, or should I explore alternative libraries?
« Last Edit: June 12, 2024, 01:38:29 pm by marcov »

Dzandaa

  • Sr. Member
  • ****
  • Posts: 332
  • From C# to Lazarus
Hi,

I'm looking for the same thing...
Easier in Linux than in Windows to find a simple video capture library with possibility to modify frames before displaying it.

In C# I use AForge and Accord, but I didn't find any equivalent for Lazarus.

OpenCV wrappers involve having Opencv compiled and installed on the destination machine.
For optimization, you also need a version compiled with the right CUDAs.

B->
Regards,
Dzandaa

Dzandaa

  • Sr. Member
  • ****
  • Posts: 332
  • From C# to Lazarus
Hi,

If you like "Old Stuffs", here is a Camera Capture Skeleton using Video For Windows from a Delphi Conversion.

Just a test, feel free to modify.

B->
Regards,
Dzandaa

gidesa

  • Jr. Member
  • **
  • Posts: 96
Hello, there is the also the Laz_Win_DsPack, a series of components for Directshow,
the successor of Video for Windows. In its repository there is one example for
capturing video source frames as BMP /TBitmap. Having the BMP, of course the choice
of library depends on what type of modification you want to do on image.
See https://forum.lazarus.freepascal.org/index.php/topic,16797.0.html
By the way,  Opencv official binaries for Windows, downloadable from their site,
has support for OpenCL, that is more general GPU library. Because Cuda is only for Nvidia
cards, instead OpenCL is for Nvidia, AMD, and more GPUs. 

Dzandaa

  • Sr. Member
  • ****
  • Posts: 332
  • From C# to Lazarus
Hi,

@Gidesa,

I know Laz_Win_DsPack, but I don't know how to capture a frame and modify it or how to select the camera and resolution.

I tried the VMRBitmap example but it plays just the video from the camera and when I click on Text, it crashes with Message:
Quote
Canvas does not allow drawing

As always, using a camera on lazarus with Windows is not as easy as in Linux :)

B->

Regards,
Dzandaa

gidesa

  • Jr. Member
  • **
  • Posts: 96
As always, using a camera on lazarus with Windows is not as easy as in Linux :)

You are totally right! I went crazy :-) Because Opencv was lacking camera tuning (contrast, etc.),
and DSPack was very low level.
But now things are a (bit) different.
In Laz Win Dspack the relevant examples are missing. You can download from Delphi DSPack Github
the Demos/D6-D7/SampleGrabber. Maybe it has to be adapted a bit to Lazarus.
More, I attach a Delphi unit I wrote. There is a class that, using DSPack, exposes some useful functions. For example
list all Directshow video sources,  select one of them, change parameters (contrast, brightness, ..),
capture a frame, show the video source native dialogs.
Also this unit probably has to be adapted to Lazarus.

af0815

  • Hero Member
  • *****
  • Posts: 1338
Try to use https://github.com/afriess/LazarusVideoUtilities.git and Branch WIP_andi, there are more samples

Edit: Compilable sample with Lazarus 3.4 (rev unknown) FPC 3.2.3 i386-win32-win32/win64 , but i have actual no camera installed
« Last Edit: June 12, 2024, 03:29:04 pm by af0815 »
regards
Andreas

Dzandaa

  • Sr. Member
  • ****
  • Posts: 332
  • From C# to Lazarus
Hi,

To @af0815

Lazarus Crash at loading.

I don't have FPC 3.2.3 (I have 3.2.2), so I presume that is a compatibility problem.

I rewrote the main form in a new project, add tst_prffrmvideo unit and form

set -dEINEKAMERA in Options

But when I select KameraOnExecute, I just have a message in the log, No opening Form:
Code: Pascal  [Select][+][-]
  1. A: Search Cam=LifeCam Num=1
  2. A: Cam=Webcam C110
  3. A: Select Cam =31ms
  4. A: No configured Camera found -> exit
  5. A: Play =0ms
  6. A: Stop =0ms
  7. --- Startup=2543ms ------

I uncommented   KameraA.Show;  Now I see the form.

I suppose I miss something :)

Thanks anyway.

B->



« Last Edit: June 12, 2024, 05:55:40 pm by Dzandaa »
Regards,
Dzandaa

af0815

  • Hero Member
  • *****
  • Posts: 1338
yes, you must know the name of the device or the correct devicenum.

The version of fpc and Lazarus is normal not the problem, the actual system here works for 7 years. So it was an older version too.

I'll look for a camera.
regards
Andreas

gidesa

  • Jr. Member
  • **
  • Posts: 96
Attached an example of using DSPack and TVideoControl, adapted for Lazarus (2.2.6)/FPC (3.2.2).
I think that you cannot directly modify image in VideoWindow control, but have to capture as bitmap, and show on a separate area, for example a TImage.

af0815

  • Hero Member
  • *****
  • Posts: 1338
I wor with the GraphStudioNext https://github.com/cplussharp/graph-studio-next to find out the internal working of the filters. And ther you find the Correct name and other information to deal later in Lazarus. And nearly all you can do with this tool you can also do with Lazarus. But the hardest thing is to connect the correct ports of the filters and the parameters.

I have the software running an get pictures

a) You have to configure the correct name of the camera
Code: Pascal  [Select][+][-]
  1.   KameraA.NameKamera:= 'Integrated Webcam';//MyNameKamera;
  2.   KameraA.NameFormat:= 'Major Type: Video - Sub Type: YUY2 Format: VideoInfo YUY2 640X480, 16 bits';//MyNameFormat;
  3.  
b ) After the camera is found you see the possible modes and this you have to configure too
c ) in tst_prffrmvideo remove the check for the correct width and heigh (or correct this value)

d) with toggle you can make snapshot

After this it is running for me :-)



regards
Andreas

Dzandaa

  • Sr. Member
  • ****
  • Posts: 332
  • From C# to Lazarus
Hi,

@af0815

Working now for:
Major Type: Video - Sub Type: MJPG Format: VideoInfo2 MJPG 1024X768, 24 bits

I also had to change:

Code: Pascal  [Select][+][-]
  1.            
  2.         if IsEqualGUID(VideoMediaTypes.Items[i].majortype,MEDIATYPE_Video) AND
  3.            IsEqualGUID(VideoMediaTypes.Items[i].subtype, MEDIASUBTYPE_MJPG) AND
  4.            IsEqualGUID(VideoMediaTypes.Items[i].formattype,FORMAT_VideoInfo) then
  5.          begin
  6.            if (VideoMediaTypes.Items[i].AMMediaType^.cbFormat > 0) and assigned(VideoMediaTypes.Items[i].AMMediaType^.pbFormat) then
  7.            with PVideoInfoHeader(VideoMediaTypes.Items[i].AMMediaType^.pbFormat)^.bmiHeader do begin
  8.              if SameText(GetFOURCC(biCompression),'MJPG') AND
  9.                   (biWidth = 1024) AND
  10.                   (biHeight = 768) AND
  11.                   (biBitCount = 24) then begin
  12.                {$Ifdef KAMERADEBUG}DoMessage('Media selected='+MediaStr); {$EndIf}
  13.                SelMedia:= i;
  14.                break;
  15.              end;
  16.            end;
  17.          end  
  18.  

Thank you very much.

I'll examine the code deeper later.

B->
Regards,
Dzandaa

 

TinyPortal © 2005-2018