none
bitmap resizing and getting the right pix location RRS feed

  • Question

  • So I have two programs. One is my main program that is using aforge videosourceplayer and the other is a test program that is using a picture box. So now the test program is working right. I can draw a Square around an area and get the correct pixels location, but when I do it with my main program I do not get the right  pixel locations. 

    here is a pic from the main program:  

    now here is a picture from the test program :

    The test program uses the actual size of the camera but it cuts off the part of the picture that does not fit in the picturebox.

    The main program seem to compress the full image of the bitmap in to the size of the   aforge videosourceplayer .

    now to get the right picture location I tried this:

            origPosxStart = (int)((videoSourcePlayer.Size.Width / 3208D) * origPosxStart);
          origPosYStart = (int)(( videoSourcePlayer.Size.Height / 2200D ) * origPosYStart);

    but it did not work.

    what should I do ?


       

    Friday, August 2, 2019 3:02 PM

Answers

  • Yes, video players will stretch or shrink the video to fit into the player window.  What do you mean by "it did not work"?  What didn't work?  What result did you get?

    If both images start at (0,0), then the only difference is the stretch/shrink ratio.  Assuming the video window contains the entire frame, and assuming the bitmap itself is 3280x2200, it's just

        Xtest = Xmain * 3280 / videoSourcePlayer.Size.Width;
        Ytest = Ymain * 2200 / videoSourcePlayer.Sizez.Height;

    (You do not need to introduce floating point math here.  Just leave them all as integers.)

    How will your test program know what the video player's window size is?

    There is another consideration here.  In most cases a video player will try to keep the aspect ratio the same as the original, so the video does not appear to be squashed.  That means that the video won't quite fill the window in one of the two directions. That makes the computation more complicated.

    Here's an example.  Say I have a 2000x1000 video.  If I play that in a 200x100 window, it will multiply the sizes by 0.1 everything is even.  But if I play it in a 200x200 window, the player has to decide what to do.  If it literally filled the window, by multiplying by 0.1 in X and 0.2 in Y, then the video would look bad.  What most players will do is figure out which direction has the most shrinkage (0.1 in my example), and use that factor for both directions.  That leaves extra space in the window, which will be filled with black bars.

    If that is what is happening, then your computation is more complicated.


    Tim Roberts | Driver MVP Emeritus | Providenza & Boekelheide, Inc.

    • Marked as answer by Btb4198 Friday, August 2, 2019 9:38 PM
    Friday, August 2, 2019 7:14 PM

All replies

  • Yes, video players will stretch or shrink the video to fit into the player window.  What do you mean by "it did not work"?  What didn't work?  What result did you get?

    If both images start at (0,0), then the only difference is the stretch/shrink ratio.  Assuming the video window contains the entire frame, and assuming the bitmap itself is 3280x2200, it's just

        Xtest = Xmain * 3280 / videoSourcePlayer.Size.Width;
        Ytest = Ymain * 2200 / videoSourcePlayer.Sizez.Height;

    (You do not need to introduce floating point math here.  Just leave them all as integers.)

    How will your test program know what the video player's window size is?

    There is another consideration here.  In most cases a video player will try to keep the aspect ratio the same as the original, so the video does not appear to be squashed.  That means that the video won't quite fill the window in one of the two directions. That makes the computation more complicated.

    Here's an example.  Say I have a 2000x1000 video.  If I play that in a 200x100 window, it will multiply the sizes by 0.1 everything is even.  But if I play it in a 200x200 window, the player has to decide what to do.  If it literally filled the window, by multiplying by 0.1 in X and 0.2 in Y, then the video would look bad.  What most players will do is figure out which direction has the most shrinkage (0.1 in my example), and use that factor for both directions.  That leaves extra space in the window, which will be filled with black bars.

    If that is what is happening, then your computation is more complicated.


    Tim Roberts | Driver MVP Emeritus | Providenza & Boekelheide, Inc.

    • Marked as answer by Btb4198 Friday, August 2, 2019 9:38 PM
    Friday, August 2, 2019 7:14 PM
  • Weird, I just did that and it is working but the weird thing is, I am like 100 % sure I tried that this morning and it did not work.

    Friday, August 2, 2019 9:40 PM