GetCaptureProperty() публичный Метод

Obtain the capture property
public GetCaptureProperty ( CvEnum index ) : double
index CvEnum The index for the property
Результат double
        public void write() {
            int codec = Emgu.CV.CvInvoke.CV_FOURCC('P', 'I', 'M', '1');

            int fps = 25;
            if (list_timestamps.Count > 0)
            {
                String tempvideopath = Program.getConfiguration().Mediafolderpath + @"\" + list_timestamps[0].ToString() + ".mpg";
                Capture tempcapture = new Capture(tempvideopath);
                fps = (int)tempcapture.GetCaptureProperty(CAP_PROP.CV_CAP_PROP_FPS);
                tempcapture.Dispose();
            }

            VideoWriter videowriter = new VideoWriter(videopath, codec, fps, 640, 480, true);
            

            for (int i = 0; i < list_timestamps.Count; i++)
            {
                videopath = Program.getConfiguration().Mediafolderpath + @"\" + list_timestamps[i].ToString() + ".mpg";
                try
                {
                    Capture joincapture = new Capture(videopath);
                    Image<Bgr, byte> frame = joincapture.QueryFrame();
                    for (int n = 1; n < 15; n++)
                        joincapture.QueryFrame();

                    while (frame != null)
                    {
                        videowriter.WriteFrame(frame);
                        frame = joincapture.QueryFrame();
                    }
                    joincapture.Dispose();

                    // Notify main frame to update its progressbar
                    ExportVideoProgressEventArgs e = new ExportVideoProgressEventArgs(i);
                    DoneAppendingRallyVideoEvent(this, e);
                }
                catch (NullReferenceException) { Console.WriteLine("unreadable video file"); }
            }
            videowriter.Dispose();
        
        }
Пример #2
0
        private void CameraInit(int cameraIndex)
        {
            var camera = _cameras[cameraIndex];

            _capture      = new Capture(cameraIndex);
            _cameraDevice = cameraIndex;

            var w = _capture.GetCaptureProperty(CapProp.FrameWidth);
            var h = _capture.GetCaptureProperty(CapProp.FrameHeight);

            var currentResolution = w + "x" + h;

            var resolutions = VideoDeviceManager.GetAllAvailableResolution(camera).OrderByDescending(x => x.Width).ThenByDescending(x => x.Height).ToList();

            resolutionsList.Items.Clear();
            var strings = resolutions.Select(x => x.Width + "x" + x.Height).Distinct().ToList();
            var index   = -1;

            for (int i = 0; i < strings.Count; i++)
            {
                resolutionsList.Items.Add(strings[i]);
                if (strings[i].Equals(currentResolution))
                {
                    index = i;
                }
            }
            resolutionsList.SelectedIndex = index;
        }
Пример #3
0
		public void Initialise(string filename)
		{
			Close();
			try
			{
				_Capture = new Capture(filename); //create a video player
				FCaptureFPS = _Capture.GetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FPS);
				Length = _Capture.GetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FRAME_COUNT) / FCaptureFPS;
				FCapturePeriod = (int)(1000.0d / FCaptureFPS);
			}
			catch
			{
				_Status = "Player open failed";
				return;
			}

			_Status = "Player open success";
			HasCapture = true;

			Image.FrameAttributesChanged = true;

			Filename = filename;
			CaptureThreadRun = true;
			CaptureThread = new Thread(fnCapture);
			CaptureThread.Start();
		}
Пример #4
0
    static void Main(string[] args)
    {
      navigationMatrix = new Matrix3D();
      navigationMatrix.Translate(new Vector3D(0, 100, 110));
      navigationMatrix.Scale(new Vector3D((double)1 / 5, (double)1 / 5, (double)1 / 5));

      displayProfile = new Bin[Bin.RANGEL, Bin.RANGEA, Bin.RANGEB];
      for (int l = 0; l < Bin.RANGEL; l++)
        for (int a = 0; a < Bin.RANGEA; a++)
          for (int b = 0; b < Bin.RANGEB; b++)
            displayProfile[l, a, b] = new Bin(l, a, b);

      PopulateProfile(displayProfile, navigationMatrix);

      String path = Environment.CurrentDirectory + PATH_TO_VIDEO;
      if (!System.IO.File.Exists(path))
        return;


      //Opens the movie file
      capture = new Capture(path);
      double fps = capture.GetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FPS);

      //Reads frame by frame
      Timer timer = new Timer(1000 / fps);
      timer.Elapsed += new ElapsedEventHandler(timer_Elapsed);
      timer.Start();

      Console.Read();
    }
Пример #5
0
 private void frameProcessing()
 {
     _capture = new Capture(_file);
     totalFrameCount = _capture.GetCaptureProperty(Emgu.CV.CvEnum.CapProp.FrameCount);
     progressBar1.Maximum = (int)totalFrameCount;
     timer.Start();
     _capture.ImageGrabbed += ProcessFrame;
     if (timer.ElapsedMilliseconds == 1000) _capture.Stop();
 }
