i have this method:
private void UpdateControl(int videoWidth, int videoHeight)
{
int height = 640;
int width = height * videoWidth / videoHeight;
}
i can calculate the width but the height is 640 and i wonder if i can calculate the height also? i don’t understand also why it’s 640.
in this method i convert the first frame image Mat from a video file.
i convert the Mat to bitmap and then getting the bitmap width and height.
in this case i know that the actual image size is {Width=480, Height = 848}.
now i’m using the UpdateControl to find the real size that the pictureBox should be.
but i don’t understand why the height is 640 and what is the width calulcation and if there is a way to calculate the height too automatically.
private void InitVideoFile(string videoFileName)
{
_videoCapture = new VideoCapture(videoFileName);
_totalFrames = _videoCapture.FrameCount;
trackBarFrames.Minimum = 0;
trackBarFrames.Maximum = _totalFrames - 1;
trackBarFrames.TickFrequency = 1;
trackBarFrames.Value = 0;
_firstFrame = new Mat();
if (_videoCapture.Read(_firstFrame))
{
Bitmap bitmap = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(_firstFrame);
UpdateControl(bitmap.Width, bitmap.Height);
pictureBoxFrame.Image = bitmap;
labelImageSize.Text = "Image Size " + bitmap.Size.ToString();
labelFrames.Text = $"Displaying Frame 1/{_totalFrames}";
}
}