Ejemplo n.º 1
0
        public static VideoImaging Load(string videoFile)
        {
            string       path = Settings.VideoFullPath(videoFile);
            VideoImaging vi   = new VideoImaging(path);

            return(vi.videoCapture.IsOpened() ? vi : null);
        }
 public static void UnloadVideoFile()
 {
     VideoImaging = null;
     Parameters   = null;
     MotionData   = null;
     UpdateAllControll();
 }
        public static void LampAnalyze(IEnumerable <string> selectedlist)
        {
            foreach (string videofile in selectedlist)
            {
                VideoImaging vi = VideoImaging.Load(videofile);
                if (vi == null)
                {
                    continue;
                }
                VideoImaging = vi;

                Parameters para = Parameters.LoadOrCreate(videofile, vi, true);
                if (para == null)
                {
                    continue;
                }
                Parameters = para;

                MotionData md = vi.AnalizeAll(para);
                if (md == null)
                {
                    continue;
                }
                MotionData = md;

                md.SaveRawData(videofile);
            }
            UnloadVideoFile();
        }
 public static void InitFormsAndShow(MainForm parent)
 {
     foreach (var f in ChildForm)
     {
         (f.Value as Form).MdiParent = parent;
         (f.Value as Form).Show();
     }
     VideoImaging = null;
     MotionData   = null;
     UpdateAllControll();
 }
Ejemplo n.º 5
0
        public ControllerForm()
        {
            InitializeComponent();

            tabPageSelect.Tag    = AnalyzeDirector.TabMode.Select;
            tabPageCondition.Tag = AnalyzeDirector.TabMode.Condition;
            tabPageGraph.Tag     = AnalyzeDirector.TabMode.Graph;
            tabPageAggregate.Tag = AnalyzeDirector.TabMode.Aggregate;
            tabPageLamp.Tag      = AnalyzeDirector.TabMode.Lamp;

            List <ShapeItem> src = new List <ShapeItem>()
            {
                new ShapeItem {
                    Name = "円", Shape = Parameters.TargetShape.Circle
                },
                new ShapeItem {
                    Name = "長方形", Shape = Parameters.TargetShape.Rectangle
                },
                new ShapeItem {
                    Name = "任意", Shape = Parameters.TargetShape.Any
                },
            };

            comboBoxShape.DisplayMember = "Name";
            comboBoxShape.ValueMember   = "Shape";
            comboBoxShape.DataSource    = src;
            comboBoxShape.SelectedValue = Parameters.TargetShape.Any;

            listView.BeginUpdate();
            listView.Items.Clear();
            foreach (string file in Settings.VideoFiles)
            {
                Bitmap thumb = VideoImaging.GetThumbnail(file, imageList.ImageSize);
                if (thumb != null)
                {
                    imageList.Images.Add(thumb);
                    ListViewItem item = new ListViewItem()
                    {
                        Name       = file,
                        ImageIndex = imageList.Images.Count - 1,
                    };
                    listView.Items.Add(item);
                }
            }
            listView.EndUpdate();

            comboBoxViewMode.SelectedIndex = 0;
        }
Ejemplo n.º 6
0
        public void LoadVideo(VideoImaging vi, int startFrame = 0)
        {
            trackBar.Maximum = vi.FrameCount - 1;
            trackBar.Value   = startFrame;

            Size size = vi.Size;

            if (size.Width > size.Height)  //横長
            {
                this.Width  = 800 + 18;
                this.Height = 450 + 167;
            }
            else  //縦長
            {
                this.Width  = 450 + 18;
                this.Height = 800 + 167;
            }
        }
Ejemplo n.º 7
0
        public static System.Drawing.Bitmap GetThumbnail(string videoFile, System.Drawing.Size size)
        {
            string       path = Settings.VideoFullPath(videoFile);
            VideoImaging vi   = new VideoImaging(path);

            if (vi != null)
            {
                vi.PosFrames = vi.videoCapture.FrameCount / 2;
                vi.SetRawMat();
                Mat mat = vi.rawmat;
                mat = mat.Resize(new Size(size.Width, size.Height));
                vi.videoCapture.Dispose();
                return(BitmapConverter.ToBitmap(mat));
            }
            else
            {
                return(null);
            }
        }
 public static void LoadVideoFile(string videoFile)
 {
     VideoImaging = VideoImaging.Load(videoFile);
     if (VideoImaging == null)
     {
         Parameters = null;
         MotionData = null;
     }
     else
     {
         Parameters = Parameters.LoadOrCreate(videoFile, VideoImaging);
         MotionData = MotionData.TryLoadRawData(videoFile, Parameters);
         ImageForm.LoadVideo(VideoImaging, Parameters.StartFrame);
         if (MotionData != null)
         {
             GraphForm.LoadData(MotionData);
         }
     }
     UpdateAllControll();
     ControllerForm.SwitchTab();
 }
