PDA

View Full Version : AVI capture & ImageAvailable Event



Joram
June 3, 2009, 12:10:26
Hello everyone,

First off I'm fairly new to c# and the ImageingControl and I hope you can give me some onformations about the problem I have:

I'm using the ICImagingControl ImageAvailable Event to receive new images and pass them further to a control I use (which adds some more overlays etc.). There is no instance of the ImageingControl visible on the form, so the LiveDisplay is set to false. Also I cannot use the Overlay-methods from the ImagingControl due to thef act that I use an already existing Control to draw Overlays which just accepts Images for background.

Now I also need to be able to capture avi-video from the camera. I read that it's not possible to use the ImageBuffer and capture an AVi file at the same time. What I've tried so far is:

Use the AviStartCapture() Method which saves the video but seems not to pass further any images to the buffer (I just asume this) so my own control with the Overlays doesn't get updated.

Captured Video with the MediaStreamSink which ends in the same effect as above.

Is there a good way maybe to use Filters to achieve my goal?
Thx alot for the help.

regards

Stefan Geissler
June 3, 2009, 12:55:42
Hello Joram,

this is a quite often dicussed topic in the forum. There is a sample at:
http://www.imagingcontrol.com/en_US/library/dotnet/image-and-avi-capture/

Joram
June 4, 2009, 15:50:24
Hello Stefan,

Thank you for your quick and helpfull solution.
I have another question which you hopefully have some guidance:

I've noticed, that, when using an ICImagingControl and FrameFilters that a "FileNotFoundException" Module not loaded... Error is raised if there is no control placed on the GUI but one is "manually" created and initialized within the programm. I found a workaround by just placing a control on the GUI but not using it in any way in the code.

Because I use a FrameFilter to grab incomming images and pass them to my own imageControl for display, I don't need the ICImagingControl to be on the GUI.

Thanks for your time
regards, Joram

Stefan Geissler
June 5, 2009, 10:39:49
Hi,

for dynamically creating IC Imaging Control, there are many posts about the license context class in this forum. Please search for "licensecontext".

Joram
June 10, 2009, 18:36:19
Hello Stefan,

Thx for your previous answer, I wouldn't have thought off this as a licence problem at first. Well this is solved now.

I have another problem regarding the usage of a uEye Camera Model UI-222x-M. To make it work properly I had to make the fps and negative height fixes as you described in other threads. (Btw in their latest driver release you can set a registry entry useAbsHeight as a workaround I think, more in their changelog).
Now the issue I have is, that while using a filter to copy images in the Transform Method and then using the MediaStreamSink to record the avi video, somewhere frames must get lost because the movie is around half the length than the record time. I did set the FrameTimeCorrection in the Sink to true. Other cameras (with lower fps) do work properly. When having the filter disabled, the uEye camera works fine as well. The Transform-Method uses 4-6ms to compute om my machine.

This is the Transform Method from the Filter that copies the images away:

public override bool Transform(IFrame src, IFrame dest)
{
unsafe
{
if (m_bEnabled)
{
// Check whether the destination frame is available
if (dest.Ptr == null) return false;

// Copy the member variables to the function's stack, to protect them from being
// overwritten by parallel calls to setThreshold() etc.
//
// beginParamTransfer/endParamTransfer makes sure that the values from various
// member variables are consistent, because the user of this filter must enclose
// writing parameter access into beginParamTransfer/endParamTransfer, too.
BeginParameterTransfer();
bool enabled = m_bEnabled;
EndParameterTransfer();

byte* pIn = src.Ptr;
byte* pOut = dest.Ptr;

if ((_bitmap[_writeIndex] == null) || (_bitmap[_writeIndex].Width != src.FrameType.Width) ||
(_bitmap[_writeIndex].Height != Math.Abs(src.FrameType.Height)))
{
_bitmap[_writeIndex] = new Bitmap(src.FrameType.Width, Math.Abs(src.FrameType.Height),
System.Drawing.Imaging.PixelFormat.Format24bppRgb) ;
}

BitmapData bdat = _bitmap[_writeIndex].LockBits(new Rectangle(0, 0, _bitmap[_writeIndex].Width,
_bitmap[_writeIndex].Height),
ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);

try
{
CopyMemory(bdat.Scan0, src.GetIntPtr(), src.FrameType.BufferSize);
}
finally
{
_bitmap[_writeIndex].UnlockBits(bdat);
}

if (NewImage != null)
{
_bitmap[_writeIndex].RotateFlip(RotateFlipType.RotateNoneFlipY);
NewImage(_bitmap[_writeIndex]);
}

_writeIndex = (_writeIndex + 1) % _bitmap.Length;
//image.Dispose();
}

dest.CopyFrom(src);
}

return true;
}

Thx for your help.

Stefan Geissler
June 11, 2009, 09:09:15
Hi Joram,


I wouldn't have thought off this as a licence problem at first. Well this is solved now.
Very well!

I have another problem regarding the usage of a uEye Camera Model UI-222x-M. To make it work properly I had to make the fps and negative height fixes as you described in other threads. (Btw in their latest driver release you can set a registry entry useAbsHeight as a workaround I think, more in their changelog).
The registry entry is new to me. I very seldom use the IDS camera, but I will keep this in mind.

To your last issue: I wonder how long your transform method takes. If it lasts too long, then the filewriter drops the frames an inserts empty ones. I suggest to comment out the copymemory function and try again. If the AVI file is properly in this case, then the copymemory and the amount of data is the bottleneck. I am afraid, this can not be fastened.
Also rotation and flip can be very CPU intensive, I suggest to comment this line to for testing.