Beispiel #1
0
        private void CameraReading()
        {
            bool control = false;

            lock (flags)
            {
                control = flags.running;
            }
            if (control)
            {
                using (Mat videoFrame = new Mat())
                    using (Mat showFrame = new Mat())
                    {
                        if (capture.Read(videoFrame))
                        {
                            lock (flags)
                            {
                                cc.PassengersFilter(flags);
                                localiser.Locate(videoFrame, flags);
                            }
                            localiser.GetLocations(out car1, out car2);
                            lock (flags)
                            {
                                if (flags.calibrated)
                                {
                                    Point2f[] car12 = { car1, car2 };
                                    Point2f[] carAB = cc.CameraToLogic(car12);
                                    flags.posCarA = carAB[0];
                                    flags.posCarB = carAB[1];
                                }
                                else
                                {
                                    flags.posCarA = car1;
                                    flags.posCarB = car2;
                                }
                            }
                            timeCamNow = DateTime.Now;
                            TimeSpan timeProcess = timeCamNow - timeCamPrev;
                            timeCamPrev = timeCamNow;
                            Cv2.Resize(videoFrame, showFrame, flags.showSize, 0, 0, InterpolationFlags.Nearest);
                            BeginInvoke(new Action <Image>(UpdateCameraPicture), BitmapConverter.ToBitmap(showFrame));
                            //输出视频
                            if (flags.videomode == true)
                            {
                                vw.Write(showFrame);
                            }
                        }
                        lock (flags)
                        {
                            control = flags.running;
                        }
                    }
            }
        }
Beispiel #2
0
        private void CameraReading()
        {
            bool control = false;

            lock (flags)
            {
                control = flags.running;
            }
            if (control)
            {
                //using (Mat videoFrame = new Mat())
                using (Mat videoFrame = new Mat("../../map/reverse_map.png"))
                    using (Mat showFrame = new Mat())
                    {
                        //if (capture.Read(videoFrame))
                        if (true)
                        {
                            lock (flags)
                            {
                                cc.PassengersFilter(flags);
                                localiser.Locate(videoFrame, flags);
                            }

                            /*
                             * localiser.GetLocations(out car1, out car2);
                             * lock (flags)
                             * {
                             *  if (flags.calibrated)
                             *  {
                             *      Point2f[] car12 = { car1, car2 };
                             *      Point2f[] carAB = cc.CameraToLogic(car12);
                             *      flags.posCarA = carAB[0];
                             *      flags.posCarB = carAB[1];
                             *  }
                             *  else
                             *  {
                             *      flags.posCarA = car1;
                             *      flags.posCarB = car2;
                             *  }
                             * }
                             */
                            timeCamNow = DateTime.Now;
                            TimeSpan timeProcess = timeCamNow - timeCamPrev;
                            timeCamPrev = timeCamNow;
                            Cv2.Resize(videoFrame, showFrame, flags.showSize, 0, 0, InterpolationFlags.Nearest);
                            BeginInvoke(new Action <TimeSpan>(UpdateProcessTime), timeProcess);
                            Mat show_img = new Mat();
                            Cv2.Flip(showFrame, show_img, 0);
                            //BeginInvoke(new Action<Image>(UpdateCameraPicture), BitmapConverter.ToBitmap(showFrame));
                            BeginInvoke(new Action <Image>(UpdateCameraPicture), BitmapConverter.ToBitmap(show_img));
                            //输出视频
                            if (flags.videomode == true)
                            {
                                //vw.Write(showFrame);
                                vw.Write(show_img);
                            }
                        }
                        lock (flags)
                        {
                            control = flags.running;
                        }
                    }
            }
        }