Пример #6
0
        static void Main(string[] args)
        {
            /* One File
            string desktop = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
            string workingDir = @"E:\REDID\vids";//Path.Combine(desktop, "test", "Dancing_Resized");
            string videoName = "pos_030.avi";
            */

            string workingDir = @"C:\Users\Paolo\Desktop\crowd_results\New folder";
            string outDir = @"C:\Users\Paolo\Desktop\crowd_results";
            int maxFrames = 1000;
            string[] files = Directory.GetFiles(workingDir, "*.avi");
            foreach (string f in files)
            {
                string filename = Path.GetFileName(f);
                string outDirFile = Path.Combine(outDir, filename.Remove(filename.Length - 4));

                if (!Directory.Exists(outDirFile))
                    Directory.CreateDirectory(outDirFile);
                else
                {
                    Console.WriteLine("Directory already exists! OVERWRITE?");
                    if ( Console.ReadKey().Key == ConsoleKey.Y)
                    {
                        Directory.Delete(outDirFile, true);
                        CvInvoke.cvWaitKey(100);
                    }
                    else
                        Environment.Exit(1);
                }

                Capture cap = new Capture(f);
                string rootFile = Path.GetFileName(f);
                rootFile = rootFile.Remove(rootFile.Length - 4);
                int totFrames = (int)cap.GetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FRAME_COUNT);
                if (totFrames > maxFrames && maxFrames != 0)
                    totFrames = maxFrames;
                Console.WriteLine("FILE {0}: {1} frames", rootFile, totFrames);
                StreamWriter sw1 = new StreamWriter(Path.Combine(outDirFile, "imageList.txt"));
                for (int frameNumber = 1; frameNumber < totFrames; frameNumber++)
                {
                    IMG currentFrame = cap.QueryFrame();
                    if (currentFrame == null)
                        continue;

                    string fileOut = string.Format("{0}_{1}.jpg", rootFile, frameNumber.ToString("D8"));
                    currentFrame.Save(Path.Combine(outDirFile, fileOut));
                    sw1.Write(fileOut + '\n');
                    if (frameNumber % 100 == 0)
                        Console.WriteLine("Frame {0} written...", frameNumber);

                }
                sw1.Dispose();
            }
        }
Пример #7
0
        public CameraBL()
        {
            try
            {
                // check if all libraries were loaded
                if (DependencyCheck.Execute())
                {
                    // init grabber
                    this.grabber = new Capture();

                    // get current height and width
                    this.FrameWidth = grabber.GetCaptureProperty(CAP_PROP.CV_CAP_PROP_FRAME_WIDTH);
                    this.FrameHeight = grabber.GetCaptureProperty(CAP_PROP.CV_CAP_PROP_FRAME_HEIGHT);
                }
            }
            catch (NullReferenceException)
            {
                this.IsCameraAvailable = false;
            }
        }
