Forum > DirectX

DSPack for Lazarus - Win32 DirectShow Multimedia components

<< < (10/10)

Gyuri:
Hello to All,

I apologise if my post sounds too simple for some of you, but I am a novice in Pascal programming.

I am testing a USB camera with DirectShow, using the DSPACK, and I encountered some problems.
I can visualise the live picture of the camera in a VideoWindow, but I would like to superipose over the
live picture a simple crosshair (see the attached picture). I am using a VMRBitmap to transfer the drawing
to mix it with the live video image.

I draw the pair of horizontal and vertical red lines which form a crosshair on a Bitmap (TBitmap) with white
background. The bitmap could be transferred to the VMRABitmap with the Loadbitmap procedure. However,
this directly is not working (I mean, it does not gives result). I am using the vmrbSrcColorKey and ColorKey
for the white background, this should remain transparent over the live video image, only the crosshair should
be visible from the entire bitmap overlayed on the video. This works correctly under Delphi.


--- Code: ---// crossBitmap is a TBitmap with the red haircross on it over a white background, it is created previously
try
VMRBitmap.LoadBitmap(crossBitmap);             
VMRBitmap.Source := VMRBitmap.Canvas.ClipRect;
VMRBitmap.Options := VMRBitmap.Options + [vmrbSrcColorKey];
VMRBitmap.ColorKey := clWhite;
VMRBitmap.DrawTo(0,0,1,1, 1);
finally
crossBitmap.Free;
 end;

--- End code ---

I found a "brute force" way to solve this, first I am saving the bitmap to a file, load the file, and pass the bitmap to the
VMRABitmap. Yes, I admit, this is not a correct way, and I would not use this, but for now it is the only working solution.
The crosshair position has to be moved on the video image, so I can't save and load every time the bitmap.


--- Code: ---// crossBitmap is a TBitmap with the red haircross on it over a white background, it is created previously
crossBitmap.SaveToFile('test.bmp');
try
crossBitmap.LoadFromFile('test.bmp');
VMRBitmap.LoadBitmap(crossBitmap);             
VMRBitmap.Source := VMRBitmap.Canvas.ClipRect;
VMRBitmap.Options := VMRBitmap.Options + [vmrbSrcColorKey];
VMRBitmap.ColorKey := clWhite;
VMRBitmap.DrawTo(0,0,1,1, 1);
finally
crossBitmap.Free;
end;

--- End code ---

I have a clue, that this behaviour is due to the native TBitmap format of Lazarus, which is different than the Windows
bitmap, and since VMRABitmap is expecting a Windows type bitmap, it does not mix over the video the desired content.

But I am not able to find a solution. Can anyone recommend another way?

I also noticed the problem mentioned on the first page of the topic, the VMRBitmap.LoadEmptyBitmap
does not work for me either. Instead, to clear the overlay on the video, I am using the same trick, I create
a bitmap, and pass it to VMRBitmap. This could be a compromise, but is acceptable.


--- Code: ---
//emptyBitmap is a TBitmap
emptyBitmap := TBitmap.Create;                 
VMRBitmap.LoadEmptyBitmap(400,300,pf24bit ,clWhite);    //a pixel formattal van valami baj
//VMRBitmap.LoadBitmap( emptyBitmap );
VMRBitmap.Source := VMRBitmap.Canvas.ClipRect;
VMRBitmap.DrawTo(0,0,1,1,0);
emptyBitmap.Free;
end;

--- End code ---

Thanks in advance,
Gyuri

af0815:
For the records, i have done a Fork on GitHub  O:-)  https://github.com/afriess/LazarusVideoUtilities

Thanks to the holder of the original codebase -> Mike.Cornflake  :) https://sourceforge.net/projects/lazarusvideoutilities/

The actual code is working with Lazarus 1.8.0RC5 r56092M FPC 3.1.1 i386-win32-win32/win64 too. It is only working on Windows, because of using MS-DirectShow.

I use this package to work with USB-Cameras in Win7 and WIn10 with resolution up to 1920x1080. This looks like a natural limitation of DirtectShow. Because 4k resolution (eg. Logitech BRIO) are only working with M$ UWP programming on the last version Win 10 (1709) - if the hardware support the 4k.

Andreas

Mike.Cornflake:

--- Quote from: af0815 on November 03, 2017, 10:58:53 am ---For the records, i have done a Fork on GitHub  O:-)  https://github.com/afriess/LazarusVideoUtilities

Thanks to the holder of the original codebase -> Mike.Cornflake  :) https://sourceforge.net/projects/lazarusvideoutilities/

The actual code is working with Lazarus 1.8.0RC5 r56092M FPC 3.1.1 i386-win32-win32/win64 too. It is only working on Windows, because of using MS-DirectShow.
--- End quote ---

Awesome stuff, many thanks for this :-).  I've been unable to find time for any of the plans I had for this, let alone maintain it.

fin:
Thanks af0815 :)

mtron:

--- Quote from: af0815 on November 03, 2017, 10:58:53 am ---I use this package to work with USB-Cameras in Win7 and WIn10 with resolution up to 1920x1080. This looks like a natural limitation of DirtectShow. Because 4k resolution (eg. Logitech BRIO) are only working with M$ UWP programming on the last version Win 10 (1709) - if the hardware support the 4k.

--- End quote ---

This is great, Andreas!

Do you have any Lazarus example on how to work with camera capture, just still images?

Thanks and best

Navigation

[0] Message Index

[*] Previous page

Go to full version