PDA

View Full Version : lines disappearing or changing width in overlay on resized video



grizli
March 7, 2009, 18:44:45
Hi all
I've got a .Net user control wrapping an ICImageControl. it's used in an app as a basic aiming device: the video is resized to enlarge the pic and an overlayBitmap is used to draw crosshairs on the image, which move on screen according to range. the supplied overlay coordinates are corrected by the original video size / enlaged video size ratio, so the crosshairs seemingly display in the correct relative position. the thing is, the crosshairs lines sometimes thin out or even disappear.
my guess is it's a translation problem, since the ratio is float by definition (i cast it to int when calling the DrawLine() method), but still, since the video image is enlarged and not shrunk, why do lines change width to the point they disappear?
other trivia: i'm using IC Image Control 3.0 .NET, and the crosshairs are 1 pixel wide, loaded from file

i've also written a test project, where I use DrawLine with ratio corrected coordinates to draw a square with a cross inside, and use 2 buttons to move it's x position by one pixel each time, for left and right.

the original video is 640X480 webcam, and the new size after LiveDisplayDefault = false is 1024X768 .

each step I 1.delete the old lines by drawing on them with the dropout color,
2.change the original x pos by 1 (before the ratio correction)
3. draw the the crossed square to the new position.

when i do not resize the video, the lines are 1 pixel wide all the time, moving left and right. after resize the same code produces a crossed square where the lines are sometime 2 pixels wide and sometimes 1 pixel wide. I can live (i think) with the lines being 2 pixels wide, but i need it to be constant...
when using Math.Floor(x) to make sure, I needed 2 clicks for each move (naturally), but still the vertical lines were sometimes thin and some times wide.

any ideas will be more than welcome

thanks
grizli

grizli
March 8, 2009, 15:06:08
o.k, further insights:
the problem isn't with the control, it's with the fact the overlay bitmap is defined the same size as the original video size, and if the video is scaled the bitmap is also scaled. if the scaling is by an integer (2,3,4 - eg. on a 640X480 source video, scale the video to 1280X960, 1920X1440 etc) the lines draw fine. If, however, the ratio is not clean, (say 640X480 to 1024X768 where the ratio is 0.625) whenever the xpos * scaling ratio has a reminder greater than 0.5, the vertical line width will shrink. that's the good news. the bad news is that I can't figure out how to juggle with the Pen width or the coordinates value themselves, so that it will solve this...

any idea?

grizli

Stefan Geissler
March 9, 2009, 11:03:16
Hello Grizli,

you found the reason for the disappearing lines: If the image was resized, some pixel may are substituted. But this should happen only , if the image was made smaller. If the image was enlarged, then no lines should disappear.

I suggest to have a look on your xpos value and on the type casting: You should use something like
xpos = (int)((double)xpos * 0.625);

This should return valid values.

grizli
March 9, 2009, 11:40:49
Hi Stefan
I believed the same about this not happening when enlarging, only when shrinking, but I can't argue with the test app. the pos is exactly the way you suggested in the original app, in the test app I wrote everything from scratch using the overlay bitmap Graphics to eliminate any translation errors I might have introduced, and there I use Graphics.PageScale = 1.6; to manage the scaling. anyway, the problem isn't with the location - the line is there - it's with the line width, which becomes thinner...

thanks
grizli

Stefan Geissler
March 9, 2009, 12:27:55
Girzli,

I never worked with Graphics.PageScale, thus I do not know, what it does. What about the IC built.in zoom functions?

grizli
March 9, 2009, 21:28:00
Hi Stefan
the whole thing came into light while using the control's overlayBitmap DrawLine method while providing the necessary ratio correction myself. again, the position is correct, but the line width isn't...

grizli

grizli
March 10, 2009, 13:12:39
Hi Stefan
is there any way I can control the size of the overlayBitmap? maybe through a filter?

grizli

Stefan Geissler
March 10, 2009, 14:03:27
Grizli,

The size of the overlaybitmap can not be controlled. It must be the same size as the video format.

Also, it the video is enlarged, then lines will not be substituted. This can only happen, if the video was made smaller.

You can avoid the problem, if you painted the live video in an ImageAvailable Event handler and a Delegate on your own. Then you can draw the lines every time with one pixel width, regardless of the zoom of the video.

grizli
March 12, 2009, 15:47:30
Hi Stephan
I tried the ImageAvailable event trick, the markers do mark correctly, but it introduces delays to the video, and once in a while there're flickers in the images. anyway, I wrote another test app, and there's definitely a problem with the overlay resize implementation. I wrote a test where I draw a cross on the video and can resize it (coordinate ratio applied, of course), and also open a new form with only a picture box, into which I copy the original - pre resize- image buffer, and then resize the image using Graphics.
i took the following pics:
from the video, at 640x480 - original size, ratio 1.0f

from the video, screen shot after resize to 1024x768.

