Ejemplo n.º 1
0
        private void VideoOpen()
        {
            if (context.isVideo)
            {
                VideoClose();
            }

            DialogResult dlgResult = openVideoFileDlg.ShowDialog(this);

            if (dlgResult == DialogResult.OK)
            {
                // Открываем видеофайл
                IntPtr hBitmap;
                int    videoFramesCount;
                double videoFps;
                int    errcode = OcvWrapper.VideoOpen(openVideoFileDlg.FileName,
                                                      out context.videoHandle, out hBitmap, out videoFramesCount,
                                                      out videoFps);
                if (errcode != 0)
                {
                    MessageBox.Show("Unable to open input video!", "Error!",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                if (videoFramesCount == 0)
                {
                    MessageBox.Show("Input video is empty!", "Error!",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                // Сохраняем информацию о видеофайле в полях класса
                frameCurr = Image.FromHbitmap(hBitmap);
                context.VideoFramesCount  = videoFramesCount;
                context.VideoFps          = videoFps;
                context.VideoFrameCurrent = 0;
                context.VideoDurationMs   = 1000.0 * videoFramesCount / videoFps;
                context.isVideo           = true;
                context.VideoFilePath     = openVideoFileDlg.FileName;
                context.modemajor         = EditModeMajor.VideoView;
                context.modeminor         = EditModeMinor.None;
                context.modedir           = EditModeDir.None;

                // Обновляем индикацию на форме
                VideoNavigatorUpdate();
                StatusBarUpdate();
                PictureRedraw();
                tbrVideoSlider.Minimum = 0;
                tbrVideoSlider.Maximum = context.VideoFramesCount - 1;
                int largeChange = context.VideoFramesCount / 20;
                if (largeChange > 1)
                {
                    tbrVideoSlider.LargeChange = context.VideoFramesCount / 20;
                }
                else
                {
                    tbrVideoSlider.LargeChange = 1;
                }
            }
        }
Ejemplo n.º 2
0
        private void VideoClose()
        {
            if (!context.isVideo)
            {
                return;
            }

            if (!MarkupClose())
            {
                throw new Exception("VideoClose(): Unable to close markup!");
            }

            // Закрываем объект декодирования видео
            int errcode = OcvWrapper.VideoClose(context.videoHandle);

            if (errcode != 0)
            {
                throw new Exception("VideoClose(): Unable to close video with ffmpeg!");
            }

            // Обновляем состояние контекста графического интерфейса
            context.Reset();

            // Обновляем индикацию на форме
            VideoNavigatorUpdate();
            StatusBarUpdate();
            PictureRedraw();
        }
Ejemplo n.º 3
0
        private void btnSubtract_Click(object sender, EventArgs e)
        {
            int x = Convert.ToInt32(txtNumber1.Text);
            int y = Convert.ToInt32(txtNumber2.Text);
            int z = OcvWrapper.TestSubtract(x, y);

            MessageBox.Show("Required Answer is " + Convert.ToString(z), "Answer",
                            MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
Ejemplo n.º 4
0
        private void btnSaveImage_Click(object sender, EventArgs e)
        {
            IntPtr hBitmap;
            Bitmap bmp;
            String filepath = "..\\Data\\" + txtOutputFile.Text;

            bmp     = new Bitmap(pictureBox1.Image);
            hBitmap = bmp.GetHbitmap();
            int errcode = OcvWrapper.ImageSave(filepath, hBitmap);
        }
Ejemplo n.º 5
0
        private void btnLoadImage_Click(object sender, EventArgs e)
        {
            IntPtr hBitmap;
            String filepath = "..\\Data\\" + txtInputFile.Text;
            int    errcode  = OcvWrapper.ImageLoad(filepath, out hBitmap);

            if (errcode == 0)
            {
                pictureBox1.Image = Image.FromHbitmap(hBitmap);
            }
            else
            {
                MessageBox.Show("Unable to load input image!", "Error!",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Ejemplo n.º 6
0
 private void CloseVideo()
 {
     if (isVideo)
     {
         OcvWrapper.VideoClose(videoHandle);
         pictureBox1.Image        = null;
         txtVideoFilePath.Text    = "";
         txtVideoFramesTotal.Text = "";
         txtVideoFps.Text         = "";
         txtVideoDuration.Text    = "";
         txtCurrentFrame.Text     = "";
         txtCurrentPosition.Text  = "";
         isVideo = false;
         enterAppState(appState.NOVID);
     }
 }
Ejemplo n.º 7
0
        private void btnProcessList_Click(object sender, EventArgs e)
        {
            int inputValuesCount, outputValuesCount;

            double[] inputValues, outputValues;

            inputValuesCount = lstInputValues.Items.Count;
            inputValues      = new double[inputValuesCount];
            for (int i = 0; i < inputValuesCount; i++)
            {
                inputValues[i] = Double.Parse(lstInputValues.Items[i].ToString());
            }

            OcvWrapper.TestAddArray(inputValues, inputValuesCount, out outputValues, out outputValuesCount);
            for (int i = 0; i < outputValuesCount; i++)
            {
                lstOutputValues.Items.Add(outputValues[i].ToString());
            }
        }
Ejemplo n.º 8
0
        private void btnOpenVideo_Click(object sender, EventArgs e)
        {
            // Открываем диалог выбора пути к видеофайлу
            DialogResult result = openVideoDlg.ShowDialog(this);

            if (result != DialogResult.OK)
            {
                return;
            }

            // Открываем видеофайл
            IntPtr hBitmap;
            int    errcode = OcvWrapper.VideoOpen(openVideoDlg.FileName,
                                                  out videoHandle, out hBitmap,
                                                  out videoFramesTotal, out videoFps);

            if (errcode != 0)
            {
                MessageBox.Show("Unable to open input video!", "Error!",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            // Сохраняем информацию о видеофайле в полях класса
            ixFrameCurr     = 0;
            frameCurr       = Image.FromHbitmap(hBitmap);
            videoDurationMs = 1000.0 * videoFramesTotal / videoFps;
            isVideo         = true;
            enterAppState(appState.ISVID_NOTRAJ);

            // Отображаем информацию о видеофайле на форме
            pictureBox1.Image        = frameCurr;
            txtVideoFilePath.Text    = openVideoDlg.FileName;
            txtVideoFramesTotal.Text = videoFramesTotal.ToString();
            txtVideoFps.Text         = videoFps.ToString();
            txtVideoDuration.Text    = videoDurationMs.ToString();
            trackBar1.Maximum        = videoFramesTotal - 1;
            //trackBar1.LargeChange = videoFramesTotal - 1;
        }
Ejemplo n.º 9
0
        // Метод перематывает видео к нужному кадру и соответственно
        // обновляет состояние интерфейса на форме
        private bool VideoMoveTo(int iframe)
        {
            if (!context.isVideo)
            {
                throw new Exception("No video loaded!");
            }

            if (iframe < 0 || iframe >= context.VideoFramesCount)
            {
                return(false);
            }

            double positionMs = iframe *
                                context.VideoDurationMs / context.VideoFramesCount;

            // Перематываем видеофайл
            IntPtr hBitmap;
            int    newframe;
            int    errcode;

            errcode = OcvWrapper.VideoSeek(context.videoHandle, positionMs,
                                           out hBitmap, out newframe);
            if (errcode != 0)
            {
                MessageBox.Show("Unable to seek position in video!", "Error!",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }

            // Сохраняем информацию о текущей позиции видео в полях класса
            context.VideoFrameCurrent = newframe - 1;
            frameCurr = Image.FromHbitmap(hBitmap);

            // Отображаем информацию о текущей позиции видео на форме
            VideoNavigatorUpdate();
            PictureRedraw();
            return(true);
        }
Ejemplo n.º 10
0
        // Метод перематывает видео до нужной позиции
        private void GoToPosition(double video_time_ms)
        {
            // Перематываем видеофайл
            IntPtr hBitmap;
            int    iframe;
            int    errcode;

            errcode = OcvWrapper.VideoSeek(videoHandle, video_time_ms, out hBitmap, out iframe);
            if (errcode != 0)
            {
                MessageBox.Show("Unable to seek position in video!", "Error!",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            // Сохраняем информацию о текущей позиции видео в полях класса
            ixFrameCurr = iframe;
            frameCurr   = Image.FromHbitmap(hBitmap);

            // Отображаем информацию о текущей позиции видео на форме
            txtCurrentFrame.Text = ixFrameCurr.ToString();
            pictureBox1.Image    = frameCurr;
        }