Exemplo n.º 1
0
        public void ExecuteFFMPEG()
        {
            VirtualCVLog.Log("Execute ffmpeg");

            // libx264 : mpegts
            // jpg : mjpeg
            string[] ffmpegOptions =
            {
                "-re",
                "-stream_loop","-1",
                "-i",          "pipe:",
                "-c:v",        "jpg",
                "-vf",         $"fps={FPS}",
                "-c:v",        "mjpeg",
                "-preset",     "veryfast",
                "-f",          "mjpeg",
                $"{URL}:{Port}"
            };

            ffmpegProcess.StartInfo.FileName               = Path.Combine(ffmpegPath, "ffmpeg.exe");
            ffmpegProcess.StartInfo.Arguments              = string.Join(" ", ffmpegOptions);
            ffmpegProcess.StartInfo.WorkingDirectory       = ffmpegPath;
            ffmpegProcess.StartInfo.UseShellExecute        = false;
            ffmpegProcess.StartInfo.RedirectStandardInput  = true;
            ffmpegProcess.StartInfo.RedirectStandardOutput = true;
            ffmpegProcess.StartInfo.CreateNoWindow         = true;

            ffmpegProcess.Start();

            ffmpegStreamWriter = ffmpegProcess.StandardInput;
        }
Exemplo n.º 2
0
        void SetCamera()
        {
            cam = GetComponent <Camera>();

            cam.fieldOfView           = VirtualCVSettings.GetParam().fov;
            cam.usePhysicalProperties = VirtualCVSettings.GetParam().usePhysicalCamera;
            cam.focalLength           = VirtualCVSettings.GetParam().focal_length;

            VirtualCVLog.Log($"Camera info : {name} - {cam.fieldOfView} - {cam.usePhysicalProperties} - {cam.focalLength}");
        }
Exemplo n.º 3
0
        void TakeScreenshot()
        {
            screenshotIndex++;
            string isRight            = (isRightCamera ? "right" : "left");
            string screenshotFileName = Path.Combine(screenshotPath, string.Format($"Screenshot_{isRight}_{screenshotIndex}.jpg"));

            VirtualCVLog.Log($"Screenshot saved : path - {screenshotFileName}");

            File.WriteAllBytes(screenshotFileName, cameraImage.EncodeToJPG());
        }
Exemplo n.º 4
0
        public static void WebSocketProc()
        {
            VirtualCVLog.Log("Start WebSocket Server");

            string serverURL = $"{URL}:{Port}";

            webSocketServer = new WebSocketServer(serverURL);
            webSocketServer.AddWebSocketService <Data>("/Data");
            webSocketServer.Start();
        }
Exemplo n.º 5
0
        void OnGUI()
        {
            GUILayout.Label("Camera settings", EditorStyles.boldLabel);

            param.usePhysicalCamera = EditorGUILayout.Toggle("Use physical camera", param.usePhysicalCamera);
            param.useDepthCameara   = EditorGUILayout.Toggle("Use depth camera", param.useDepthCameara);

            EditorGUILayout.Space();

            param.textureWidth  = EditorGUILayout.IntField("Texture width", param.textureWidth);
            param.textureHeight = EditorGUILayout.IntField("Texture height", param.textureHeight);

            EditorGUILayout.Space();

            param.fov          = EditorGUILayout.FloatField("Field of view", param.fov);
            param.fps          = EditorGUILayout.IntField("FPS", param.fps);
            param.focal_length = EditorGUILayout.FloatField("Focal length", param.focal_length);

            EditorGUILayout.Space();

            param.useStereoCamera = EditorGUILayout.Toggle("Use stereo camera", param.useStereoCamera);
            param.ipd             = EditorGUILayout.FloatField("Interpupillary distance", param.ipd);

            EditorGUILayout.Space();

            if (GUILayout.Button("Save settings"))
            {
                VirtualCVLog.Log("Settings saved");
                VirtualCVSettings.SaveSettings(param);
            }
            if (GUILayout.Button("Apply to camera"))
            {
                ApplyCamera();
            }

            EditorGUILayout.Space();

            int selectedPythonScript = GetPythonScriptIndex(param.python_script);

            selectedPythonScript = EditorGUILayout.Popup("Python script", selectedPythonScript, pythonFiles);
            param.python_script  = pythonFiles[selectedPythonScript];
            if (GUILayout.Button("Launch the script"))
            {
                if (Application.isPlaying)
                {
                    PythonExecutor.getInstance().ExecutePython(param.python_script);
                }
                else
                {
                    VirtualCVLog.LogE("It's able to run only when Unity is playing.");
                }
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Execute python script
        /// </summary>
        /// <param name="scriptFile">python script file name, default is opencv.py</param>
        public void ExecutePython(string pythonScriptFile)
        {
            VirtualCVLog.Log("Execute python script : " + pythonScriptFile);

            string useStereo = VirtualCVSettings.GetParam().useStereoCamera ? "stereo" : "";

            pythonProcess.StartInfo.FileName               = pythonExe;
            pythonProcess.StartInfo.WorkingDirectory       = pythonScriptPath;
            pythonProcess.StartInfo.Arguments              = $"{pythonScriptFile} {useStereo}";
            pythonProcess.StartInfo.UseShellExecute        = false;
            pythonProcess.StartInfo.RedirectStandardOutput = true;
            pythonProcess.StartInfo.CreateNoWindow         = true;

            pythonProcess.Start();
        }
Exemplo n.º 7
0
        void Start()
        {
            VirtualCVLog.Log("VirtualCVCamera starts");

            bool useStereo = VirtualCVSettings.GetParam().useStereoCamera;

            isRightCamera = (name == "VirtualCVCameraRight");
            if (isRightCamera && !useStereo)
            {
                return;
            }

            SetCamera();
            SetTexture();

            screenshotPath = Path.Combine(Application.dataPath, "..", "Screenshot");
            Directory.CreateDirectory(screenshotPath);

            int port = isRightCamera ? rightCameraPort : leftCameraPort;

            ffmpegExecutor = new FFMPEGExecutor(port);
            ffmpegExecutor.Initialze();
            ffmpegExecutor.ExecuteFFMPEG();
        }
Exemplo n.º 8
0
 public void Initialze()
 {
     VirtualCVLog.Log("ffmpeg path : " + ffmpegPath);
 }