コード例 #1
0
        public Dictionary <int, List <MarkerStructure> > GetMarkerList()
        {
            int frame_number = 0;
            int total_frame  = (int)m_data.Get(OpenCvSharp.CaptureProperty.FrameCount);

            OpenCvSharp.Mat read_image =
                new OpenCvSharp.Mat(new OpenCvSharp.Size(m_data.FrameWidth, m_data.FrameHeight), OpenCvSharp.MatType.CV_8U);
            frame_number = 0;
            if (!m_data.IsOpened())
            {
                System.Windows.Forms.MessageBox.Show("not opened");
            }
#if DEBUG1
            var window    = new OpenCvSharp.Window("debug");
            int sleepTime = (int)Math.Round(1000 / m_data.Fps);
#endif
            while (true)
            {
                //m_data.Read(read_image);
                //m_data.Grab();
                OpenCvSharp.NativeMethods.videoio_VideoCapture_operatorRightShift_Mat(m_data.CvPtr, read_image.CvPtr);
                Dictionary <int, List <MarkerStructure> > tmp = MarkerTracker(read_image, frame_number);
#if DEBUG1
                if (!read_image.Empty())
                {
                    foreach (int key in tmp.Keys)
                    {
                        foreach (MarkerStructure aa in tmp[key])
                        {
                            OpenCvSharp.Cv2.Rectangle(read_image, new OpenCvSharp.Rect(
                                                          new OpenCvSharp.Point(aa.marker_position.X, aa.marker_position.Y), new OpenCvSharp.Size(aa.marker_size.Height, aa.marker_size.Width)), new OpenCvSharp.Scalar(255.0f, 255.0f, 0.0f), 3);
                        }
                    }
                    OpenCvSharp.Cv2.PutText(read_image, frame_number.ToString(), new OpenCvSharp.Point(10, 50), OpenCvSharp.HersheyFonts.HersheyPlain, 5.0f, new OpenCvSharp.Scalar(255.0f, 255.0f, 0.0f), 3);
                    window.ShowImage(read_image);
                    OpenCvSharp.Cv2.WaitKey(sleepTime);
                }
#endif
                if (tmp != null)
                {
                    marker_result = AddDictionary(marker_result, tmp);
                }
                frame_number++;
                if (read_image.Empty())
                {
                    break;
                }
            }

            foreach (int key in marker_result.Keys)
            {
                marker_result[key].Sort();
            }

            return(marker_result);
        }
コード例 #2
0
        protected Dictionary<int, List<MarkerStructure>> GetMarkerList()
        {
            int frame_number = 0;

            foreach (VideoPacking p in m_data)
            {
                OpenCvSharp.Mat read_image = 
                    new OpenCvSharp.Mat(new OpenCvSharp.Size(p.VideoInstance.FrameWidth, p.VideoInstance.FrameHeight), OpenCvSharp.MatType.CV_8U);
                frame_number = 0;
                if (!p.VideoInstance.IsOpened())
                {
                    System.Windows.Forms.MessageBox.Show("not opened");
                    break;
                }

#if DEBUG
                var window = new OpenCvSharp.Window("debug");
                int sleepTime = (int)Math.Round(1000 / p.VideoInstance.Fps);
#endif
                while (true)
                {
                    p.VideoInstance.Grab();
                    OpenCvSharp.NativeMethods.videoio_VideoCapture_operatorRightShift_Mat(p.VideoInstance.CvPtr, read_image.CvPtr);
                    Dictionary<int, List<MarkerStructure>> tmp = MarkerTracker(read_image, p.VideoIdx, frame_number);
#if DEBUG
                    if (!read_image.Empty())
                    {
                        window.ShowImage(read_image);
                        foreach (int key in tmp.Keys)
                        {
                            foreach (MarkerStructure aa in tmp[key])
                            {
                                OpenCvSharp.Cv2.Rectangle(read_image, new OpenCvSharp.Rect(
                                    new OpenCvSharp.Point(aa.marker_position.X, aa.marker_position.Y), new OpenCvSharp.Size(aa.marker_size.Height, aa.marker_size.Width)), new OpenCvSharp.Scalar(255.0f, 0.0f, 0.0f), 3);
                            }
                        }
                        OpenCvSharp.Cv2.WaitKey(sleepTime);
                    }
#endif
                    if(tmp != null)
                        marker_result = AddDictionary(marker_result, tmp);
                    frame_number++;
                    if (read_image.Empty())
                        break;
                }
            }
            
            foreach(int key in marker_result.Keys)
            {
                marker_result[key].Sort();
            }

            return marker_result;
        }
コード例 #3
0
ファイル: demo.cs プロジェクト: tuncayozdemir07/face-sdk
        static int Main(string[] args)
        {
            // print usage
            Console.WriteLine("Usage: dotnet csharp_demo.dll [OPTIONS]");
            Console.WriteLine("Examples:");
            Console.WriteLine("    To specify license directory (for online license for example): dotnet csharp_demo.dll --license_dir license_dir");
            Console.WriteLine("");

            // parse arguments
            bool    error   = false;
            Options options = new Options();

            CommandLine.Parser.Default.ParseArguments <Options>(args)
            .WithParsed <Options>(opts => options  = opts)
            .WithNotParsed <Options>(errs => error = true);

            // exit if argument parsign error
            if (error)
            {
                return(1);
            }

            // print values of arguments
            Console.WriteLine("Arguments:");
            foreach (var opt in options.GetType().GetProperties())
            {
                Console.WriteLine("--{0} = {1}", opt.Name, opt.GetValue(options, null));
            }
            Console.WriteLine();

            try
            {
                OpenCvSharp.Window window = new OpenCvSharp.Window("demo");
                // create worker
                // (we are expecting run from bin folder)
                Worker worker = new Worker(
                    options.config_dir,
                    options.capturer_config,
                    options.license_dir);

                // here we trying camera open with opencv
                const int desiredFrameWidht  = 1280;
                const int desiredFrameHeight = 720;

                int camera_id = 0;

                // VideoCapture camera;
                OpenCvSharp.VideoCapture camera = new OpenCvSharp.VideoCapture();


                for (; camera_id < 10; ++camera_id)
                {
                    camera.Open(camera_id);
                    camera.Set(OpenCvSharp.CaptureProperty.FrameWidth, desiredFrameWidht);
                    camera.Set(OpenCvSharp.CaptureProperty.FrameHeight, desiredFrameHeight);
                    OpenCvSharp.Mat frame = new OpenCvSharp.Mat();
                    for (int i = 0; i < 10; i++)
                    {
                        frame = camera.RetrieveMat();
                    }

                    if (frame.Empty())
                    {
                        Console.WriteLine("webcam " + camera_id + " not opened");
                        camera.Release();
                    }
                    else
                    {
                        break;
                    }
                }

                for (;;)
                {
                    OpenCvSharp.Mat frame;

                    //camera.Grab();
                    frame = camera.RetrieveMat();

                    if (frame.Empty())
                    {
                        break;
                    }

                    // give a frame to the worker
                    worker.work(frame);

                    if (27 == (char)OpenCvSharp.Cv2.WaitKey(10))
                    {
                        camera.Release();
                        break;
                    }
                }

                // force free resources
                // otherwise licence error may occur
                // when create sdk object in next time
                worker.dispose();
            }
            catch (Exception e)
            {
                Console.WriteLine("! exception catched: '" + e + "' ... exiting");
                return(1);
            }
            Console.WriteLine("close program");
            return(0);
        }