Exemplo n.º 1
0
        // 이미지 전송 타이머
        private void timerPlay_Tick(object sender, EventArgs e)
        {
            try
            {
                this.Invoke((MethodInvoker) delegate()
                {
                    if (mjpgControl1.Position + 1 >= mjpgControl1.Length)
                    {
                        //mjpgControl1.Position = 0;

                        if (MjpgFileNames.Length - 1 <= FileIndex)
                        {
                            FileIndex = 0;
                        }

                        mjpgControl1.FilePath = MjpgFileNames[++FileIndex];
                        Console.WriteLine(" File path: {0} \n", mjpgControl1.FilePath);
                    }
                    mjpgControl1.Position = mjpgControl1.Position + 1;

                    unsafe
                    {
                        // 시뮬레이션 때문에 사용      --- jpg 이미지에서 raw 데이터로 변환시 시간 소요
                        Bitmap bt = (Bitmap)Image.FromStream(mjpgControl1.DataStream);
                        image     = OpenCvSharp.Extensions.BitmapConverter.ToMat(bt);
                        // ------------ how to use API -- 4 ---------
                        if (!image.Empty())
                        {
                            obj.ResetAndProcessFrame(0, image.DataPointer, bt.Width * bt.Height * 3);
                            if (obj.GetObjectNumber() > 0)
                            {
                                Console.WriteLine(" Event happened!!\n ");
                                for (int i = 0; i < obj.GetObjectNumber(); i++)
                                {
                                    Console.WriteLine(" Object ID:{0}, Class:{1}, Status:{2}, Speed:{3} \r \n ", obj.GetObjectIDAt(i),
                                                      obj.GetObjectClassAt(i), obj.GetObjectStatusAt(i), obj.GetObjectSpeedAt(i));
                                }
                            }
                        }
                    }
                });
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            string filename = "..\\TrafficVideo\\20180911_113611_cam_0.avi"; //20180912_112338_cam_0

            bool isFileExist = File.Exists(filename);

            Console.WriteLine(isFileExist ? " File exists." : "File does not exist.");
            if (!isFileExist)
            {
                Console.WriteLine("File does not exist.Please double check the file you choose !! \n");
                Console.Read();
                return;
            }

            using (VideoCapture capture = new VideoCapture(filename))
            {
                // ------------------------------------- How to use API -- 2 ------------------------------------
                ITMS_CLIWrap obj = new ITMSAPI_CLIWrap.ITMS_CLIWrap();
                obj.Init();
                // ----------------------------------------------------------------------------------------------

                int  sleepTime      = (int)Math.Round(1000 / capture.Fps);
                bool debugShowImage = true;
                int  ESCKEY         = 0;

                using (Window window = new Window("Video Playing", WindowMode.AutoSize))
                {
                    using (Mat image = new Mat()) // Frame image buffer
                    {
                        // When the movie playback reaches end, Mat.data becomes NULL.
                        while (true && ((char)ESCKEY != 27))
                        {
                            capture.Read(image); // read data
                            if (image.Empty())
                            {
                                break;
                            }
                            unsafe
                            {
                                // ------------------------------- How to use API -- 3 ----------------------
                                obj.ResetAndProcessFrame(0, image.DataPointer, image.Cols * image.Rows * image.Channels());
                                if (obj.GetObjectNumber() > 0)
                                {
                                    Console.WriteLine(" Event happened!!\n");
                                    for (int i = 0; i < obj.GetObjectNumber(); i++)
                                    {
                                        Console.WriteLine(" Object ID:{0}, Class:{1}, Status:{2}, Speed:{3} \r \n ", obj.GetObjectIDAt(i),
                                                          obj.GetObjectClassAt(i), obj.GetObjectStatusAt(i), obj.GetObjectSpeedAt(i));
                                    }
                                }
                                // --------------------------------------------------------------------------
                            }
                            if (debugShowImage)
                            {
                                window.ShowImage(image);
                            }
                            ESCKEY = Window.WaitKey(1);
                        }
                    }
                }
                // ---------------------------------- How to USE API -- 4 -----------------------------------
                if (obj != null)
                {
                    ((IDisposable)obj).Dispose();
                }
                // ------------------------------------------------------------------------------------------
            }
        }