Пример #8
0
        //filename: Catch image from video file
        //ms: Capture every ms. ms = 0 means capture all frames. (24 frames per second)
        public List<string> CatchImages(string fileName, int ms, string outputPath)
        {
            _log.Debug("Start to capture");
            if (string.IsNullOrWhiteSpace(fileName) || string.IsNullOrWhiteSpace(outputPath))
            {
                _log.Error("Cannot catch images from path: " + fileName + " and output to: " + outputPath);
            }
            //List<Image<Bgr, Byte>> imageList = new List<Image<Bgr, Byte>>();
            List<string> imagePath = new List<string>();
            Capture capture = new Capture(fileName);

            double frameCount = capture.GetCaptureProperty(CapProp.FrameCount);
            capture.Dispose();

            int index = 0;
            int fc = (int)frameCount;
            Mat mat = null;
            try
            {
                //TODO: Modified this to change period of capture image.
                while (index < 30/*fc*/)
                {
                    index++;
                    using (capture = new Capture(fileName))
                    {
                        capture.SetCaptureProperty(CapProp.PosFrames, (double)index);

                        using (mat = capture.QueryFrame())
                        {
                            string indexStr = index < 10 ? "0" + index : index.ToString();
                            string imgPath = outputPath + "\\" + indexStr;
                            if (!Directory.Exists(outputPath))
                            {
                                Directory.CreateDirectory(outputPath);
                            }
                            //long quality = 60;
                            //saveJpeg(imgPath, mat.Bitmap, quality);
                            string grayImgName = saveGrayAndThreshold(imgPath, mat.Bitmap);
                            if (!string.IsNullOrEmpty(grayImgName))
                            {
                                imagePath.Add(grayImgName);
                            }
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                _log.Error("Exception:", ex);
            }

            return imagePath;
        }
Пример #9
0
        /// <summary>
        /// Access device property or use default value
        /// </summary>
        /// <param name="prop"> property name</param>
        /// <param name="def">default to use if not connected</param>
        /// <returns>value or default</returns>
        double GetPropertyOrDefault(Emgu.CV.CvEnum.CAP_PROP prop, double def)
        {
            double value = def;

            lock (this) {
                if (IsConnected)
                {
                    value = _device.GetCaptureProperty(prop);
                }
            }
            return(value);
        }
Пример #10
0
        public SalmonCounter()
        {
            InitializeComponent();
            _capture = new Capture(videoOne);

            counter = new Counter(_capture.Width);

            bImage = new BlobImage();
            fgDetector = new ForegroundDetector(bImage);
            sTracker = new SalmonTracker(bImage, counter);

            watch = new Stopwatch();
            time = new TimeSpan();

            FPS = (int)_capture.GetCaptureProperty(Emgu.CV.CvEnum.CapProp.Fps);
            frameCount = (int)_capture.GetCaptureProperty(Emgu.CV.CvEnum.CapProp.FrameCount);
            pictureBox1.Width = _capture.Width;
            pictureBox1.Height = _capture.Height;

            show.Width = _capture.Width;
            show.Height = _capture.Height;

            //msec between frames
            msec = (int)(1000 / FPS);

            //set the event handler
            _capture.ImageGrabbed += grabImage;
            _capture.Start();
            watch.Start();
            _frame = new Mat();

            //Start foregroundSegmenter tread and salmon tracker thread
            backgroundSubtractorThread = new Thread(fgDetector.detect);
            backgroundSubtractorThread.Start();
            sTrackerThread = new Thread(sTracker.updateSalmons);
            sTrackerThread.Start();
        }
Пример #11
0
        public faceTrack()
        {
            InitializeComponent();

            CvInvoke.UseOpenCL = false;

            _cascadeClassifierFace = new CascadeClassifier(Application.StartupPath + "/haarcascade_frontalface_default.xml");
            _cascadeClassifierEye = new CascadeClassifier(Application.StartupPath + "/haarcascade_eye.xml");

            try
            {
                capturecam = new Capture(0);
                capturecam.SetCaptureProperty(CapProp.Fps, 30);
                capturecam.SetCaptureProperty(CapProp.FrameHeight, 240);
                capturecam.SetCaptureProperty(CapProp.FrameWidth, 320);
                capturecam.SetCaptureProperty(CapProp.AutoExposure, 1);

                trackBarUpdate(trackBarContrast, (int)capturecam.GetCaptureProperty(CapProp.Contrast));
                trackBarUpdate(trackBarBrightness, (int)capturecam.GetCaptureProperty(CapProp.Brightness));
                //trackBarUpdate(trackBarGain, (int)capturecam.GetCaptureProperty(CapProp.Gain));
                trackBarUpdate(trackBarZoom, (int)capturecam.GetCaptureProperty(CapProp.Zoom));

                textBoxTime.Text = "Time: ";
                textBoxCodec.Text = "Codec: ";
                textBoxFrameRate.Text = "Frame: ";

                capturecam.ImageGrabbed += ProcessFrame;
                //Application.Idle += ProcessFrame;

                //original.Image = capturecam.QueryFrame();
            }
            catch (NullReferenceException excpt)
            {
                MessageBox.Show(excpt.Message);
            }
        }
Пример #12
0
        private void ClickCameraButton(object sender, EventArgs e)
        {
            ClearTimer();

            try
            {
                _capture = new Capture(0);
                double fps = _capture.GetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FPS);
                _cameraTimer.Interval = Convert.ToInt16(1);
                _cameraTimer.Tick += TickCameraTimer;
                _cameraTimer.Start();
            }
            catch (Exception)
            {
                MessageBox.Show("無法找到攝影機,請確定是否有連接");
            }
        }
Пример #13
0
        public Form1()
        {
            InitializeComponent();

            markedPoints = new Dictionary<string, Point[]>();

            try
            {
                capture = new Capture("kinect_local_rgb_raw_synced.avi");
                capture.SetCaptureProperty(Emgu.CV.CvEnum.CapProp.PosFrames, currentFrame);
                pictureBox.Image = capture.QueryFrame().Bitmap;

                frameCount = (int) capture.GetCaptureProperty(Emgu.CV.CvEnum.CapProp.FrameCount);
                
            } catch ( Exception e)
            {
                Console.WriteLine(e);
            }
        }
Пример #14
0
 public void InitVideoCapture(string path)
 {
     try
     {
         m_FrameMat = new Mat();
         m_VideoCaptureFilename = path;
         m_VideoCaptureInterface = null;
         m_VideoCaptureInterface = new Capture(m_VideoCaptureFilename);
         m_VideoCaptureInterface.SetCaptureProperty(CapProp.FrameHeight, 640);
         m_VideoCaptureInterface.SetCaptureProperty(CapProp.FrameWidth, 360);
         m_VideoCaptureInterface.SetCaptureProperty(CapProp.Fps, 5);
         m_VideoCaptureInterface.ImageGrabbed += VideoCaptureInterface_ImageGrabbed;
         m_VideoCaptureFrameCount = (int)m_VideoCaptureInterface.GetCaptureProperty(CapProp.FrameCount);
         m_VideoCaptureInterface.Start();
     }
     catch (Exception e)
     {
     }
 }
Пример #15
0
 private void frameProcessing()
 {
     _capture = new Capture(_file);
     totalFrameCount = _capture.GetCaptureProperty(Emgu.CV.CvEnum.CapProp.FrameCount);
     _capture.ImageGrabbed += ProcessFrame;
 }
Пример #16
0
        public void SetFile(string filePath)
        {
            if (capture != null)
                capture.Dispose();

            capture = new Capture(filePath);

            nextFrame = capture.QueryFrame();
            if (nextFrame != null)
                isDirty = true;

            this.VideoSize = new Size2((int)capture.GetCaptureProperty( Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FRAME_WIDTH),
                                       (int)capture.GetCaptureProperty( Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FRAME_HEIGHT));

            #if false
            Image<Bgr, byte> img = capture.QueryFrame();
            img = capture.QueryFrame();
            ImageViewer viewer = new ImageViewer();
            viewer.Image = img;
            viewer.ShowDialog();
            #endif
        }
Пример #17
0
        private void SetupCapture(int Camera_Identifier)
        {
            //update the selected device
            CameraDevice = Camera_Identifier;


            //Dispose of Capture if it was created before
            if (_capture != null) _capture.Dispose();
            try
            {
                //Set up capture device
                _capture = new Capture(CameraDevice);
                _capture.SetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FPS, Int16.Parse(fpstext.Text));
                if (resolution.SelectedIndex == 0)
                {
                    _capture.SetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FRAME_HEIGHT, 480);
                    _capture.SetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FRAME_WIDTH, 640);
                }

                if (resolution.SelectedIndex == 1)
                {
                    _capture.SetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FRAME_HEIGHT, 1000);
                    _capture.SetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FRAME_WIDTH, 2000);
                    
                }
                selectedWidth= _capture.Width;
                selectedHeight = _capture.Height;
                
                selectedfps = Convert.ToInt16(_capture.GetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FPS));
               // _capture.ImageGrabbed += ProcessFrame;
              
            }
            catch (NullReferenceException excpt)
            {MessageBox.Show(excpt.Message);}

        }
