コード例 #1
0
        public bool AddCameraConfig(int newCustomId, CameraConfiguration cameraConfig)
        {
            if (cameraConfigurationsMap.ContainsKey(newCustomId))
            {
                return(false);
            }

            cameraConfigurationsMap[newCustomId] = cameraConfig;

            return(true);
        }
コード例 #2
0
        public string LoadCamera(int cameraConfigId, ComputeDeviceInfo computeDeviceInfo, int port)
        {
            try
            {
                if (cameraConfigurationsMap.ContainsKey(cameraConfigId))
                {
                    CameraConfiguration cameraConfig = cameraConfigurationsMap[cameraConfigId];

                    string apiCallBody = "BlankValue";

                    // identify the type
                    switch (cameraConfig.Type)
                    {
                    case "camera":
                        apiCallBody = "{\n\"Fbp\":[\"Start\",\"globals()['cap'] = cv2.VideoCapture({{index}})\\nglobals()['refreshCameraCode'] = 'globals()[\\\\'ret\\\\'], globals()[\\\\'imageSrc\\\\'] = globals()[\\\\'cap\\\\'].read()'\\nglobals()['ret'], globals()['frame'] = globals()['cap'].read()\\nglobals()['imageSrc'] = globals()['frame']\",\"\"],\"RunOnce\": true,\"InfiniteLoop\": false,\"LoopLimit\": 1,\"ReturnResult\": true}";
                        apiCallBody = apiCallBody.Replace("{{index}}", cameraConfig.Index.ToString());
                        break;

                    case "mjpgStream":
                        apiCallBody = "{\n\"Fbp\":[\"Start\",\"globals()['cap'] = cv2.VideoCapture({{url}})\\nglobals()['refreshCameraCode'] = 'globals()[\\\\'ret\\\\'], globals()[\\\\'imageSrc\\\\'] = globals()[\\\\'cap\\\\'].read()'\\nglobals()['ret'], globals()['frame'] = globals()['cap'].read()\\nglobals()['imageSrc'] = globals()['frame']\",\"\"],\"RunOnce\": true,\"InfiniteLoop\": false,\"LoopLimit\": 1,\"ReturnResult\": true}";
                        apiCallBody = apiCallBody.Replace("{{url}}", "'" + cameraConfig.Url + "'");
                        break;

                    case "image":
                        apiCallBody = "{\n\"Fbp\":[\"Start\",\"globals()['imageSrc'] = cv2.imread('{{imageLocalPath}}')\\nglobals()['refreshCameraCode'] = 'globals()[\\\\'imageSrc\\\\'] = cv2.imread(\\\\'{{imageLocalPath}}\\\\')'\",\"\"],\"RunOnce\": true,\"InfiniteLoop\": false,\"LoopLimit\": 1,\"ReturnResult\": true}";
                        apiCallBody = apiCallBody.Replace("{{imageLocalPath}}", cameraConfig.Url);
                        break;

                    case "imageShot":
                        apiCallBody = "{\n\"Fbp\":[\"Start\",\"globals()['imageSrc'] = getImageFromShotUri({{shotUri}})\\nglobals()['refreshCameraCode'] = 'globals()[\\\\'imageSrc\\\\'] = getImageFromShotUri({{shotUri}})'\",\"\"],\"RunOnce\": true,\"InfiniteLoop\": false,\"LoopLimit\": 1,\"ReturnResult\": true}";
                        apiCallBody = apiCallBody.Replace("{{shotUri}}", "'" + cameraConfig.Url + "'");
                        break;
                    }

                    Console.WriteLine("[DEBUG] ApiCallBody(" + computeDeviceInfo.IpAddress + port.ToString() + "): " + apiCallBody);
                    string result = imageClient.MakePostCall("http://{{host}}:{{port}}/task".Replace("{{host}}", computeDeviceInfo.IpAddress).Replace("{{port}}", port.ToString()), apiCallBody);

                    return(result);
                }
            }
            catch (Exception ex)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("[ERROR] ICANSEEUtility.LoadCamera(val=" + cameraConfigId + ", ipAddress=" + computeDeviceInfo.IpAddress + ", port=" + port.ToString() + ") " + ex.Message);
                Console.ResetColor();
            }
            return(null);
        }
コード例 #3
0
        public bool ClearCamera(int cameraId)
        {
            CameraConfiguration cameraConfiguration = null;

            foreach (var camera in OpenCameraMap)
            {
                if (camera.Key.Id == cameraId && camera.Value)
                {
                    cameraConfiguration = camera.Key;
                }
            }

            if (cameraConfiguration != null)
            {
                OpenCameraMap[cameraConfiguration] = false;
            }
            else
            {
                return(false);
            }

            return(true);
        }
コード例 #4
0
 public void AddReplaceCameraConfiguration(int newCustomId, CameraConfiguration cameraConfig)
 {
     this.utility.AddReplaceCameraConfiguration(newCustomId, cameraConfig);
 }
コード例 #5
0
 public bool AddCameraConfiguration(int newCustomId, CameraConfiguration cameraConfig)
 {
     return(this.utility.AddCameraConfig(newCustomId, cameraConfig));
 }
コード例 #6
0
 public void AddReplaceCameraConfiguration(int newCustomId, CameraConfiguration cameraConfig)
 {
     cameraConfigurationsMap[newCustomId] = cameraConfig;
 }
コード例 #7
0
 public void SetCameraActive(CameraConfiguration cameraConfiguration)
 {
     OpenCameraMap[cameraConfiguration] = true;
 }