Ejemplo n.º 9
0
        public static Parameters LoadOrCreate(string videoFile, VideoImaging vi, bool donotCreate = false)
        {
            Parameters parameter;
            string     targetdir = Settings.TargetDir(videoFile);
            string     filename  = Settings.XmlFilename(videoFile);

            if (!Directory.Exists(targetdir))
            {
                Directory.CreateDirectory(targetdir);
            }
            if (File.Exists(filename))
            {
                XmlSerializer serializer  = new XmlSerializer(typeof(Parameters));
                var           xmlSettings = new System.Xml.XmlReaderSettings()
                {
                    CheckCharacters = false
                };
                using (var sr = new StreamReader(filename, Encoding.UTF8))
                    using (var xmlReader = System.Xml.XmlReader.Create(sr, xmlSettings)) {
                        parameter = (Parameters)serializer.Deserialize(xmlReader);
                    }
            }
            else if (donotCreate)
            {
                parameter = null;
            }
            else
            {
                parameter = new Parameters()
                {
                    VideoFile  = videoFile,
                    FPS        = (int)Math.Round(vi.FPS),
                    StartFrame = 0,
                    EndFrame   = vi.FrameCount - 1,
                };
                parameter.Save();
            }

            return(parameter);
        }
Ejemplo n.º 10
0
        public void UpdateCtrl()
        {
            Parameters para = AnalyzeDirector.Parameters;

            if (!AnalyzeDirector.Loaded ||
                AnalyzeDirector.Tab == AnalyzeDirector.TabMode.Aggregate ||
                AnalyzeDirector.Tab == AnalyzeDirector.TabMode.Select)
            {
                labelFrame.Text        = "";
                pictureBoxIpl.ImageIpl = null;
                this.Enabled           = false;
                this.WindowState       = FormWindowState.Minimized;
                radioButtonRaw.Select();
            }
            else
            {
                VideoImaging vi = AnalyzeDirector.VideoImaging;
                vi.PosFrames = trackBar.Value;
                Mat       mat = new Mat();
                const int R   = 10;
                if (radioButtonRaw.Checked)
                {
                    toolStripStatusLabel.Text = "左クリック:長さの基準の設定          右クリック:検出対象の色の設定";
                    mat = vi.GetRawMat();
                    List <Point> points = para.Ruler;
                    foreach (Point p in points)
                    {
                        mat.Circle(p.X, p.Y, R, Scalar.Blue, 4);
                    }
                    if (points.Count == 2)
                    {
                        mat.Line(points[0], points[1], Scalar.Blue, 4);
                    }
                }
                else if (radioButtonRange.Checked)
                {
                    toolStripStatusLabel.Text = "左クリック:解析範囲の設定          右クリック:解析範囲のクリア";
                    mat = vi.RangeMaskedMat(para);
                    foreach (Point p in para.Range)
                    {
                        mat.Rectangle(new Rect(p.X - R, p.Y - R, 2 * R, 2 * R), Scalar.Green, -1);
                    }
                }
                else if (radioButtonBinary.Checked)
                {
                    toolStripStatusLabel.Text = "物体検出用の2値化画像の確認。" +
                                                "上手くいっていない場合、「検出閾値」や「検出対象の色」を変更する";
                    mat = vi.BinaryMat(para);
                }
                else if (radioButtonDetect.Checked)
                {
                    toolStripStatusLabel.Text = "検出結果の確認。物体の向きは「物体の形状」が円の場合、検出できない。";
                    mat = vi.DetectedMat(para);
                }
                else if (radioButtonStrobo.Checked)
                {
                    toolStripStatusLabel.Text = "ストロボ風写真の作成。「ストロボの間隔」で調整可能。(小さいと作成に時間がかかるので注意)";
                    mat = vi.StoroboMat(para);
                }
                else if (radioButtonTrajectory.Checked)
                {
                    toolStripStatusLabel.Text = "物体の重心の軌跡を表示。";
                    mat = vi.TrajectoryMat(para);
                }

                //axis
                if (AnalyzeDirector.Analized && mat.Type() == MatType.CV_8UC3)
                {
                    Point  o     = AnalyzeDirector.MotionData.GetOrigin();
                    double theta = -AnalyzeDirector.Parameters.XaxisAngle / 180d * Math.PI;
                    double dx    = Math.Cos(theta);
                    double dy    = Math.Sin(theta);
                    double l     = mat.Height + mat.Width;
                    mat.Line(new Point(o.X - l * dx, o.Y - l * dy), new Point(o.X + l * dx, o.Y + l * dy), Scalar.Violet, 1);
                    mat.Line(new Point(o.X + l * dy, o.Y - l * dx), new Point(o.X - l * dy, o.Y + l * dx), Scalar.Violet, 1);
                }

                labelFrame.Text        = vi.PosFrames.ToString() + " / " + (vi.FrameCount - 1).ToString();
                pictureBoxIpl.ImageIpl = mat;
                this.Enabled           = true;
                this.WindowState       = FormWindowState.Normal;
            }

            radioButtonStrobo.Visible     = AnalyzeDirector.MotionData != null;
            radioButtonTrajectory.Visible = AnalyzeDirector.MotionData != null;
        }