Пример #18
0
        private void button1_Click(object sender, EventArgs e)
        {
            //CvInvoke.cvCreateCameraCapture(2);
            Capture capture = new Capture();
            capture.SetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FRAME_WIDTH, 1280);
            capture.SetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FRAME_HEIGHT, 720);
            //capture.SetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FPS, 60);

            label1.Text = "Width:" + Convert.ToInt32(capture.GetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FRAME_WIDTH)).ToString()
                + ",Height:" + Convert.ToInt32(capture.GetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FRAME_HEIGHT)).ToString();
            Application.Idle += new EventHandler(delegate(object sender2, EventArgs e2)
            {
                img = capture.QueryFrame();
                camerabox1.Image = img.ToBitmap();
                if (a > 0)
                {
                    getBox(img);
                    a = 0;
                }
            });
        }
Пример #19
0
        private string GetVideoInformation(Capture capture)
        {
            var height = _capture.GetCaptureProperty(CapProp.FrameHeight);
            var width = _capture.GetCaptureProperty(CapProp.FrameWidth);
            var frameRate = capture.GetCaptureProperty(CapProp.Fps);
            var totalFrames = capture.GetCaptureProperty(CapProp.FrameCount);
            var codecDouble = capture.GetCaptureProperty(CapProp.FourCC);
            var codec = ConvertToStringCaptureProperty(codecDouble);

            return String.Format("Format: {0}x{1}\nFPS: {2}\nFrames: {3}\nCodec: {4}",
                width,
                height,
                frameRate,
                totalFrames,
                codec);
        }
Пример #20
0
        private void writeRallyVideoFromLoaded(double s, double e, VideoWriter writer, String loadedvideopath)
        {
            double start = Math.Floor(s);
            double end = Math.Ceiling(e);
            double startmsec = start * 1000;
            double endmsec = end * 1000;


            Capture tempcapture = new Capture(loaded_videopath);

            Image<Bgr, Byte> frame;
            if (tempcapture != null)
            {
                //tempcapture.SetCaptureProperty(CAP_PROP.CV_CAP_PROP_POS_MSEC, start);

                double fps2 = tempcapture.GetCaptureProperty(CAP_PROP.CV_CAP_PROP_FPS);
                //tempcapture.SetCaptureProperty(CAP_PROP.CV_CAP_PROP_POS_MSEC, 100);

                for (int i = 0; i < (start * fps2); i++)
                    (tempcapture).QueryFrame();

                int durationframes = (int)((end - start) * fps2); // since c# sucks i have to do it manually just like any other crap

                int count = 0;
                while (count < durationframes)
                {
                    frame = (tempcapture).QueryFrame();
                    videoWriter.WriteFrame(frame);
                    count++;
                }
            }


            tempcapture.Dispose();
            videoWriter.Dispose();
        }
Пример #21
0
        public void SetVideo(string fileName)
        {
            if (_Capture != null)
            {
                _Capture.Dispose();
            }

            _FilePath = fileName;
            _Capture = new Capture(fileName);

            _TotalFrames = (int)_Capture.GetCaptureProperty(CapProp.FrameCount);
        }
Пример #22
0
        /*
         * This function loads the Rally that is to be reviewed.
         * That is, it sets its frame position to 00:00, Enables the control buttons in the reviewer, etc
         */
        private void loadReviewingRally(Rally rally)
        {

            Game.Reviewing_rally = rally;

            if (Game.Reviewing_rally != null)
            {
                

                pictureBox_birdview.Refresh();

                updatePositionList();

                // Enable control buttons
                panel_reviewervideocontrols.Enabled = true;
                panel_reviewerpositions.Enabled = true;

                if (Game.Reviewing_rally.Finalized)
                    button_reviewerfinalized.Text = "Unfinalize";
                else
                    button_reviewerfinalized.Text = "Finalize";



                // Reception Player Radiobuttons
                if (Game.Reviewing_rally.Reception_pos.Player == configuration.Teama.Player1)
                    radioButton_reviewerplayer1.Checked = true;

                if (Game.Reviewing_rally.Reception_pos.Player == configuration.Teama.Player2)
                    radioButton_reviewerplayer2.Checked = true;

                if (Game.Reviewing_rally.Reception_pos.Player == configuration.Teamb.Player1)
                    radioButton_reviewerplayer3.Checked = true;

                if (Game.Reviewing_rally.Reception_pos.Player == configuration.Teamb.Player2)
                    radioButton_reviewerplayer4.Checked = true;

                radioButton_reviewerplayer1.Text = configuration.Teama.Player1.Name;
                radioButton_reviewerplayer2.Text = configuration.Teama.Player2.Name;
                radioButton_reviewerplayer3.Text = configuration.Teamb.Player1.Name;
                radioButton_reviewerplayer4.Text = configuration.Teamb.Player2.Name;


                // Defence player checkboxes:
                List<Person> defenceplayers = Game.Reviewing_rally.Reception_pos.Defenceplayers;
                checkBox_defenceplayer1.Checked = defenceplayers.Contains(configuration.Teama.Player1);
                checkBox_defenceplayer2.Checked = defenceplayers.Contains(configuration.Teama.Player2);
                checkBox_defenceplayer3.Checked = defenceplayers.Contains(configuration.Teamb.Player1);
                checkBox_defenceplayer4.Checked = defenceplayers.Contains(configuration.Teamb.Player2);

                


                // here we load the video for the first time in the reviewer at frame=0
                String video_name = Game.Reviewing_rally.Start_time.ToString(); 
                try
                {
                    capture_review = null; // delete the old one
                    String videopath = Program.getConfiguration().Mediafolderpath + @"\" + video_name + ".mpg";
                    this.capture_review = new Capture(videopath);
                    double fps = capture_review.GetCaptureProperty(CAP_PROP.CV_CAP_PROP_FPS); 
                    if (fps > 0)
                    {
                        review_timer_interval = (int)Math.Ceiling((1000 / fps)) - 3;
                        //timer_review_capture.Interval = interval;

                    }
                    else
                    {
                        fps = 25;
                        timer_review_capture.Interval = 40;
                    }
                }
                catch (NullReferenceException) { Console.WriteLine("unreadable video file"); }
                

                // Count the frames in the video
                double frame_number = 0;
                if (capture_review != null)
                {
                    //this.capture_review.SetCaptureProperty(CAP_PROP.CV_CAP_PROP_POS_FRAMES, 0);
                    while (capture_review.QueryFrame() != null)
                        frame_number++;

                    String videopath = Program.getConfiguration().Mediafolderpath + @"\" + video_name + ".mpg";
                    this.capture_review.Dispose();
                    this.capture_review = new Capture(videopath);

                    /*
                    if (capture_device_index != -1)
                    {
                        for (int i = 0; i < 10; i++)
                            capture_review.QueryFrame();
                        this.capture_review.SetCaptureProperty(CAP_PROP.CV_CAP_PROP_POS_FRAMES, 0);
                    }

                    */
                }
                trackBar_reviewervideo.Maximum = (int)frame_number;
                trackBar_reviewervideo.Value = 0;

                

                // If all the loading is done we display the right tab
                tabControl_main.SelectedIndex = 1;  // switch to review-tab


                // After we loaded all the stuff we can finally play the video:
               button_reviewerplaypause.Text = "Pause";

               timer_review_capture.Start();

               

                if (calibration != null)
                {
                    if (game.Reviewing_rally.Service_pos.ImageX != 0 && game.Reviewing_rally.Service_pos.ImageY != 0)
                    {
                        editing_position = 0;
                        savePosition(game.Reviewing_rally.Service_pos.ImageX, game.Reviewing_rally.Service_pos.ImageY);
                    }

                    if (game.Reviewing_rally.Defence_pos.ImageX != 0 && game.Reviewing_rally.Defence_pos.ImageY != 0)
                    {
                        editing_position = 5;
                        savePosition(game.Reviewing_rally.Defence_pos.ImageX, game.Reviewing_rally.Defence_pos.ImageY);
                    }
                }



                //selectnextEmptyPosition();
                // Select first index
                listView_reviewertrackedpoints.Items[0].Selected = true;
                listView_reviewertrackedpoints.Focus();
            }
        }
        public override bool InitializeStream()
        {
            if (!VideoDevices.Any())
            {
                FeedbackService.ShowErrorMessage("No video devices connected to this PC!");
                return false;
            }

            try
            {
                _capture = new Capture(VideoDevices.IndexOf(InputName));
                double fps = _capture.GetCaptureProperty(CapProp.Fps);

                if (fps < 10)
                    FPS = 30;
                else
                    FPS = fps;
            }
            catch
            {
                FeedbackService.ShowErrorMessage(string.Format("Failed to capture '{0}' device.", InputName));
                return false;
            }

            return true;
        }
