Beispiel #1
0
        /// <summary>
        /// Scans for connectable cameras.
        /// </summary>
        /// <returns>true.</returns>
        /// <remarks>The return value is necessary as this method can be called in a splash screen and has to be able to report its success.</remarks>
        public static bool ScanForConnectableCameras()
        {
            log.Info("Scanning for available camera assemblies...");

            // force new initialization with ScanForCameraDlls true
            GetInstance().InitializeCameras(true);

            List <Camera> cameras = GetInstance().AvailableCameras;

            log.Info(cameras.Count + " cameras available:");
            log.Info(String.Join(" / ", cameras.Select(f => f.Name).ToArray()));
            log.Info("Detecting connectable cameras...");

            connectableCameras = new List <Camera>();

            foreach (var item in cameras)
            {
                try
                {
                    item.Connect();
                    log.Info(item.Name + " available for connection.");
                    item.Disconnect();
                    connectableCameras.Add(item);
                }
                catch
                {
                    /* empty */
                }
            }
            return(true);
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            log.SetLogLevel(log4net.Core.Level.Debug);

            SVS cam = new SVS();

            try
            {
                cam.Connect();
            }
            catch (MetriCam2.Exceptions.ConnectionFailedException e)
            {
                log.FatalFormat("Could not connect to camera: {0}", e.Message);
                return;
            }
            log.InfoFormat("Camera connected: {0} (S/N {1})", cam.Name, cam.SerialNumber);

            //log.DebugFormat("activating software trigger (current setting: {0})", cam.AcquisitionMode);
            cam.SetParameter("AutoGain", false);
            //log.DebugFormat("activated software trigger (current setting: {0})", cam.AcquisitionMode);

            cam.SetParameter("Exposure", 5.0f * 1000f);
            log.DebugFormat("exposure: {0}", cam.Exposure);

            log.DebugFormat("activating software trigger (current setting: {0})", cam.AcquisitionMode);
            cam.AcquisitionMode = MetriCam2.Cameras.Internal.SVS.GigeApi.ACQUISITION_MODE.ACQUISITION_MODE_SOFTWARE_TRIGGER;
            log.DebugFormat("activated software trigger (current setting: {0})", cam.AcquisitionMode);

            Console.WriteLine("Press Esc to quit. Press any other key to capture a frame.");
            while (true)
            {
                ConsoleKeyInfo key = Console.ReadKey();
                if (key.Key == ConsoleKey.Escape)
                {
                    break;
                }

                cam.Update();
                log.InfoFormat("Updated camera. Frame number is {0}", cam.FrameNumber);
                //cam.CalcChannel()
            }

            cam.Disconnect();
            log.Info("Camera disconnected");
        }
Beispiel #3
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();
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            log.SetLogLevel(log4net.Core.Level.Info);

            cam = new UEyeCamera(); // Change this type if you want to test your camera implementation.
            List <Camera.ParamDesc> allParameters;

            log.Info("Testing " + cam.Name);

            allParameters = cam.GetParameters();
            log.InfoFormat("Camera {0} has {1} parameter(s):\n{2}", cam.Name, allParameters.Count, Camera.ParamDesc.ToString(allParameters));


            // TEST: setting a writable parameter while disconnected
            if (cam is UEyeCamera)
            {
                TestSetParameterSuccess("TriggerMode", "SOFTWARE");
            }

            // TEST: setting a non-writable parameter while disconnected
            TestSetParameterDisconnected("Gain", 40);

            cam.Connect();

            log.InfoFormat("Connected {0} camera with S/N \"{1}\".", cam.Name, cam.SerialNumber);

            allParameters = cam.GetParameters();
            log.InfoFormat("Camera {0} has {1} parameter(s):\n{2}", cam.Name, allParameters.Count, Camera.ParamDesc.ToString(allParameters));

            if (cam is UEyeCamera)
            {
                // TEST: setting a list parameter to a valid value.
                TestSetParameterSuccess("TriggerMode", "HARDWARE");

                // TEST: setting a list parameter to an invalid value.
                TestSetParameterToInvalid("TriggerMode", "---");
            }

            // TEST: setting a range parameter to a valid value.
            TestSetParameterSuccess("Gain", 40);

            // TEST: setting a range parameter to an invalid value.
            TestSetParameterToInvalid("Gain", 305);

            // TEST: setting an Auto* parameter to a valid value
            TestSetParameterSuccess("AutoGain", true);

            // TEST: setting an Auto* parameter to an invalid value
            TestSetParameterToInvalid("AutoGain", 13);

            Dictionary <string, object> params1 = new Dictionary <string, object>();

            params1["Gain"]     = 40;
            params1["AutoGain"] = true;
            if (cam is UEyeCamera)
            {
                params1["TriggerMode"] = "FREERUN";
            }
            cam.SetParameters(params1);
            List <Camera.ParamDesc> allParameters1 = cam.GetParameters();

            log.InfoFormat("Camera {0} has {1} parameter(s):\n{2}", cam.Name, allParameters1.Count, Camera.ParamDesc.ToString(allParameters1));

            Dictionary <string, object> params2 = new Dictionary <string, object>();

            params2["Gain"]     = 40;
            params2["AutoGain"] = false;
            if (cam is UEyeCamera)
            {
                params2["TriggerMode"] = "FREERUN";
            }
            cam.SetParameters(params2);
            List <Camera.ParamDesc> allParameters2 = cam.GetParameters();

            log.InfoFormat("Camera {0} has {1} parameter(s):\n{2}", cam.Name, allParameters2.Count, Camera.ParamDesc.ToString(allParameters2));

            cam.Disconnect();

            log.Info("Press any key to close.");
            Console.ReadKey();
        }
