コード例 #1
0
        private void processMovie()
        {
            if (videoReader.IsOpen)
            {
                Bitmap videoFrame;

                processor.Background = videoReader.ReadVideoFrame();

                int i = 0;

                while ((videoFrame = videoReader.ReadVideoFrame()) != null)
                {
                    Bitmap preprocess = processor.preprocessImage(videoFrame);
                    this.Dispatcher.Invoke(new Action(() => frameCountLabel.Content  = Properties.Resources.FPS_LABEL_BEGIN + (int)(++i / videoReader.FrameRate) + "s"));
                    this.Dispatcher.Invoke(new Action(() => preprocessedImage.Source = VideoProcessor.convertBitmap(preprocess)));

                    Bitmap diff = processor.findDifference(preprocess);
                    preprocess.Dispose();

                    this.Dispatcher.Invoke(new Action(() => differenceImage.Source = VideoProcessor.convertBitmap(diff)));

                    Bitmap final = processor.showMotion(videoFrame, diff);
                    diff.Dispose();

                    this.Dispatcher.Invoke(new Action(() => finalImage.Source = VideoProcessor.convertBitmap(final)));
                    final.Dispose();
                    videoFrame.Dispose();
                }
                i = 0;
                videoReader.Dispose();
                videoReader.Close();
                restart();
            }
        }
コード例 #2
0
        }//void

        public void parcala()
        {
            VideoFileReader reader = new VideoFileReader();
            IWMPMedia       saniye = axWindowsMediaPlayer1.newMedia(ofdVideoYukle.FileName);

            videoFrameList.Clear();

            reader.Open(ofdVideoYukle.FileName);
            this._TotalFrameCount = (int)saniye.duration * reader.FrameRate;
            this._VideoFPS        = reader.FrameRate;
            progressBar1.Maximum  = this._TotalFrameCount;
            FrameSayisi           = _TotalFrameCount;
            for (int i = 0; i < this._TotalFrameCount; i++)
            {
                Bitmap videoFrame = reader.ReadVideoFrame();
                string yol        = "C://Users//BegovicTeam//Desktop//video sıkıştırma//frameparcalanmis//" + "image" + i + ".mpeg";
                convertMpeg(videoFrame, yol);
                progressBar1.Value += 1;
            }
            reader.Close();
            reader.Dispose();

            birlestir();

            frameParcala.Abort();
        }