Пример #24
0
        private void button_startmove_Click(object sender, EventArgs e)
        {
            long start_time;
     

            // initiating a new move along with a new timestamp as identifier
            if (!new_move)
            {
                live_video_click_count = 0;

                // Enable the Spielzug/Move property buttons
                button_kill.Enabled = true;
                button_smash.Enabled = true;
                button_drop.Enabled = true;
                button_bigPoint.Enabled = true;
                button_timeout.Enabled = true;

                radioButton_playerupright.Enabled = true;
                radioButton_playerupleft.Enabled = true;
                radioButton_playerdownleft.Enabled = true;
                radioButton_playerdownright.Enabled = true;

                radioButton_playerupright.Checked = false;
                radioButton_playerupleft.Checked = false;
                radioButton_playerdownleft.Checked = false;
                radioButton_playerdownright.Checked = false;
                

                start_time = getCurrentTime(); // get current time as identifier
                while (List_timestamps.Contains(start_time))
                    start_time = getCurrentTime();
                
                List_timestamps.Add(start_time); // add timestamp to the list we use for the screenshots

                // Create a new Rally 
                Game.Current_rally = 
                    new Rally(configuration.Teama.Player1.Current_position,
                              configuration.Teama.Player2.Current_position,
                              configuration.Teamb.Player1.Current_position,
                              configuration.Teamb.Player2.Current_position,
                              start_time, Game.Sets.Count);

                
   

                // Clear the BirdView
                pictureBox_birdview.Invalidate();

                rallyframes = new List<Image<Bgr, byte>>();

                
                String move_identifier = start_time.ToString();
                String videopath = Program.getConfiguration().Mediafolderpath + @"\" + move_identifier + ".mpg";

                if (capture_device_index != -1)
                    this.videoWriter = new VideoWriter(videopath, Emgu.CV.CvInvoke.CV_FOURCC('P', 'I', 'M', '1'), fps, 640, 480, true);


                // start a new video capture from video
                if (capture_device_index == -1)
                {
                    Capture tempcapture = new Capture(loaded_videopath);
                    int tempfps = (int)tempcapture.GetCaptureProperty(CAP_PROP.CV_CAP_PROP_FPS);
                    //this.videoWriter = new VideoWriter(videopath, Emgu.CV.CvInvoke.CV_FOURCC('P', 'I', 'M', '1'), tempfps, 640, 480, true);
                    startmilisecond = axWindowsMediaPlayer_live.Ctlcontrols.currentPosition;
                    axWindowsMediaPlayer_live.Ctlcontrols.play();
                    tempcapture.Dispose();
                }


                button_startmove.Text = "End of rally";
                button_startmove.ForeColor = System.Drawing.Color.Red;
                new_move = true;
            }
            else
            {
                live_video_click_count = 0;

                // Disable the Spielzug/Move property buttons
                button_kill.Enabled = false;
                button_smash.Enabled = false;
                button_drop.Enabled = false;
                button_bigPoint.Enabled = false;
                button_timeout.Enabled = false;

                radioButton_playerupright.Enabled = false;
                radioButton_playerupleft.Enabled = false;
                radioButton_playerdownleft.Enabled = false;
                radioButton_playerdownright.Enabled = false;

                radioButton_playerupright.Checked = false;
                radioButton_playerupleft.Checked = false;
                radioButton_playerdownleft.Checked = false;
                radioButton_playerdownright.Checked = false;

                // AUTO handling of score
                // Save into the list and add to xml output
                if (Game.Current_rally != null)
                {
                    Set current_set = Game.Sets[Game.Sets.Count - 1];
                    current_set.Rallies.Add(Game.Current_rally);
                    

                    // Set End Time
                    Game.Current_rally.EndRally_time = getCurrentTime();
                    Game.Current_rally.Duration_ticks = Game.Current_rally.EndRally_time - Game.Current_rally.Start_time;

                    // calculate the point for the successful team
                    Game.Current_rally.setNewScore(Game, configuration.TeamAup);
                    

                    xmlDoc.addRally(Game.Current_rally);


                    if (Game.Current_rally.Kill)
                        button_kill.Text = "KILL";
                    else
                        button_kill.Text = "NO KILL";

                    if (configuration.TeamAup)
                    {
                        textBox_scoreteamup.Text = current_set.TeamAScore.ToString();
                        textBox_scoreteamdown.Text = current_set.TeamBScore.ToString();
                    }
                    else
                    {
                        textBox_scoreteamup.Text = current_set.TeamBScore.ToString();
                        textBox_scoreteamdown.Text = current_set.TeamAScore.ToString();
                    }
                    // set color 
                    setScoreColor(current_set);
                    Team winner = current_set.getSetWinner(Game);

                    if (winner != null)
                    {
                        teamXhasWon();
                    }
                }


                

                // stop the capturing and write video
                if (capture_device_index != -1) // camera capture
                {
                    start_time = Game.Current_rally.Start_time;
                    WriteRallyVideoThread writevideoobject = new WriteRallyVideoThread(buffer, videoWriter, start_time);
                    writevideoobject.donewritingrallyvideo += new DoneWritingRallyVideoEventHandler(writevideothread_donewritingvideo);
                    writeRallyVideoFromBuffer(writevideoobject);
                }
                else // loaded video
                {
                    endmilisecond = axWindowsMediaPlayer_live.Ctlcontrols.currentPosition;
                    start_time = Game.Current_rally.Start_time;
                    WriteRallyVideoThread writevideoobject = new WriteRallyVideoThread(startmilisecond, endmilisecond, loaded_videopath, null, start_time);
                    writevideoobject.donewritingrallyvideo += new DoneWritingRallyVideoEventHandler(writevideothread_donewritingvideo);
                    writevideoobject.donewritingrallyframe += new DoneWritingRallyFrameEventHandler(writevideothread_donewritingframe);
                    writeRallyVideoFromLoaded(writevideoobject);
                    
                }


                button_startmove.Text = "Start of rally…"; // SAVE
                button_startmove.ForeColor = System.Drawing.Color.Black;
                new_move = false;

            }
        }