please notice the vertical line on the cross in the 1024x768 pic, it is thinner. when the marker moves across the window it's very noticable, I assure you. at my client's pc, when the screen resolution is lower, the lines disappear completely.

grizli
March 12, 2009, 15:56:23
since I can't attach more than 3 images per post, here are the picture box source image and the resized one (resized using
Graphics g = graphics.FromImage(pictureBox1.Image);
g.DrawImage(image, new RectangleF(0f,0f,1024.0f, 768.0f)); )
as one can see, the vertical and horizontal lines of the marker are the same width. if the demo app source or exe are of any interest, I'll be happy to provide them.

since this is a client reported bug, I'm in a bit of a problem here, so any insights will be appreciated.

nice weekend to one and all

grizli

Stefan Geissler
March 13, 2009, 10:53:26
Hi Grizli,

The flicker is common. In C++ I had a programmin afford to avoid this problem.

However, I would like to have a look on your source code, thus I am able to reproduce your problem and hopefully present a solution. Please contact me at http://www.imagingcontrol.com/en_US/support/case/

sdecorme
April 3, 2009, 15:18:37
any solution for this flickering problem ?

Stefan Geissler
April 3, 2009, 15:35:50
Well, the solution is do draw the image and the lines in memory fist. After all drawings are done, the image in memory should be shown in the Picturebox.

sdecorme
April 3, 2009, 15:39:52
I don't know how to do this in c#.
thanks

Stefan Geissler
April 6, 2009, 11:29:01
Sdecorme,

Just before I create a sample for you, I would like to describe it in words:

In order to avoid the flickering, you must draw the ImageBuffer and the graphics in memory. After this is done, you show the resulting image the picturebox.

Thus, the first step is creating a System.Drawing.Bitmap.

System.Drawing.Bitmap MyBitmap = ICImagingControl1.ImageActiveBuffer.Bitmap.

In the next step you need Graphics object:
private Graphics TheGraphics;
TheGraphics = Graphics.FromImage(MyBitmap );

The "TheGraphics" Object is used to draw your lines and other stuff. After doing so, you show the Graphics:
PictureBox1.Image = MyBitmap;

I hope, this works. Please give it a try.

sdecorme
April 6, 2009, 11:39:17
I think there is a make a wrong explanation.
My problem is in the AviStartCapture function
When I make my video the size of the video (720x480) is different then the IcImagingControl(768x576) and the horizontal lines disappears .
but the overlay work fine in live mode.
Thanks

Stefan Geissler
April 6, 2009, 12:05:58
Hello Sdecorme,

Do you use the DVEncoder to resize the live video from 768x576 to 720x480? If so:

It seems in this case, the DV Encoder is set to NTSC instead of PAL-B video norm, thus it resizes the live video. If lines are removed from the original image while the image is resized, then it may happen, that these removed lines contained your horizontal line. Thus the horizontal line is deleted. I suggest to configure the DVEncoder thus it uses PAL (768x576) video norm. The following sample shows, how to configure a codec:http://www.imagingcontrol.com/en_US/support/documentation/dotnet/SaveCodecProperties.htm

If you do not use the DV Encoder, how do you resize the incoming live video stream from 768x576 to 720x480 resolution?

sdecorme
April 6, 2009, 15:25:39
I've set this before, but the user changed it by another way. So I was in NTSC
your right once again.
Do you know a way to configure it automatically ?(I know it is not made by you :embarrassed:)

Stefan Geissler
April 6, 2009, 15:41:31
Hi,

No, there is way to configure this codec automatically. Only the way described in the sample is possible.

The NTSC is the default video norm of this codec.

sdecorme
April 6, 2009, 16:49:47
I found another way with the directxshow function.
I've recording 2 video one in NTSC one in PAL with a PAL video camera.
the PAL video is :bad:
the NTSC video is :good:
Why a PAL video signal recorded in PAL give a worth quality then the NTSC recording ?

Stefan Geissler
April 6, 2009, 17:38:28
Well, I must surrender, this is a question, I have no answer for. May be its a issue of the DV Encoder? Did you try another codec, e.g. DivX?

sdecorme
April 7, 2009, 08:09:49
No
Because I want to have a better quality .
Thanks

Stefan Geissler
April 7, 2009, 10:20:30
Well, the DivX creates a good quality be small AVI files. This depends on its settings.

sdecorme
April 7, 2009, 10:28:03
Ok I will test it can I record on while encoding .

Please could you have a look at it :
http://www.theimagingsourceforums.com/showthread.php?t=321824
I've put it in the wrong forum

Thanks

Stefan Geissler
April 7, 2009, 10:29:17
Just answered!

seaf
October 27, 2009, 14:10:25
As for me for resizing video I prefer to use Vidcrop PRO

Stefan Geissler
October 27, 2009, 14:13:49
Nice. How to integrate this into your C# source code?