Exemple #1
0
        static void Main(string[] args)
        {
            MetriLog  log              = new MetriLog();
            Random    rand             = new Random();
            const int MAX_DELAY_IN_MIN = 20;

            Camera                leftCam = new TheImagingSource();
            Camera                rightCam = new TheImagingSource();
            SerialPort            triggerPort = new SerialPort("COM7", 9600);
            TriggeredStereoCamera cam = new TriggeredStereoCamera(leftCam, rightCam, triggerPort);
            FloatImage            left, leftOld = null, right, rightOld = null;
            float thres;

            // thres = 1000.0f; // uEye
            thres = 100000.0f; // TIS
            int         cnt = 0;
            const float MAX_EXPOSURE      = 10f;
            const float DARK_THRES        = 50f; // uEye: 10f, TIS: 50f
            const int   NUM_WARMUP_IMAGES = 50;

            ConfigureLogging(StressTests.Freeze.Resources.LoggingConfigInfo);
            log.SetLogFile(@"D:\temp\stress_test_TIS.log");

            cam.Connect();
            cam.Exposure = 4;
            log.Info("Warming up.");
            for (int i = 0; i < NUM_WARMUP_IMAGES; i++)
            {
                Capture(cam, out left, out right, ref cnt);
            }

            log.Info("Starting test.");
            bool running = true;

            while (running)
            {
                log.Debug("Another round starts.");
                for (int i = 0; i < 10; i++)
                {
                    if (cam.Exposure > MAX_EXPOSURE)
                    {
                        cam.Exposure = MAX_EXPOSURE;
                        leftOld      = null;
                        rightOld     = null;
                        continue;
                    }

                    Capture(cam, out left, out right, ref cnt);

                    float minL, maxL, minR, maxR;
                    left.GetMinMax(out minL, out maxL);
                    right.GetMinMax(out minR, out maxR);

                    log.Debug("MAX = " + maxL + "   " + maxR);
                    if (maxL == 255f || maxR == 255f)
                    {
                        log.Info("Overexposed, reducing exposure time.");
                        cam.Exposure = cam.Exposure * (3f / 4f);
                        leftOld      = null;
                        rightOld     = null;
                        continue;
                    }
                    if (maxL < DARK_THRES && maxR < DARK_THRES)
                    {
                        if (cam.Exposure < MAX_EXPOSURE)
                        {
                            log.Info("Underexposed, increasing exposure time.");
                            cam.Exposure = cam.Exposure * (4f / 3f);
                            leftOld      = null;
                            rightOld     = null;
                            continue;
                        }

                        log.Info("seems to be dark, let's sleep an hour.");
                        Thread.Sleep(1000 * 60 * 60);
                        leftOld  = null;
                        rightOld = null;
                        continue;
                    }

                    rightOld = Compare(right, rightOld, thres, cnt, "R", log);
                    leftOld  = Compare(left, leftOld, thres, cnt, "L", log);

                    if (null == leftOld || null == rightOld)
                    {
                        break;
                    }
                }
                int   random         = rand.Next(100);
                float delayInMinutes = (float)random / 100f * (float)MAX_DELAY_IN_MIN;
                log.Debug("Sleeping for " + delayInMinutes + " minutes");
                Thread.Sleep((int)(1000 * 60 * delayInMinutes));
                //Thread.Sleep(500);
            }

            cam.Disconnect();
        }