Пример #25
0
        /* Zapisanie domyślnych ustawień kamery i uruchomienie odbioru obrazu */
        private void KameraMyszka_Load(object sender, EventArgs e)
        {
            try
            {
                capture = new Capture();
                defaultBrightness = capture.GetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_BRIGHTNESS);
                defaultContrast = capture.GetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_CONTRAST);
                defaultSharpness = capture.GetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_SHARPNESS);
                defaultSaturation = capture.GetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_SATURATION);
                defaultWhiteBlueBalance = capture.GetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_WHITE_BALANCE_BLUE_U);
                defaultWhiteRedBalance = capture.GetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_WHITE_BALANCE_RED_V);
                defaultHue = capture.GetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_HUE);
                defaultGain = capture.GetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_GAIN);
                defaultGamma = capture.GetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_GAMMA);
                nudBrightness.Value = (decimal)defaultBrightness;
                nudContrast.Value = (decimal)defaultContrast;
                nudSharpness.Value = (decimal)defaultSharpness;
                nudSaturation.Value = (decimal)defaultSaturation;
                nudWhiteBlue.Value = (decimal)defaultWhiteBlueBalance;
                nudWhiteRed.Value = (decimal)defaultWhiteRedBalance;
                nudHue.Value = (decimal)defaultHue;
                nudGain.Value = (decimal)defaultGain;
                nudGamma.Value = (decimal)defaultGamma;
                Application.Idle += RefreshWindow;
            }
            catch (NullReferenceException ex) { Console.WriteLine("ERROR! "+ex.StackTrace); }

            globalHotkeys.Register();
            globalHotkeys2.Register();
        }
