コード例 #1
0
        public static void Main(String[] args)
        {
            ProcessCommandLineArguments(args);


            Environment.SetEnvironmentVariable("NotStudy", "true");

            if (Environment.GetEnvironmentVariables().Contains("ExpSaveDir"))
            {
                string saveDir = Environment.GetEnvironmentVariables()["ExpSaveDir"] as string;
                ExperimentClickFrameSaver.Init(saveDir);
            }

            /*
             * if (Environment.GetEnvironmentVariables().Contains("ExpSaveDir") &&
             *  Environment.GetEnvironmentVariables().Contains("ExpSaveTime"))
             * {
             *  string saveDir = Environment.GetEnvironmentVariables()["ExpSaveDir"] as string;
             *  string saveTime = Environment.GetEnvironmentVariables()["ExpSaveTime"] as string;
             *
             *  int iSaveTime = Int32.Parse(saveTime);
             *  ExperimentFrameSaver.Init(iSaveTime, saveDir);
             * }
             */

            CMSCameraProfile profile = CMSCameraProfile.OneCamera;

            if (Environment.GetEnvironmentVariables().Contains("CameraProfile"))
            {
                try
                {
                    string pa = Environment.GetEnvironmentVariables()["CameraProfile"] as string;
                    profile = (CMSCameraProfile)Enum.Parse(typeof(CMSCameraProfile), pa);
                }
                catch (Exception e)
                {
                }
            }

            if (profile.Equals(CMSCameraProfile.OneCamera))
            {
                CMSController         controller = new CMSController();
                VideoForm             vf         = new VideoForm();
                CMSSingleWebcamSource source     = new CMSSingleWebcamSource();
                CMSControlToggler     ct         = new CMSControlToggler();
                controller.Start(source, vf, ct);
            }
            else if (profile.Equals(CMSCameraProfile.LeftRight))
            {
                CMSController           controller = new CMSController();
                LeftRightWindowsForm    lrvf       = new LeftRightWindowsForm();
                CMSMultipleWebcamSource source     = new CMSMultipleWebcamSource();
                source.Profile = CMSCameraProfile.LeftRight;
                CMSControlToggler ct = new CMSControlToggler();
                controller.Start(source, lrvf, ct);
            }
            else
            {
                CMSController           controller = new CMSController();
                CMSMultipleCameraForm   f          = new CMSMultipleCameraForm();
                CMSMultipleWebcamSource source     = new CMSMultipleWebcamSource();
                source.Profile = profile;
                CMSControlToggler ct = new CMSControlToggler();
                controller.Start(source, f, ct);
            }
        }
コード例 #2
0
        public void Start(CMSVideoSource videoSource, CMSVideoDisplay videoDisplay, CMSControlToggler controlToggler)
        {
            mutex = new object();

            try
            {
                ProcessKeys[] procKeysDelegates = null;
                lock (mutex)
                {
                    CMSConstants.Init();
                    controllerState = CMSState.Starting;


                    model = new CMSModel();
                    model.Init("./" + CMSConstants.SUITE_LIB_DIR, "./" + CMSConstants.SUITE_CONFIG_DIR,
                               "./" + CMSConstants.MAIN_CONFIG_FILE,
                               "./" + CMSConstants.MAIN_CAMERA_CONFIG_FILE,
                               "./" + CMSConstants.MAIN_LOG_CONFIG_FILE,
                               "./" + CMSConstants.MAIN_ID_CONFIG_FILE);

                    model.Load();
                    model.IncrementAndSaveSessionNum();

                    CMSLogger.SetUidReceivedDelegate(model.UidUpdated);
                    CMSLogger.Init(model.LogConfig, model.IdConfig);

                    //CMSLogger.CanCreateLogEvent(

                    if (CMSLogger.CanCreateLogEvent(false, false, false, "CMSLogStartEvent"))
                    {
                        CMSLogStartEvent startEvent = new CMSLogStartEvent();
                        startEvent.SetDateTime(DateTime.Now);
                        CMSLogger.SendLogEvent(startEvent);
                    }

                    this.videoSource         = videoSource;
                    videoSource.CameraLost  += new CameraLost(CameraLost);
                    videoSource.CameraFound += new CameraFound(CameraFound);
                    videoSource.VideoInputSizesDetermined += new VideoInputSizesDetermined(VideoInputSizesDetermined);
                    videoSource.ProcessFrame += new ProcessFrame(ProcessFrameFromSource);
                    videoSource.Init(videoDisplay.GetParentForm());


                    this.videoDisplay = videoDisplay;
                    videoDisplay.Init(new CMSViewAdapter(model, this, videoSource));

                    model.SelectedSuite.CMSTrackingSuiteAdapter = new CMSStandardTrackingSuiteAdapter(model, this, videoDisplay);

                    string currentMoniker = model.CurrentMonikor;
                    if (videoSource.StartSource(currentMoniker))
                    {
                        string newMoniker = videoSource.GetCurrentMonikor();
                        model.CurrentMonikor = newMoniker;
                        controllerState      = CMSState.Setup;
                    }
                    else
                    {
                        controllerState = CMSState.CameraNotFound;
                    }


                    this.controlToggler                 = controlToggler;
                    controlToggler.GetState             = GetState;
                    controlToggler.ToggleControl        = ToggleControl;
                    controlToggler.GetCursorPos         = GetCursorPos;
                    controlToggler.ControlTogglerConfig = model.GeneralConfig.ControlTogglerConfig;
                    controlToggler.Start();


                    procKeysDelegates    = new ProcessKeys[2];
                    procKeysDelegates[0] = ProcessKeys;
                    procKeysDelegates[1] = controlToggler.ProcessKeys;
                }
                CMSKeyHook.initHook(procKeysDelegates);
                Application.Run(videoDisplay.GetParentForm());
                CMSKeyHook.removeHook();
            }
            catch (Exception e)
            {
                try
                {
                    if (CMSLogger.CanCreateLogEvent(true, true, false, "CMSLogExceptionEvent"))
                    {
                        CMSLogExceptionEvent exceptionEvent = new CMSLogExceptionEvent();

                        exceptionEvent.SetException(e);
                        CMSLogger.SendLogEvent(exceptionEvent);
                    }
                }
                catch
                {
                }
                MessageBox.Show("Error occurred during startup:" + e.Message);
                Application.Exit();
            }
        }