PDA

View Full Version : resizing live video



Unregistered
January 7, 2005, 22:51:35
Hi,

I'm useing the IC control V2.1 trial.
Visual Studio .net C#

It looks very promising for what we want to do except a couple small things.

1. I need to resize the video stream before applying the overlay.

this raises another quation

2. can I add direct show filters to the filter graph the control is using? If I can will the overlay be the last filter/effect applied to the image?

the problem I am encountering at the moment is that resizing the video by using this code:

//set video size to physical size
videoControl1.LiveDisplayDefault = false;
videoControl1.LiveDisplayWidth = videoWidth;
videoControl1.LiveDisplayHeight = videoHeight;

this resizes the video to the size of the control.

now I want to align a target overlay. So the user will click on the live video then I draw a circle in that position. With this current code the mouse position and the overlay position progressively become more and more off the further from point 0,0 you click. My assumption is that the overlay drawing coordinates are based on the captured video pixel locations and the mouse coordinates are based on the controls pixel location.

Thank You
Tom

PS: Hope I was clear enough.

Stefan Geissler
January 10, 2005, 12:27:51
Hello Tom,



I need to resize the video stream before applying the overlay.

This is not possible. You may use a smaller video format if it is available. The resizing mechanism is only for the display of the live video. The image in the filter graph still keeps it original size.



Can I add direct show filters to the filter graph the control is using? If I can will the overlay be the last filter/effect applied to the image?

No. This is not possible with IC Imaging Control 2.1

If you want to map mouse coordinates of a resized displayed image on the overlay, you must recalculate them using the relation of the video format's dimensions to the dimensions of the display window. If you make the live video display smaller than the original video format, you not see the drawings on the overlay if they only have one pixel width.

You may use a PictureBox control to display the live video and perform the drawings. You should use a timer event to snap an image from the live video. This allows other events like program end, mouse events etc. to be handled too. This is the C# sample code:


private void Form1_Load(object sender, System.EventArgs e)
{
timer1.Enabled = false;
timer1.Interval = 20;

try
{
icImagingControl1.LoadDeviceStateFromFile("device.xml",true);
}
catch
{
}

if (icImagingControl1.DeviceValid)
{
icImagingControl1.LiveStart();
timer1.Enabled = true;
}
}

This is the event handler for a device selection button:


private void cmdDevice_Click(object sender, System.EventArgs e)
{
timer1.Enabled = false;
if (icImagingControl1.DeviceValid)
{
icImagingControl1.LiveStop();
}

icImagingControl1.ShowDeviceSettingsDialog();

if (icImagingControl1.DeviceValid)
{
icImagingControl1.SaveDeviceStateToFile("device.xml");
icImagingControl1.LiveStart();
timer1.Enabled = true;
}
}

This is the timer event handler that is used for flicker free drawing. Please remark, the drawing coordinates of the yellow line are coordinates on the memory bitmap and do not need to be set in relation to the size of the video format.


/* timer1_Tick
*
* To draw flickerfree, all the drawings must be performed into a separate
* Bitmap object in memory. This bitmap is created with the same dimensions
* as the PictureBox control.
* An image is snapped from the live video stream. It is accessed by a
* call to the method ImageActiveBuffer() that returns an ImageBuffer object.
* With the Graphics.DrawImage() method the snapped image is copied resized
* into the memory bitmap "buffer". Then the drawings are done in the same
* Graphics objects. Each time the timer1_Tick method is called, all drawings
* must be drawn completely new, because they are overwritten by the live video
* image.
* After all drawings on the memory bitmap have been performed, the memory
* bitmap must be drawn into the PictureBox.
*/
private void timer1_Tick(object sender, System.EventArgs e)
{
Graphics graph;
Pen ThePen = new Pen(Color.Yellow, 1);
Bitmap buffer = new Bitmap(pictureBox1.Width, pictureBox1.Height);
timer1.Enabled = false;

graph = Graphics.FromImage(buffer);

// Snap the image from the live video stream.
icImagingControl1.MemorySnapImage();
// Draw the snapped image resized in the memory bitmap.
graph.DrawImage((Image)icImagingControl1.ImageActi veBuffer.Bitmap,0,0,pictureBox1.Width, pictureBox1.Height);
// Now perform any additional drawings.
graph.DrawLine(ThePen,10,10,200,200);

graph.Dispose();
ThePen.Dispose();

graph = pictureBox1.CreateGraphics();
// Copy the memory bitmap in the PictureBox control.
graph.DrawImage((Image)buffer,0,0);
graph.Dispose();
buffer.Dispose();
timer1.Enabled = true;
}