예제 #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;
                }
            }
        }
예제 #2
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;
        }