コード例 #8
0
        // Private ExecutePresetHelper
        private string ExecutePresetHelper(string presetId, CameraConfiguration cameraConfiguration, string postScript)
        {
            int  RunCompatibility      = 0;
            bool targetCameraOpen      = false;
            bool targetAlgorithmActive = false;

            PresetDescription presetConfiguration = utility.QueryPresetById(presetId, brokerHubHost, brokerHubPort);

            if (presetConfiguration == null)
            {
                throw new Exception("Preset not found: " + presetId);
            }

            ComputeDeviceInfo computeDevice = utility.QueryComputeDeviceById(presetConfiguration.ComputeDeviceId);
            int port = presetConfiguration.Port;

            ComputeDeviceState currentState = QueryDeviceState(computeDevice, port);

            logger.LogComputeDeviceStateMap(computeDeviceStateMap, string.Format("QueryDeviceState({0}, {1}) = {2}", computeDevice.ComputeDeviceId, port.ToString(), logger._GetShortFormattedComputeDeviceState(currentState)));

            if (currentState == null)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("[ERROR] ExecutePreset(presetId={0}, cameraId={1}) Failure in current state", presetId, cameraConfiguration.Id);
                Console.ResetColor();
                return(null);
            }

            // Any logic for deciding on run
            // Update statusMap with conditions
            if (!(currentState.IsAnyAlgorithmsActive() || currentState.IsAnyCameraActive() || currentState.IsAnyPresetActive()))
            {
                RunCompatibility = 1;
            }
            // If same algorithm, camera is there but preset is over, then run
            else if (currentState.IsAlgorithmActive(presetConfiguration.AlgorithmId) && currentState.IsCameraActive(cameraConfiguration.Id) && !(currentState.IsPresetActive(presetId)))
            {
                RunCompatibility = 2;
            }
            else
            {
                RunCompatibility = 5;

                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("[FIX NEEDED] ExecutePreset(presetId={0}, cameraId={1}) Backdoor activated for allowing execution", presetId, cameraConfiguration.Id);
                Console.ResetColor();
            }

            if (currentState.IsCameraActive(cameraConfiguration.Id))
            {
                targetCameraOpen = true;
            }
            if (currentState.IsAlgorithmActive(presetConfiguration.AlgorithmId))
            {
                targetAlgorithmActive = true;
            }


            // If run compatibility satisfies, run the algorithm in specific compute device
            if (RunCompatibility > 0)
            {
                string result = "";

                // If camera already not loaded, call LoadCamera
                if (!targetCameraOpen)
                {
                    result = utility.LoadCamera(cameraConfiguration.Id, computeDevice, port);
                    if (result == null)
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("[ERROR] ExecutePreset(presetId={0}, cameraId={1}) LoadCamera() Failed", presetId, cameraConfiguration.Id);
                        Console.ResetColor();
                        return(null);
                    }
                    else
                    {
                        computeDeviceStateMap[computeDevice][port].SetCameraActive(cameraConfiguration);
                        logger.LogComputeDeviceStateMap(computeDeviceStateMap, string.Format("SetCameraActive={0}", cameraConfiguration.Id + "," + cameraConfiguration.Label));
                    }
                }


                // If preset request to run ScalarExecuteCommand attribute, call the InitCommandFirst
                if (!targetAlgorithmActive)
                {
                    result = utility.ExecuteAlgorithm(presetConfiguration, computeDevice.IpAddress, "InitCommand");

                    if (result == null)
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("[ERROR] ExecutePreset(presetId={0}, cameraId={1}) InitAlgo Failed", presetId, cameraConfiguration.Id);
                        Console.ResetColor();
                        return(null);
                    }
                }

                computeDeviceStateMap[computeDevice][port].SetPresetActive(presetConfiguration, utility.GetAlgorithmsList());
                presetCameraMap[presetId] = cameraConfiguration;
                logger.LogComputeDeviceStateMap(computeDeviceStateMap, "SetPresetActive=" + presetConfiguration.Id + "," + presetConfiguration.Name);

                // If preset is one time run, then clear preset from the statusMap
                if (presetConfiguration.ReturnResult && !presetConfiguration.InfiniteLoop && (presetConfiguration.RunOnce || presetConfiguration.LoopLimit == 1))
                {
                    computeDeviceStateMap[computeDevice][port].ClearPreset(presetConfiguration.Id);
                    logger.LogComputeDeviceStateMap(computeDeviceStateMap, "One Run ClearPreset=" + presetConfiguration.Id + "," + presetConfiguration.Name);
                }


                if (postScript == null)
                {
                    result = utility.ExecuteAlgorithm(presetConfiguration, computeDevice.IpAddress);
                }
                else
                {
                    result = utility.ExecuteAlgorithm(presetConfiguration, computeDevice.IpAddress, resultStatementToOverride: postScript);
                }


                if (result == null)
                {
                    computeDeviceStateMap[computeDevice][port].ClearPreset(presetConfiguration.Id);
                    logger.LogComputeDeviceStateMap(computeDeviceStateMap, "Preset Failure ClearPreset=" + presetConfiguration.Id + "," + presetConfiguration.Name);


                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("[ERROR] ExecutePreset(presetId={0}, cameraId={1}) Preset Execution Failed", presetId, cameraConfiguration.Id);
                    Console.ResetColor();

                    return(null);
                }

                return(result);
            }

            return(null);
        }
コード例 #9
0
 public string ExecutePreset(string presetId, CameraConfiguration cameraConfiguration)
 {
     return(ExecutePresetHelper(presetId, cameraConfiguration, null));
 }
コード例 #10
0
 public string ExecutePresetExtended(string presetId, CameraConfiguration cameraConfiguration, string postScript)
 {
     return(ExecutePresetHelper(presetId, cameraConfiguration, postScript));
 }