Пример #26
0
        private void recordVideoToolStripMenuItem_Click_1(object sender, EventArgs e)
        {
            //set up filter
            SF.Filter = "Video Files|*.avi;*.mp4;*.mpg";
            //Get information about the video file save location
            if (SF.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                //check to see if capture exists if it does dispose of it
                if (_Capture != null)
                {
                    if (_Capture.GrabProcessState == System.Threading.ThreadState.Running) _Capture.Stop(); //Stop urrent capture if running
                    _Capture.Dispose();//dispose of current capture
                }
                try
                {
                    //record the save location
                    this.Text = "Saving Video: " + SF.FileName; //display the save method and location

                    //set the current video state
                    CurrentState = VideoMethod.Recording;

                    //set up new capture
                    _Capture = new Capture(); //Use the default device
                    _Capture.ImageGrabbed += ProcessFrame; //attach event call to process frames

                    //get/set the capture video information

                    Frame_width = (int)_Capture.GetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FRAME_WIDTH);
                    Frame_Height = (int)_Capture.GetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FRAME_HEIGHT);

                    FrameRate = 15; //Set the framerate manually as a camera would retun 0 if we use GetCaptureProperty()

                    //Set up a video writer component
                    /*                                        ---USE----
                    /* VideoWriter(string fileName, int compressionCode, int fps, int width, int height, bool isColor)
                     *
                     * Compression code.
                     *      Usually computed using CvInvoke.CV_FOURCC. On windows use -1 to open a codec selection dialog.
                     *      On Linux, use CvInvoke.CV_FOURCC('I', 'Y', 'U', 'V') for default codec for the specific file name.
                     *
                     * Compression code.
                     *      -1: allows the user to choose the codec from a dialog at runtime
                     *       0: creates an uncompressed AVI file (the filename must have a .avi extension)
                     *
                     * isColor.
                     *      true if this is a color video, false otherwise
                     */
                    VW = new VideoWriter(@SF.FileName, -1, (int)FrameRate, Frame_width, Frame_Height, true);

                    //set up the trackerbar
                    UpdateVideo_CNTRL(false);//disable the trackbar

                    //set up the button and images
                    play_pause_BTN1.BackgroundImage = VideoCapture.Properties.Resources.Record;
                    recordstate = false;

                    //Start aquring from the webcam
                    _Capture.Start();

                }
                catch (NullReferenceException excpt)
                {
                    MessageBox.Show(excpt.Message);
                }
            }
        }
Пример #27
0
        private void ExtractVideoFrames(String Filename)
        {
            Capture _capture = new Capture(Filename);
            try
            {
                TotalVideoFrames = _capture.GetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FRAME_COUNT);
                VideoFPS = Math.Round(_capture.GetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FPS));
                VideoLength = Convert.ToInt32(Math.Round(TotalVideoFrames / VideoFPS));
                double frameNumber = 0.0;
                IBGFGDetector<Bgr> _detector = new FGDetector<Bgr>(FORGROUND_DETECTOR_TYPE.FGD);

                bool Reading = true;

                while (Reading)
                {
                    _capture.SetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_POS_FRAMES, frameNumber);
                    _capture.SetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_BRIGHTNESS, 100);
                    Image<Bgr, Byte> frame = _capture.QueryFrame();
                    if (frame != null)
                    {
                        frame = frame.Resize(Convert.ToDouble(ConfigurationSettings.AppSettings["OutFrameResizeScalefactor"]), Emgu.CV.CvEnum.INTER.CV_INTER_AREA);
                        frame._EqualizeHist();

                        frame.Save(OutImageLocation + "\\" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".jpg");
                    }
                    else
                    {
                        Reading = false;
                    }

                    frameNumber += (VideoFPS * TimeDiff);
                    if (frameNumber > TotalVideoFrames)
                        Reading = false;

                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                _capture.Dispose();
            }
        }
        public void write()
        {
            Capture tempcapture = new Capture(loaded_videopath);
            int fps = (int)tempcapture.GetCaptureProperty(CAP_PROP.CV_CAP_PROP_FPS);

            if (tempcapture != null)
            {

                int durationframes = (int)((end - start) * fps);
                int progressbar_max = (int)(durationframes + (start * fps));

                /*
                Console.WriteLine("start frame should be: " + (start * fps));
                Emgu.CV.CvInvoke.cvSetCaptureProperty(tempcapture, CAP_PROP.CV_CAP_PROP_POS_FRAMES, (start * fps));
                Console.WriteLine("current frame pos (opencv): " + Emgu.CV.CvInvoke.cvGetCaptureProperty(tempcapture, CAP_PROP.CV_CAP_PROP_POS_FRAMES));

                tempcapture.SetCaptureProperty(CAP_PROP.CV_CAP_PROP_POS_FRAMES, (start * fps));
                Console.WriteLine("current frame pos (emgucv): " + tempcapture.GetCaptureProperty(CAP_PROP.CV_CAP_PROP_POS_FRAMES));
                */

                int duration = (int)(end - start);
                String outputpath = Program.getConfiguration().Mediafolderpath + @"\" + starttime.ToString() + ".mpg";
                String argument = "-sameq -ss " + start + " -t " + duration + " -i " + loaded_videopath + " " + outputpath;

                String exepath = Environment.CurrentDirectory + @"\" + "ffmpeg.exe";
                Process myProcess = new Process();

                try
                {
                    myProcess.StartInfo.CreateNoWindow = true;
                    myProcess.StartInfo.UseShellExecute = false;
                    myProcess.StartInfo.FileName = exepath;
                    myProcess.StartInfo.Arguments = argument;
                    myProcess.EnableRaisingEvents = true;
                    myProcess.Exited += new EventHandler(processFinished);
                    myProcess.Start();
                }
                catch (Win32Exception ex)
                {
                    Console.WriteLine(ex.NativeErrorCode);
                }


            }
                /*
                DoneWritingRallyFrameEventArgs eframe;
                
                for (int i = 0; i < (start * fps); i++)
                {
                    (tempcapture).QueryFrame();
                    eframe = new DoneWritingRallyFrameEventArgs(i, progressbar_max);
                    donewritingrallyframe(this, eframe);
                }
                
                

                int count = 0;
                while (count < durationframes)
                {
                    frame = (tempcapture).QueryFrame();
                    videoWriter.WriteFrame(frame);
                    count++;
                    eframe = new DoneWritingRallyFrameEventArgs((count+(int)(start * fps)), progressbar_max);
                    donewritingrallyframe(this, eframe);
                }
            }


            tempcapture.Dispose();
            videoWriter.Dispose();



            // We are theoretically done with writing the video... so we notify all registered listeners
            DoneWritingRallyVideoEventArgs e = new DoneWritingRallyVideoEventArgs(this.starttime);
            donewritingrallyvideo(this, e);

            */
        }