コード例 #3
0
        public void Dispose()
        {
            wallpaperPath = null;
            if (wallpaper != null)
            {
                wallpaper.Dispose();
            }
            if (gif != null)
            {
                foreach (Bitmap b in gif)
                {
                    if (b != null)
                    {
                        b.Dispose();
                    }
                }
            }
            if (loadStream != null)
            {
                loadStream.Dispose();
            }
            frameRateCounter.Stop();

            if (mp4 != null)
            {
                mp4.Close();
                mp4.Dispose();
                mp4frame = 0;
            }
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: Plugway/UVEA
        public static void Generate()
        {
            var reader = new VideoFileReader();

            reader.Open(VideoPath + VideoName);
            var    writer         = new VideoFileWriter();
            var    numberOfFrames = (int)reader.FrameCount;
            Bitmap probeBitmap    = reader.ReadVideoFrame(0);

            if (numberOfFrames > probeBitmap.Width)        //if user want -> fit to original width
            {
                numberOfFrames = probeBitmap.Width;
            }
            writer.Open(VideoPath + "out.mp4", numberOfFrames, probeBitmap.Height, OutputFps, VideoCodec.H265);
            for (var x = 0; x < probeBitmap.Width; x++)
            {
                var convertedBitmap = new Bitmap(numberOfFrames, probeBitmap.Height);
                reader.Open(VideoPath + VideoName);
                for (var f = 0; f < numberOfFrames; f++)
                {
                    var currentBitmap = reader.ReadVideoFrame();
                    for (var y = 0; y < probeBitmap.Height; y++)
                    {
                        convertedBitmap.SetPixel(f, y, currentBitmap.GetPixel(x, y));
                    }
                    currentBitmap.Dispose();
                }
                writer.WriteVideoFrame(convertedBitmap);
                convertedBitmap.Dispose();
            }
            reader.Dispose();
            writer.Close();
        }
コード例 #5
0
        private void ShutDown(string errmsg)
        {
            bool err = !string.IsNullOrEmpty(errmsg);

            if (err)
            {
                _reasonToStop = ReasonToFinishPlaying.DeviceLost;
            }


            try
            {
                if (_vfr != null && _vfr.IsOpen)
                {
                    _vfr?.Dispose();     //calls close
                }
            }
            catch (Exception ex)
            {
                Logger.LogExceptionToFile(ex, "FFMPEG");
            }

            PlayingFinished?.Invoke(this, new PlayingFinishedEventArgs(_reasonToStop));
            AudioFinished?.Invoke(this, new PlayingFinishedEventArgs(_reasonToStop));


            _stopEvent.Close();
            _stopEvent = null;
            _stopping  = false;
        }
コード例 #6
0
ファイル: VideoHelper.cs プロジェクト: jinzuoshou/FFireManage
        /// <summary>
        /// 截取视频缩略图
        /// </summary>
        /// <param name="videoPath">视频路径</param>
        /// <param name="thumbImagePath">缩略图文件路径</param>
        /// <param name="thubWidth">缩略图指定的边长(正方形)</param>
        /// <param name="thubQuality">缩略图质量</param>
        public static void VideoSnapshots(string videoPath, string thumbImagePath, int thubWidth, int thubQuality)
        {
            VideoFileReader reader = new VideoFileReader();

            try
            {
                lock (lockData)
                {
                    reader.Open(videoPath);
                }
                Bitmap bitMap = reader.ReadVideoFrame();
                //创建目录
                string dirPath = Path.GetDirectoryName(thumbImagePath);
                if (!Directory.Exists(dirPath))
                {
                    Directory.CreateDirectory(dirPath);
                }
                ImageHelper.CutForSquare(bitMap, thumbImagePath, thubWidth, thubQuality);
            }
            finally
            {
                reader.Dispose();
                reader.Close();
            }
        }
コード例 #7
0
 private static void OnMediaClosed(object sender, RoutedEventArgs e)
 {
     CommandManager.InvalidateRequerySuggested();
     InvalidateDif();
     videoReader.Close();
     videoReader.Dispose();
     videoReader = null;
     samples     = new short[0];
     sampleRate  = 1;
     UpdateWindowTitle();
 }
コード例 #8
0
ファイル: Video.cs プロジェクト: Aurbo99/vixen
 protected override void CleanUpRender()
 {
     _fp?.Dispose();
     _fp = null;
     if (_reader != null)
     {
         _reader.Close();
         _reader.Dispose();
         _reader = null;
     }
     _processVideo = true;
 }
コード例 #9
0
        private void GetThumbnailFromVideo()
        {
            VideoFileReader videoFileReader = new VideoFileReader();

            videoFileReader.Open(itemPath);
            Bitmap videoFrame     = videoFileReader.ReadVideoFrame();
            Image  myThumbnailImg = videoFrame.GetThumbnailImage(128, 72, () => { return(false); }, IntPtr.Zero);

            thumbnail = new Bitmap(myThumbnailImg);
            videoFrame.Dispose();
            myThumbnailImg.Dispose();
            videoFileReader.Dispose();
        }
コード例 #10
0
        // Méthode qui lit la vidéo et lance un algorithme de traitement
        public static void Initialisation(string path, List <Point> polygon_img)
        {
            polygon     = polygon_img;
            _FileReader = new VideoFileReader();
            Console.WriteLine("Motion Detector");
            Console.WriteLine("Threshold level: " + _motionAlarmLevel);
            _motionDetector = new MotionDetector(new TwoFramesDifferenceDetector(), new MotionAreaHighlighting());
            fileNameMovie   = Path.GetFileNameWithoutExtension(path);

            if (File.Exists(path))
            {
                if (!Directory.Exists("/MotionsVideo"))
                {
                    Directory.CreateDirectory("/MotionsVideo");
                }

                _FileReader.Open(path);
                //lecture de la vidéo image par image
                while (true)
                {
                    using (Bitmap videoFrame = _FileReader.ReadVideoFrame())
                    {
                        if (videoFrame == null)
                        {
                            break;
                        }
                        else
                        {
                            VideoSourcePlayer_NewFrame(videoFrame);
                        }
                    }
                }
                if (nbPicture >= 1)
                {
                    Console.WriteLine(DateTime.Now + ": Video stopped");
                    _FileWriter.Close();
                    _FileWriter.Dispose();
                    nbPicture = 0;
                    // TODO : la date réelle sur la video à mettre à la place de "00"
                    XMLManager.CreateXMLMotion("/Movie/" + fileNameMovie + ".xml", _volgnr, DateTime.Now, DateTime.Now, "00", "00");
                }
                _FileReader.Close();
                _FileReader.Dispose();
            }
        }
コード例 #11
0
        public void AnalyzeVideo(string videoPath)
        {
            if (busy)
            {
                return;
            }
            busy = true;
            Task.Run(async() =>
            {
                videoName = videoPath.Split('\\').ToList()[videoPath.Split('\\').ToList().Count() - 2];
                using (VideoFileReader reader = new VideoFileReader())
                {
                    reader.Open(videoPath);
                    try
                    {
                        int frameNumber   = 0;
                        Bitmap videoFrame = reader.ReadVideoFrame();
                        while (videoFrame != null)
                        {
                            progress = frameNumber + "/" + reader.FrameCount;

                            if (_SQLMananger.getFrame(videoName, frameNumber) == null)
                            {
                                var faces          = await UploadAndDetectFaces(videoFrame);
                                string resultAzure = JsonConvert.SerializeObject(faces);
                                _SQLMananger.saveFrame(videoName, frameNumber, resultAzure);
                            }
                            videoFrame = reader.ReadVideoFrame();
                            frameNumber++;
                        }
                        videoFrame.Dispose();
                        reader.Dispose();
                    }
                    catch (Exception e)
                    {
                        Console.Error.WriteLine("erreur dans  AnalyseVideoAsync : " + e.Message);
                    }
                }
                busy = false;
            });
        }
コード例 #12
0
ファイル: FFMPEGStream.cs プロジェクト: zemidf1/ispyconnect
        private void ShutDown(string errmsg)
        {
            bool err = !String.IsNullOrEmpty(errmsg);

            if (err)
            {
                _reasonToStop = ReasonToFinishPlaying.DeviceLost;
            }

            if (IsFileSource && !err)
            {
                _reasonToStop = ReasonToFinishPlaying.StoppedByUser;
            }

            if (_vfr != null && _vfr.IsOpen)
            {
                try
                {
                    _vfr.Dispose(); //calls close
                }
                catch (Exception ex)
                {
                    MainForm.LogExceptionToFile(ex, "FFMPEG");
                }
            }

            if (PlayingFinished != null)
            {
                PlayingFinished(this, _reasonToStop);
            }
            if (AudioFinished != null)
            {
                AudioFinished(this, _reasonToStop);
            }


            _stopEvent.Close();
            _stopEvent.Dispose();
            _stopEvent = null;
            _stopping  = false;
        }
コード例 #13
0
ファイル: AppForm.cs プロジェクト: Plugway/UVEA
        private static void OpenFileButtonHandler()
        {
            if (OpenFile.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            Reader.Close(); // close prev videos
            Reader.Dispose();
            Reader = new VideoFileReader();
            Writer.Close();
            Writer.Dispose();
            Writer = new VideoFileWriter();

            VideoName       = ("" + OpenFile.SafeFileName).Replace("" + Path.GetExtension(OpenFile.FileName), "");
            VideoPath       = Path.GetDirectoryName(OpenFile.FileName) + @"\";//задаем название и путь к файлу
            VideoExtension  = Path.GetExtension(OpenFile.FileName);
            ChosenFile.Text = OpenFile.FileName;

            Reader.Open(OpenFile.FileName);       //открываем файл

            Writer.BitRate    = Reader.BitRate;   //конфигурируем writer
            Writer.VideoCodec = VideoCodec.Mpeg4; //Reader videoCodec
            Writer.FrameRate  = Reader.FrameRate;
            Writer.Height     = Reader.Height;
            Writer.Width      = Reader.Width;
            Writer.Open(GetNameToSave(VideoPath, VideoName, VideoExtension));

            TimeLine.Value         = 0;                                                //настраиваем временную линию
            TimeLine.Maximum       = (int)Reader.FrameCount;
            TimeLine.TickFrequency = FastUtils.FastRoundInt((double)Reader.FrameRate);
            TimeLineEnd.Text       = TimeSpan.FromSeconds(Reader.FrameCount / (double)Reader.FrameRate).ToString(@"hh\:mm\:ss\.ff");

            Distorter.ResetMaxMinValues();
            DrawImage(PreviewPictureBox,                                                           //if enable start button? because multiplierFrom can be bad
                      Distorter.RunOneFrame(Reader, 0, MultiplierFrom, MultiplierTo, Function
                                            , PreviewPictureBox.Width, PreviewPictureBox.Height)); //рисуем 0 кадр

            EnableStartButton(StartButton, TimeLine);                                              //пробуем включить кнопку старт
        }
コード例 #14
0
        public List <ImageSource> GetFramesFromVideo(string fileName)
        {
            VideoFileReader reader = new VideoFileReader();

            reader.Open(fileName);

            FrameParser        parser      = new FrameParser();
            List <ImageSource> videoFrames = new List <ImageSource>();

            for (int i = 0; i < reader.FrameCount; i++)
            {
                Bitmap      videoFrame  = reader.ReadVideoFrame();
                ImageSource imageSource = parser.ImageSourceForBitmap(videoFrame);
                imageSource.Freeze();
                videoFrames.Add(imageSource);
                videoFrame.Dispose();
            }

            reader.Close();
            reader.Dispose();

            return(videoFrames);
        }
コード例 #15
0
        void bgWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker worker          = sender as BackgroundWorker;
            string           destinationPath = _saveFolder + @"\" + _subjectName + "_Process.avi";

            #region ReadProcessWriteVideo
            //Read video
            VideoFileReader _videoFileReader = new VideoFileReader();
            _videoFileReader.Open(_sourceVideoPath);
            if (_videoFileReader.IsOpen)
            {
                //Get Total Frames
                int totalFrames = (int)_videoFileReader.FrameCount;

                //DB Open
                DBExport _dbExport = new DBExport(_mainDir, _projectName, _subjectName);
                _dbExport.DBConnect();
                List <int> trackStartFrameID = _dbExport.GetAllPartTrackStartFrameID();

                //Delete File
                if (File.Exists(destinationPath))
                {
                    File.Delete(destinationPath);
                }

                //Intit Video Writer
                VideoFileWriter _videoFileWriter = new VideoFileWriter();
                _videoFileWriter.Open(destinationPath, _videoFileReader.Width, _videoFileReader.Height, _videoFileReader.FrameRate, (VideoCodec)_videoCodec, _videoFileReader.BitRate);

                int frameid = 0;
                while (true)
                {
                    Bitmap bitmap = _videoFileReader.ReadVideoFrame();
                    frameid++;
                    if (bitmap == null)
                    {
                        break;
                    }
                    Image <Bgra, Byte> frame = new Image <Bgra, Byte>(bitmap);

                    //Get Data
                    int startFrameID = _dbExport.CheckPartTrackStartFrameID(trackStartFrameID, frameid);
                    List <ExportTrackInfo> trackinfolist   = _dbExport.GetPartTrackFromDBWithFrameID(startFrameID, frameid);
                    ExportData             trackInfoScroll = _dbExport.CheckPartTrackScrollEvent(trackinfolist, _MexportVideoInfo.TrackType, _GexportVideoInfo.TrackType, _MexportVideoInfo.FixationRate, _GexportVideoInfo.FixationRate, _MexportVideoInfo.BrowserToolbarHeight, _GexportVideoInfo.BrowserToolbarHeight);

                    //Process Frames
                    #region Mouse
                    if (trackInfoScroll.mouseTracks != null)
                    {
                        if (trackInfoScroll.mouseTracks.Count >= 2 && _MexportVideoInfo.isTrackVisible)
                        {
                            //Track
                            frame.DrawPolyline(trackInfoScroll.mouseTracks.ToArray(), false, new Bgra(_MexportVideoInfo.TrackPenColor.B, _MexportVideoInfo.TrackPenColor.G, _MexportVideoInfo.TrackPenColor.R, _MexportVideoInfo.TrackPenColor.A), _MexportVideoInfo.TrackPenWidth);
                        }
                    }
                    if (_MexportVideoInfo.isFixationVisible && trackInfoScroll.mouseFixations != null)
                    {
                        if (trackInfoScroll.mouseFixations.Count > 0)
                        {
                            List <System.Drawing.Point> scanpath = new List <System.Drawing.Point>();
                            for (int i = 0; i < trackInfoScroll.mouseFixations.Count; i++)
                            {
                                //Fixation
                                frame.Draw(new CircleF(trackInfoScroll.mouseFixations[i].fixation, trackInfoScroll.mouseFixations[i].fsize), new Bgra(_MexportVideoInfo.FixationPenColor.B, _MexportVideoInfo.FixationPenColor.G, _MexportVideoInfo.FixationPenColor.R, _MexportVideoInfo.FixationPenColor.A), _MexportVideoInfo.FixationPenWidth);

                                scanpath.Add(trackInfoScroll.mouseFixations[i].fixation);
                                if (i >= 1 && _MexportVideoInfo.isPathVisible)
                                {
                                    //Path
                                    frame.DrawPolyline(scanpath.ToArray(), false, new Bgra(_MexportVideoInfo.PathPenColor.B, _MexportVideoInfo.PathPenColor.G, _MexportVideoInfo.PathPenColor.R, _MexportVideoInfo.PathPenColor.A), _MexportVideoInfo.PathPenWidth);
                                }

                                //Fixation ID
                                if (_MexportVideoInfo.isFixationIDVisible)
                                {
                                    drawText(frame, (i + 1).ToString(), trackInfoScroll.mouseFixations[i].fixation, _MexportVideoInfo.FixationIDPenColor);
                                }
                            }
                        }
                    }
                    #endregion
                    #region Gaze
                    if (trackInfoScroll.gazeTracks != null)
                    {
                        if (trackInfoScroll.gazeTracks.Count >= 2 && _GexportVideoInfo.isTrackVisible)
                        {
                            //Track
                            frame.DrawPolyline(trackInfoScroll.gazeTracks.ToArray(), false, new Bgra(_GexportVideoInfo.TrackPenColor.B, _GexportVideoInfo.TrackPenColor.G, _GexportVideoInfo.TrackPenColor.R, _GexportVideoInfo.TrackPenColor.A), _GexportVideoInfo.TrackPenWidth);
                        }
                    }
                    if (_GexportVideoInfo.isFixationVisible && trackInfoScroll.gazeFixations != null)
                    {
                        if (trackInfoScroll.gazeFixations.Count > 0)
                        {
                            List <System.Drawing.Point> scanpath = new List <System.Drawing.Point>();
                            for (int i = 0; i < trackInfoScroll.gazeFixations.Count; i++)
                            {
                                //Fixation
                                frame.Draw(new CircleF(trackInfoScroll.gazeFixations[i].fixation, trackInfoScroll.gazeFixations[i].fsize), new Bgra(_GexportVideoInfo.FixationPenColor.B, _GexportVideoInfo.FixationPenColor.G, _GexportVideoInfo.FixationPenColor.R, _GexportVideoInfo.FixationPenColor.A), _GexportVideoInfo.FixationPenWidth);

                                scanpath.Add(trackInfoScroll.gazeFixations[i].fixation);
                                if (i >= 1 && _GexportVideoInfo.isPathVisible)
                                {
                                    //Path
                                    frame.DrawPolyline(scanpath.ToArray(), false, new Bgra(_GexportVideoInfo.PathPenColor.B, _GexportVideoInfo.PathPenColor.G, _GexportVideoInfo.PathPenColor.R, _GexportVideoInfo.PathPenColor.A), _GexportVideoInfo.PathPenWidth);
                                }

                                //Fixation ID
                                if (_GexportVideoInfo.isFixationIDVisible)
                                {
                                    drawText(frame, (i + 1).ToString(), trackInfoScroll.gazeFixations[i].fixation, _GexportVideoInfo.FixationIDPenColor);
                                }
                            }
                        }
                    }
                    #endregion
                    #region Cursor
                    if (trackInfoScroll.mouseTracks != null && trackInfoScroll.mouseTracks.Count > 0 && _MexportVideoInfo.isCircleVisible)
                    {
                        //Circle
                        frame.Draw(new CircleF(trackInfoScroll.mouseTracks[trackInfoScroll.mouseTracks.Count - 1], 50), new Bgra(_MexportVideoInfo.CirclePenColor.B, _MexportVideoInfo.CirclePenColor.G, _MexportVideoInfo.CirclePenColor.R, _MexportVideoInfo.CirclePenColor.A), _MexportVideoInfo.CirclePenWidth);
                    }
                    if (trackInfoScroll.gazeTracks != null && trackInfoScroll.gazeTracks.Count > 0 && _GexportVideoInfo.isCircleVisible)
                    {
                        //Circle
                        frame.Draw(new CircleF(trackInfoScroll.gazeTracks[trackInfoScroll.gazeTracks.Count - 1], 50), new Bgra(_GexportVideoInfo.CirclePenColor.B, _GexportVideoInfo.CirclePenColor.G, _GexportVideoInfo.CirclePenColor.R, _GexportVideoInfo.CirclePenColor.A), _GexportVideoInfo.CirclePenWidth);
                    }
                    if (trackInfoScroll.mouseTracks != null && trackInfoScroll.mouseTracks.Count > 0 && _MexportVideoInfo.isCursorVisible)
                    {
                        System.Drawing.Point[] p  = new System.Drawing.Point[7];
                        System.Drawing.Point[] p2 = new System.Drawing.Point[6];
                        p[0] = new System.Drawing.Point(0 + trackInfoScroll.mouseTracks[trackInfoScroll.mouseTracks.Count - 1].X, 0 + trackInfoScroll.mouseTracks[trackInfoScroll.mouseTracks.Count - 1].Y);
                        p[1] = new System.Drawing.Point(0 + trackInfoScroll.mouseTracks[trackInfoScroll.mouseTracks.Count - 1].X, 23 + trackInfoScroll.mouseTracks[trackInfoScroll.mouseTracks.Count - 1].Y);
                        p[2] = new System.Drawing.Point(5 + trackInfoScroll.mouseTracks[trackInfoScroll.mouseTracks.Count - 1].X, 19 + trackInfoScroll.mouseTracks[trackInfoScroll.mouseTracks.Count - 1].Y);
                        p[3] = new System.Drawing.Point(8 + trackInfoScroll.mouseTracks[trackInfoScroll.mouseTracks.Count - 1].X, 26 + trackInfoScroll.mouseTracks[trackInfoScroll.mouseTracks.Count - 1].Y);
                        p[4] = new System.Drawing.Point(13 + trackInfoScroll.mouseTracks[trackInfoScroll.mouseTracks.Count - 1].X, 24 + trackInfoScroll.mouseTracks[trackInfoScroll.mouseTracks.Count - 1].Y);
                        p[5] = new System.Drawing.Point(10 + trackInfoScroll.mouseTracks[trackInfoScroll.mouseTracks.Count - 1].X, 18 + trackInfoScroll.mouseTracks[trackInfoScroll.mouseTracks.Count - 1].Y);
                        p[6] = new System.Drawing.Point(17 + trackInfoScroll.mouseTracks[trackInfoScroll.mouseTracks.Count - 1].X, 18 + trackInfoScroll.mouseTracks[trackInfoScroll.mouseTracks.Count - 1].Y);

                        p2[0] = new System.Drawing.Point(3 + trackInfoScroll.mouseTracks[trackInfoScroll.mouseTracks.Count - 1].X, 7 + trackInfoScroll.mouseTracks[trackInfoScroll.mouseTracks.Count - 1].Y);
                        p2[1] = new System.Drawing.Point(2 + trackInfoScroll.mouseTracks[trackInfoScroll.mouseTracks.Count - 1].X, 18 + trackInfoScroll.mouseTracks[trackInfoScroll.mouseTracks.Count - 1].Y);
                        p2[2] = new System.Drawing.Point(6 + trackInfoScroll.mouseTracks[trackInfoScroll.mouseTracks.Count - 1].X, 15 + trackInfoScroll.mouseTracks[trackInfoScroll.mouseTracks.Count - 1].Y);
                        p2[3] = new System.Drawing.Point(10 + trackInfoScroll.mouseTracks[trackInfoScroll.mouseTracks.Count - 1].X, 23 + trackInfoScroll.mouseTracks[trackInfoScroll.mouseTracks.Count - 1].Y);
                        p2[4] = new System.Drawing.Point(6 + trackInfoScroll.mouseTracks[trackInfoScroll.mouseTracks.Count - 1].X, 15 + trackInfoScroll.mouseTracks[trackInfoScroll.mouseTracks.Count - 1].Y);
                        p2[5] = new System.Drawing.Point(12 + trackInfoScroll.mouseTracks[trackInfoScroll.mouseTracks.Count - 1].X, 16 + trackInfoScroll.mouseTracks[trackInfoScroll.mouseTracks.Count - 1].Y);

                        frame.DrawPolyline(p2, true, new Bgra(255, 255, 255, 255), 3);
                        frame.DrawPolyline(p, true, new Bgra(0, 0, 0, 255), 2);
                    }
                    if (trackInfoScroll.gazeTracks != null && trackInfoScroll.gazeTracks.Count > 0 && _GexportVideoInfo.isCursorVisible)
                    {
                        frame.Draw(new CircleF(trackInfoScroll.gazeTracks[trackInfoScroll.gazeTracks.Count - 1], 12), new Bgra(255, 255, 255, 255), -1);
                        frame.Draw(new CircleF(trackInfoScroll.gazeTracks[trackInfoScroll.gazeTracks.Count - 1], 12), new Bgra(0, 0, 0, 255), 2);
                        frame.Draw(new CircleF(trackInfoScroll.gazeTracks[trackInfoScroll.gazeTracks.Count - 1], 5), new Bgra(0, 0, 0, 255), -1);
                    }
                    #endregion

                    //Write Video
                    _videoFileWriter.WriteVideoFrame(frame.ToBitmap());

                    //clear
                    bitmap.Dispose();
                    bitmap = null;
                    frame.Dispose();
                    frame = null;

                    //Updata Processbar
                    if (worker.CancellationPending || _closePending)
                    {
                        //clear
                        if (_videoFileWriter != null)
                        {
                            _videoFileWriter.Close();
                            _videoFileWriter.Dispose();
                            _videoFileWriter = null;
                        }
                        if (_videoFileReader != null)
                        {
                            _videoFileReader.Close();
                            _videoFileReader.Dispose();
                            _videoFileReader = null;
                        }
                        if (_dbExport != null)
                        {
                            _dbExport.DBDisconnect();
                            _dbExport = null;
                        }
                        if (bitmap != null)
                        {
                            bitmap.Dispose();
                            bitmap = null;
                        }
                        if (frame != null)
                        {
                            frame.Dispose();
                            frame = null;
                        }

                        e.Cancel = true;
                        break;
                    }
                    else
                    {
                        worker.ReportProgress(100 * frameid / totalFrames);
                        //System.Threading.Thread.Sleep(10);
                    }
                }
                //clear
                if (_videoFileWriter != null)
                {
                    _videoFileWriter.Close();
                    _videoFileWriter.Dispose();
                    _videoFileWriter = null;
                }
                if (_videoFileReader != null)
                {
                    _videoFileReader.Close();
                    _videoFileReader.Dispose();
                    _videoFileReader = null;
                }
                if (_dbExport != null)
                {
                    _dbExport.DBDisconnect();
                    _dbExport = null;
                }
            }
            #endregion
        }
コード例 #16
0
ファイル: Form1.cs プロジェクト: ibrhmckc/nesne-takip-client
        private void button2_Click(object sender, EventArgs e)
        {
            FileStream dosyamiz;
            StreamReader okuma;
            string yol = "C:\\manual_Jogging1.txt";

            dosyamiz = new FileStream(yol, FileMode.Open, FileAccess.Read);
            okuma = new StreamReader(dosyamiz);

            int n, a, b, c, d;
            int x1, x2, x3, x4;
            double xgec;

            System.Drawing.Graphics graphicsObj;

            graphicsObj = this.CreateGraphics();

            Pen myPen = new Pen(System.Drawing.Color.Red, 1);

            VideoFileReader reader = new VideoFileReader();
            IWMPMedia saniye = axWindowsMediaPlayer1.newMedia(ofVideoYukle.FileName);

            if (fbdFramePath.ShowDialog() != System.Windows.Forms.DialogResult.OK)
            {
                MessageBox.Show("Klasör seçilmedi");
            }

            string str_FramePath = fbdFramePath.SelectedPath + @"\";
            reader.Open(ofVideoYukle.FileName);
            this.TotalFrame = (int)saniye.duration * reader.FrameRate;
            this.Videofps = reader.FrameRate;
            for (int i = 0; i < 307; i++)
            {

                textBox1.Text = okuma.ReadLine();
                textBox2.Text = textBox1.Text.Replace("		", "");

                n = Convert.ToInt32(textBox2.Text.Substring(0, 1));
                a = Convert.ToInt32(textBox2.Text.Substring(1, 3));
                b = Convert.ToInt32(textBox2.Text.Substring(4, 3));
                c = Convert.ToInt32(textBox2.Text.Substring(7, 2));
                d = Convert.ToInt32(textBox2.Text.Substring(9, 2));

                if (i > 9)
                {
                    if (i == 48 || i == 49 || i == 50 || i == 51 || i == 52 || i == 53 || i == 54 || i == 55)
                    {
                        n = Convert.ToInt32(textBox2.Text.Substring(0, 2));
                        a = Convert.ToInt32(textBox2.Text.Substring(2, 2));
                        b = Convert.ToInt32(textBox2.Text.Substring(4, 3));
                        c = Convert.ToInt32(textBox2.Text.Substring(7, 2));
                        d = Convert.ToInt32(textBox2.Text.Substring(9, 2));
                    }

                    else
                    {
                        n = Convert.ToInt32(textBox2.Text.Substring(0, 2));
                        a = Convert.ToInt32(textBox2.Text.Substring(2, 3));
                        b = Convert.ToInt32(textBox2.Text.Substring(5, 3));
                        c = Convert.ToInt32(textBox2.Text.Substring(8, 2));
                        d = Convert.ToInt32(textBox2.Text.Substring(10, 2));
                    }

                }

                if (i > 99)
                {
                    n = Convert.ToInt32(textBox2.Text.Substring(0, 3));
                    a = Convert.ToInt32(textBox2.Text.Substring(3, 3));
                    b = Convert.ToInt32(textBox2.Text.Substring(6, 3));
                    c = Convert.ToInt32(textBox2.Text.Substring(9, 2));
                    d = Convert.ToInt32(textBox2.Text.Substring(11, 2));

                }

                x1 = a - c;
                x2 = b - ((3 * d) / 2);
                x3 = 2 * c;
                xgec = (Math.Sqrt(Math.Pow(c, 2) + Math.Pow(d, 2))) * 3;
                x4 = Convert.ToInt32(xgec);

                Rectangle myRectangle = new Rectangle(x1, x2, x3, x4);
                Bitmap videoFrame = reader.ReadVideoFrame();

                using (Graphics grafik = Graphics.FromImage(videoFrame as Image))
                {

                    grafik.DrawEllipse(myPen, myRectangle);

                }

                videoFrame.Save(str_FramePath + "Image" + i + ".jpg");
                videoFrame.Dispose();
            }

            reader.Close();
            reader.Dispose();
            MessageBox.Show("Video Frame lere ayrildi");
            button4.Enabled = true;
        }
コード例 #17
0
 public void Unload()
 {
     reader.Close();
     reader.Dispose();
     videoLoaded = false;
 }
コード例 #18
0
 protected override void OnClosing(CancelEventArgs e)
 {
     base.OnClosing(e);
     videoFileReader?.Dispose();
 }
コード例 #19
0
ファイル: PictureGiver.cs プロジェクト: SeryMa/FlyCatcher
 public void Dispose() => reader.Dispose();
コード例 #20
0
 public void CloseVideoReader()
 {
     _videoFileReader.Close();
     _videoFileReader.Dispose();
 }
コード例 #21
0
 public void Dispose()
 {
     UnderlyingReader.Dispose();
 }
コード例 #22
0
ファイル: Video.cs プロジェクト: Aurbo99/vixen
        private void ProcessMovie(string folder)
        {
            //Delete old path and create new path for processed video
            if (Directory.Exists(_data.Video_DataPath))
            {
                Directory.Delete(folder, true);
            }
            _data.Video_DataPath = Path.Combine(_tempPath, Guid.NewGuid().ToString());
            Directory.CreateDirectory(_data.Video_DataPath);

            string videoFilename = Path.Combine(_videoPath, _data.FileName);

            try
            {
                _reader = new VideoFileReader();
                _reader.Open(videoFilename);
                var    count         = _reader.FrameCount;
                var    videoTimespan = TimeSpan.FromSeconds(count / _reader.FrameRate.Value);
                var    frameScale    = _reader.FrameRate.Value / 20;
                int    renderHeight;
                int    renderWidth;
                string cropVideo = "";

                if (StretchToGrid)                 // Will stretch the image to the grid size.
                {
                    renderWidth  = BufferWi;
                    renderHeight = BufferHt;
                }
                else
                {
                    // Will scaled the image to the grid size.
                    GetNewImageSize(out renderWidth, out renderHeight, BufferWi, BufferHt);
                    if (!ScaleToGrid)                     // Scale and crop the image based on users scale setting
                    {
                        renderWidth  = (int)(renderWidth * ((double)ScalePercent / 100 + 1));
                        renderHeight = (int)(renderHeight * ((double)ScalePercent / 100 + 1));
                        int cropWidth  = Math.Min(renderWidth, BufferWi);
                        int cropHeight = Math.Min(renderHeight, BufferHt);
                        cropVideo = $", crop={cropWidth}:{cropHeight}:{renderWidth - cropWidth / 2}:{renderHeight - cropHeight / 2}";
                    }
                }

                // Will adjust the render size if element is below 10 as FFMPEG could refuse to scale.
                if (renderHeight < 10 || renderWidth < 10)
                {
                    // I don't see any point continuing if the element is this small.
                    if (renderHeight <= 2 || renderWidth <= 2)
                    {
                        _videoFileDetected = false;
                        return;
                    }
                    GetNewImageSize(out renderWidth, out renderHeight, 50, (int)(50 * ((double)renderWidth / renderHeight)));
                }

                _reader.Close();
                _reader.Dispose();

                VideoLength = (int)videoTimespan.TotalSeconds;
                // Gets selected video if Video length is longer then the entered start time.
                if (VideoLength > StartTimeSeconds + (TimeSpan.TotalSeconds * ((double)PlayBackSpeed / 100 + 1)))
                {
                    ffmpeg.ffmpeg converter = new ffmpeg.ffmpeg(videoFilename);
                    _currentMovieImageNum = 0;
                    // Height and Width needs to be evenly divisible to work or ffmpeg complains.
                    if (renderHeight % 2 != 0)
                    {
                        renderHeight++;
                    }
                    if (renderWidth % 2 != 0)
                    {
                        renderWidth++;
                    }
                    converter.MakeScaledVideo(_data.Video_DataPath, StartTimeSeconds, ((TimeSpan.TotalSeconds * ((double)PlayBackSpeed / 100 + 1))),
                                              renderWidth, renderHeight, frameScale, MaintainAspect, 20, RotateVideo, cropVideo);
                    _videoFileDetected = true;
                }
                else
                {
                    MessageBoxForm.msgIcon = SystemIcons.Error;                     // This is used if you want to add a system icon to the message form.
                    var messageBox = new MessageBoxForm("Entered Start Time plus Effect length is greater than the Video Length of " + _data.FileName,
                                                        "Invalid Start Time. Decrease the Start Time", MessageBoxButtons.OK, SystemIcons.Error);
                    messageBox.ShowDialog();
                    _videoFileDetected = false;
                }
            }
            catch (Exception ex)
            {
                var messageBox = new MessageBoxForm("There was a problem converting " + videoFilename + ": " + ex.Message,
                                                    "Error Converting Video", MessageBoxButtons.OK, SystemIcons.Error);
                messageBox.ShowDialog();
                _videoFileDetected = false;
            }
        }
コード例 #23
0
        // aka Get Random Object Images and Unique People Images
        private (List <Bitmap>, List <Bitmap>) AnalyzeVideo()
        {
            const int randomImgCount = 30;

            var objCount   = analysis.frames.Select(f => f.objs.Count).Sum();
            var randImgIds = new HashSet <int>();

            while (randImgIds.Count < randomImgCount)
            {
                var id = random.Next(objCount);
                randImgIds.Add(id);
            }

            var uniquePersonRects = GetUniquePersonRects();
            var uniquePersonImgs  = new List <Bitmap>();

            var reader = new VideoFileReader();

            reader.Open(videoFilepath);

            var randomObjectImgs = new List <Bitmap>();

            int currentId  = 0;
            var framecount = reader.FrameCount;

            for (int i = 0; i < framecount; i++)
            {
                if (i % 10 == 0)
                {
                    Console.WriteLine($"frame {i + 1}/{framecount} ({(i + 1) / (double)framecount:P2})");
                }

                var frame = reader.ReadVideoFrame(i);

                foreach (var uniquePersonRect in uniquePersonRects)
                {
                    if (uniquePersonRects.Count == uniquePersonImgs.Count)
                    {
                        break;
                    }

                    if (uniquePersonRect.Item1 == i)
                    {
                        var rect = uniquePersonRect.Item2;
                        var upi  = Util.Subregion(frame, rect[0], rect[1], rect[2], rect[3]);

                        uniquePersonImgs.Add(upi);
                    }
                }

                foreach (var obj in analysis.frames[i].objs)
                {
                    if (randomObjectImgs.Count == randImgIds.Count)
                    {
                        break;
                    }

                    if (randImgIds.Contains(currentId))
                    {
                        var img = Util.Subregion(frame, obj.rect[0], obj.rect[1], obj.rect[2], obj.rect[3]);
                        randomObjectImgs.Add(img);
                    }

                    currentId++;
                }

                if (randomObjectImgs.Count == randImgIds.Count && uniquePersonRects.Count == uniquePersonImgs.Count)
                {
                    break;
                }

                frame.Dispose();
            }

            reader.Dispose();

            uniquePersonImgs.Shuffle(random);
            randomObjectImgs.Shuffle(random);

            return(randomObjectImgs, uniquePersonImgs);
        }
コード例 #24
0
        public void AnalyzeVideo(string videoPath, string saveDirectory = null)
        {
            Task.Run(() =>
            {
                if (busy)
                {
                    return;
                }

                busy = true;
                if (saveDirectory == null)
                {
                    saveDirectory = Assembly.GetEntryAssembly().Location.Remove(Assembly.GetEntryAssembly().Location.LastIndexOf('\\'));
                }
                string videoName = videoPath.Split('\\').ToList()[videoPath.Split('\\').ToList().Count() - 2];
                using (VideoFileReader reader = new VideoFileReader())
                {
                    reader.Open(videoPath);
                    try
                    {
                        Bitmap videoFrame = reader.ReadVideoFrame();


                        int frameNumber = 1;
                        while (videoFrame != null)
                        {
                            progress = frameNumber + "/" + reader.FrameCount;
                            using (Image <Gray, Byte> normalizedMasterImage = new Image <Gray, Byte>(videoFrame))
                            {
                                //c'est sur ce block que ce fait la reconnaissance facial
                                Rectangle[] faces   = FindFaces(videoFrame);
                                Rectangle[] eyes    = null;
                                string notification = "";
                                try
                                {
                                    using (Bitmap target = new Bitmap(faces[0].Width, faces[0].Height))
                                    {
                                        using (Graphics g = Graphics.FromImage(target))
                                        {
                                            g.DrawImage(videoFrame, new Rectangle(0, 0, target.Width, target.Height),
                                                        faces[0],
                                                        GraphicsUnit.Pixel);
                                        }
                                        eyes = FindEyes(target);
                                        if (eyes != null)
                                        {
                                            for (int i = 0; i < eyes.Length; i++)
                                            {
                                                eyes[i].X += faces[0].X;
                                                eyes[i].Y += faces[0].Y;
                                            }
                                        }
                                    }
                                }
                                catch (Exception e)
                                {
                                    Console.Error.WriteLine("erreur dans  AnalyseVideoAsync : " + e.Message);
                                }
                                notification = JsonConvert.SerializeObject(new
                                {
                                    faces,
                                    eyes
                                });
                                orderedNotification.Add(frameNumber, notification);
                            }
                            videoFrame = reader.ReadVideoFrame();
                            frameNumber++;
                        }
                        videoFrame.Dispose();
                        reader.Dispose();
                    }
                    catch (Exception e)
                    {
                        Console.Error.WriteLine("erreur dans  AnalyseVideoAsync : " + e.Message);
                    }
                }
                busy = false;
            });
        }
コード例 #25
0
ファイル: VideoSource.cs プロジェクト: WildGenie/ispyconnect
        private void btnTest_Click(object sender, EventArgs e)
        {
            btnTest.Enabled = false;
            string res = "OK";
            try
            {
                Program.FFMPEGMutex.WaitOne();
                string source = cmbFile.Text;
                var vfr= new VideoFileReader();

                int i = source.IndexOf("://", StringComparison.Ordinal);
                if (i > -1)
                {
                    source = source.Substring(0, i).ToLower() + source.Substring(i);
                }

                vfr.Timeout = CameraControl.Camobject.settings.timeout;
                vfr.AnalyzeDuration = (int)numAnalyseDuration.Value;
                vfr.Cookies = CameraControl.Camobject.settings.cookies;
                vfr.UserAgent = CameraControl.Camobject.settings.useragent;
                vfr.Headers = CameraControl.Camobject.settings.headers;
                vfr.RTSPMode = ddlRTSP.SelectedIndex;
                vfr.Flags = -1;
                vfr.NoBuffer = true;
                vfr.Open(source);
                vfr.ReadFrame();
                vfr.Dispose();

            }
            catch (Exception ex)
            {
                res = ex.Message;
            }
            finally
            {
                try
                {
                    Program.FFMPEGMutex.ReleaseMutex();
                }
                catch (ObjectDisposedException)
                {
                    //can happen on shutdown
                }
            }

            MessageBox.Show(res);
            btnTest.Enabled = true;
        }
コード例 #26
0
        private void button2_Click(object sender, EventArgs e)
        {
            FileStream   dosyamiz;
            StreamReader okuma;
            string       yol = "C:\\manual_Jogging1.txt";

            dosyamiz = new FileStream(yol, FileMode.Open, FileAccess.Read);
            okuma    = new StreamReader(dosyamiz);

            int    n, a, b, c, d;
            int    x1, x2, x3, x4;
            double xgec;

            System.Drawing.Graphics graphicsObj;

            graphicsObj = this.CreateGraphics();

            Pen myPen = new Pen(System.Drawing.Color.Red, 1);



            VideoFileReader reader = new VideoFileReader();
            IWMPMedia       saniye = axWindowsMediaPlayer1.newMedia(ofVideoYukle.FileName);

            if (fbdFramePath.ShowDialog() != System.Windows.Forms.DialogResult.OK)
            {
                MessageBox.Show("Klasör seçilmedi");
            }

            string str_FramePath = fbdFramePath.SelectedPath + @"\";

            reader.Open(ofVideoYukle.FileName);
            this.TotalFrame = (int)saniye.duration * reader.FrameRate;
            this.Videofps   = reader.FrameRate;
            for (int i = 0; i < 307; i++)
            {
                textBox1.Text = okuma.ReadLine();
                textBox2.Text = textBox1.Text.Replace("		", "");

                n = Convert.ToInt32(textBox2.Text.Substring(0, 1));
                a = Convert.ToInt32(textBox2.Text.Substring(1, 3));
                b = Convert.ToInt32(textBox2.Text.Substring(4, 3));
                c = Convert.ToInt32(textBox2.Text.Substring(7, 2));
                d = Convert.ToInt32(textBox2.Text.Substring(9, 2));

                if (i > 9)
                {
                    if (i == 48 || i == 49 || i == 50 || i == 51 || i == 52 || i == 53 || i == 54 || i == 55)
                    {
                        n = Convert.ToInt32(textBox2.Text.Substring(0, 2));
                        a = Convert.ToInt32(textBox2.Text.Substring(2, 2));
                        b = Convert.ToInt32(textBox2.Text.Substring(4, 3));
                        c = Convert.ToInt32(textBox2.Text.Substring(7, 2));
                        d = Convert.ToInt32(textBox2.Text.Substring(9, 2));
                    }

                    else
                    {
                        n = Convert.ToInt32(textBox2.Text.Substring(0, 2));
                        a = Convert.ToInt32(textBox2.Text.Substring(2, 3));
                        b = Convert.ToInt32(textBox2.Text.Substring(5, 3));
                        c = Convert.ToInt32(textBox2.Text.Substring(8, 2));
                        d = Convert.ToInt32(textBox2.Text.Substring(10, 2));
                    }
                }

                if (i > 99)
                {
                    n = Convert.ToInt32(textBox2.Text.Substring(0, 3));
                    a = Convert.ToInt32(textBox2.Text.Substring(3, 3));
                    b = Convert.ToInt32(textBox2.Text.Substring(6, 3));
                    c = Convert.ToInt32(textBox2.Text.Substring(9, 2));
                    d = Convert.ToInt32(textBox2.Text.Substring(11, 2));
                }

                x1   = a - c;
                x2   = b - ((3 * d) / 2);
                x3   = 2 * c;
                xgec = (Math.Sqrt(Math.Pow(c, 2) + Math.Pow(d, 2))) * 3;
                x4   = Convert.ToInt32(xgec);


                Rectangle myRectangle = new Rectangle(x1, x2, x3, x4);
                Bitmap    videoFrame  = reader.ReadVideoFrame();


                using (Graphics grafik = Graphics.FromImage(videoFrame as Image))
                {
                    grafik.DrawEllipse(myPen, myRectangle);
                }


                videoFrame.Save(str_FramePath + "Image" + i + ".jpg");
                videoFrame.Dispose();
            }

            reader.Close();
            reader.Dispose();
            MessageBox.Show("Video Frame lere ayrildi");
            button4.Enabled = true;
        }
コード例 #27
0
 public void Dispose()
 {
     reader.Dispose();
 }