Пример #1
0
        /// <summary>
        /// Runs a number of single extractions from the IP camera
        /// Times the change to Bitmap and count of the pixels for
        /// These images
        /// </summary>
        public void RunBenchmarking(string logfile)
        {
            //extract the images
            List<String> saveLocations = new List<string>();
            string url = "http://192.168.0.2/axis-cgi/mjpg/video.cgi?resolution=";

            List<String[]> resolutions = ReturnResolutions();

            for(int i = 0; i < resolutions.Count; i++)
            {
                string actualurl = url + resolutions[i][0] + "x" + resolutions[i][1];

                //set up the extractor
                ImageExtractor imageExtractor = new ImageExtractor(actualurl, "root", "root");

                //set up the save file object
                ImageSaver imageSaver = new ImageSaver(0, 1);
                saveLocations.Add(imageSaver.CaptureDirectory);

                //create the validator 
                ImageValidator imageValidator = new ImageValidator();
                imageValidator.ListenForImages(imageExtractor);
                imageValidator.imageValidated += new ImageValidator.ImageValidatedEvent(imageSaver.ImageCreatedAsync);//subscribe to events from the validator

                imageExtractor.Run(true);

                System.Threading.Thread.Sleep(5000); //wait 5 seconds to let the async requests complete
            }

            //do the analysis
            for(int i = 0; i < saveLocations.Count; i++)
            {
                string header = resolutions[i][0] + "x" + resolutions[i][1];
                Console.WriteLine(Environment.NewLine + resolutions[i][0] + "x" + resolutions[i][1]);
                JPEG jpeg = new JPEG(saveLocations[i] + @"\1\test_0.jpg");

                string msToBitmap = MsToBitmap(jpeg).ToString();
                string msToBitmapAndSumPixels = MsToBitmapAndSumPixels(jpeg).ToString();
                string totalPixels = TotalPixels(jpeg).ToString();

                Console.WriteLine(msToBitmap);
                Console.WriteLine(msToBitmapAndSumPixels);
                Console.WriteLine(totalPixels);

                using (System.IO.StreamWriter file = new System.IO.StreamWriter(logfile, true))
                {
                    file.WriteLine(header);
                    file.WriteLine(msToBitmap);
                    file.WriteLine(msToBitmapAndSumPixels);
                    file.WriteLine(totalPixels);
                    file.WriteLine("------------------------------");
                }

            }

        }//RunBenchmarking
        public void Run(string captureKey)
        {
            //set up the extractor
            string uri = "http://localhost:9000/api/jpeg/0/" + captureKey;

            ImageExtractor imageExtractor = new ImageExtractor(uri, "root", "root");

            //create the motion sensor, and listen for images
            MotionSensor_2b motionSensor = new MotionSensor_2b();
            motionSensor.motionDetected += new MotionSensor_2.MotionDetected(MotionDetected);

            //create the validator 
            ImageValidator imageValidator = new ImageValidator();
            imageValidator.ListenForImages(imageExtractor);
            imageValidator.imageValidated += new ImageValidator.ImageValidatedEvent(motionSensor.ImageCreatedAsync);//subscribe to events from the validator

            imageExtractor.Run();

        }