Пример #29
0
        void FrameGrabber(object sender, EventArgs e)
        {
            try
            {
                //Get the current frame form capture device
                currentFrame = grabber.QueryFrame().Resize(520, 340, Emgu.CV.CvEnum.INTER.CV_INTER_CUBIC);
            }
            catch (NullReferenceException e1)
            {
                _motionHistory = new MotionHistory(2.0, 0.05, 0.5);
                _forgroundDetector = null;
                motionQueue.Clear(); helpQueue.Clear();
                grabber = new Capture(vidlist[excnt]);
                excnt++;
                if (excnt == 5) { excnt = 0; }
                currentFrame = grabber.QueryFrame().Resize(520, 340, Emgu.CV.CvEnum.INTER.CV_INTER_CUBIC);
                green1 = false; green2 = false; green3 = false; green4 = false;
                red1 = false; red2 = false; red3 = false; red4 = false;
            }

            //Convert it to Grayscale
            gray = currentFrame.Convert<Gray, Byte>();

            //Face Detector
            MCvAvgComp[][] facesDetected = gray.DetectHaarCascade(
              face,
              1.2,
              10,
              Emgu.CV.CvEnum.HAAR_DETECTION_TYPE.DO_CANNY_PRUNING,
              new Size(20, 20));

            //Action for each element detected
            foreach (MCvAvgComp f in facesDetected[0])
            {

                t = t + 1;
                result = currentFrame.Copy(f.rect).Convert<Gray, byte>().Resize(100, 100, Emgu.CV.CvEnum.INTER.CV_INTER_CUBIC);

                //MessageBox.Show("wiidth " + f.rect.Width + " height " + f.rect.Height + " area " + f.rect.Width * f.rect.Height);
                if (f.rect.Width > 80) continue;

                //draw the face detected in the 0th (gray) channel with blue color
                if (showHand)
                    currentFrame.Draw(f.rect, new Bgr(Color.LightGreen), 2);

                int nearespos = nearestPosition(f.rect.X, f.rect.Y);

                if (helpQueue.ToArray().ToList().IndexOf(nearespos) == -1)
                {
                    //lbAlerts.Items.Add("Help request at #" + nearespos.ToString());

                    dgAlerts.Rows.Add("Help Request", nearespos.ToString());
                    DB_Connect.InsertQuery("INSERT INTO alert_tab(exam_id,position_id,alert_type,alert_time) VALUES(" + examid + "," + nearespos.ToString() + ",'H','" + DateTime.Now + "')");
                    dgAlerts.FirstDisplayedScrollingRowIndex = dgAlerts.RowCount - 1;

                    //GCM - help
                    //AndroidGCMPushNotification apnGCM = new AndroidGCMPushNotification();
                    //string strResponse = apnGCM.SendNotification(regID, nearespos.ToString() + " "+ DateTime.Now, "H");

                    if (nearespos == 1) green1 = true;
                    else if (nearespos == 2) green2 = true;
                    else if (nearespos == 3) green3 = true;
                    else if (nearespos == 4) green4 = true;

                    if (helpQueue.Count == 10)
                    {
                        helpQueue.Dequeue();
                        helpQueue.Enqueue(nearespos);
                    }
                    else
                    {
                        helpQueue.Enqueue(nearespos);
                    }
                }
            }

            //Show the faces procesed and recognized
            imageBoxFrameGrabber.Image = ProcessFrame(currentFrame);

            if (captureOutput == null && xdoc.Descendants("RecordVideo").First().Value == "1")
            {
                MessageBox.Show("reording start");
                captureOutput = new VideoWriter(@"video" + examid + ".avi", (int)grabber.GetCaptureProperty(CAP_PROP.CV_CAP_PROP_FOURCC), 15, 520, 340, true);
            }

            if (currentFrame != null && xdoc.Descendants("RecordVideo").First().Value == "1")
            {
                captureOutput.WriteFrame<Bgr, Byte>(currentFrame);
            }
        }
        public override bool InitializeStream()
        {
            if (string.IsNullOrWhiteSpace(FilePath))
            {
                FeedbackService.ShowErrorMessage("Video file not selected!");
                return false;
            }

            try
            {
                _capture = new Capture(FilePath);
                FPS = _capture.GetCaptureProperty(CapProp.Fps);
            }
            catch
            {
                FeedbackService.ShowErrorMessage(string.Format("File '{0}' is not valid video file, or it's corrupt.", FilePath));
                return false;
            }

            return true;
        }
        public void OpenDir(string path)
        {
            // color stream
            string tpath = path+"\\" + path.Split('\\').Last();
            var c = new Capture(tpath + "_c.avi");
            if (_CCapture != null)
            {
                _CCapture.Dispose();//dispose of current capture
            }
            _CCapture = c;
            // depth stream
            c = new Capture(tpath + "_d.avi");
            if (_DCapture != null)
            {
                _DCapture.Dispose();//dispose of current capture
            }
            _DCapture = c;

            FrameRate = _DCapture.GetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FPS);
            TotalFrames = (int)_DCapture.GetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FRAME_COUNT);
            Console.WriteLine("Total frame:"+TotalFrames.ToString());
            double codec_double = c.GetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FOURCC);
            // skeleton
            OpenSkeleton(tpath + ".csv");
            // label
            if (labelWriter != null)
            {
                labelWriter.Close();
                labelWriter.Dispose();
            }
            labelWriter = new CsvFileWriter(path+"\\label.csv");
            SetCurrentFrame(0);
        }
Пример #32
-1
        public Camera()
        {
            capture = new Capture(); //create a camera captue
            capture.SetCaptureProperty(CapProp.FrameWidth, 2592);
            capture.SetCaptureProperty(CapProp.FrameHeight, 1944);
            capture.FlipVertical = true;
            FrameRate = capture.GetCaptureProperty(CapProp.Fps);

            Debug.DebugStatement("Camera initialized",ConsoleColor.White);
        }