Beispiel #5
0
        private static void TestBoolParam()
        {
            string paramName = "BoolParam";

            log.Info("Testing a ParamDesc<bool>");

            SetParameterToValid(paramName, true);
            SetParameterToValid(paramName, false);

            SetParameterToInvalid(paramName, -1);
            SetParameterToInvalid(paramName, 0);
            SetParameterToInvalid(paramName, 1);
            SetParameterToInvalid(paramName, 2);

            SetParameterToInvalid(paramName, -1f);
            SetParameterToInvalid(paramName, 0f);
            SetParameterToInvalid(paramName, 1f);
            SetParameterToInvalid(paramName, 2f);

            SetParameterToValid(paramName, "true");
            SetParameterToValid(paramName, "True");
            SetParameterToValid(paramName, "TRUE");

            SetParameterToValid(paramName, "false");
            SetParameterToValid(paramName, "False");
            SetParameterToValid(paramName, "FALSE");

            SetParameterToInvalid(paramName, "on");
            SetParameterToInvalid(paramName, "On");
            SetParameterToInvalid(paramName, "ON");

            SetParameterToInvalid(paramName, "off");
            SetParameterToInvalid(paramName, "Off");
            SetParameterToInvalid(paramName, "OFF");

            SetParameterToInvalid(paramName, "-1");
            SetParameterToInvalid(paramName, "0");
            SetParameterToInvalid(paramName, "1");
            SetParameterToInvalid(paramName, "2");
        }
Beispiel #6
0
        static void Main(string[] args)
        {
            MetriLog log = new MetriLog();

            Kinect2 cam = new Kinect2();

            try
            {
                cam.Connect();
            }
            catch (MetriCam2.Exceptions.ConnectionFailedException)
            {
                log.Error("Connection failed. Closing window in 5 sec.");
                Thread.Sleep(5 * 1000);
                return;
            }

            cam.ActivateChannel(ChannelNames.Color);

            bool running = false;

            while (running)
            {
                cam.Update();
            }

            ProjectiveTransformationZhang pt;

            try
            {
                pt = (ProjectiveTransformationZhang)cam.GetIntrinsics(ChannelNames.Color);
            }
            catch (FileNotFoundException)
            {
                log.Warn("No PT found.");
            }
            try
            {
                pt = (ProjectiveTransformationZhang)cam.GetIntrinsics(ChannelNames.Color);
            }
            catch (FileNotFoundException)
            {
                log.Warn("No PT found.");
            }
            try
            {
                pt = (ProjectiveTransformationZhang)cam.GetIntrinsics(ChannelNames.Color);
            }
            catch (FileNotFoundException)
            {
                log.Warn("No PT found.");
            }

            try
            {
                RigidBodyTransformation rbt = cam.GetExtrinsics(ChannelNames.Color, ChannelNames.ZImage);
            }
            catch (FileNotFoundException)
            {
                log.Warn("No fwd RBT found.");
            }

            try
            {
                RigidBodyTransformation rbtInverse = cam.GetExtrinsics(ChannelNames.ZImage, ChannelNames.Color);
            }
            catch (FileNotFoundException)
            {
                log.Warn("No inverse RBT found.");
            }

            cam.Disconnect();

            log.Info("Program ended. Closing window in 5 sec.");
            Thread.Sleep(5 * 1000);
        }