Ejemplo n.º 1
0
    /// <summary>
    /// Creates an OpenCV matrix based on the ZED camera's rectified parameters. This is specific to each camera.
    /// </summary>
    private void Initialize()
    {
        zedCam = zedManager.zedCamera;
        sl.CameraParameters camparams = zedCam.CalibrationParametersRectified.leftCam;

        //Shorthand.
        double fx = camparams.fx;
        double fy = camparams.fy;
        double cx = camparams.cx;
        double cy = camparams.cy;

        //Build a rough 3x3 matrix for OpenCV with the camera's parameters.
        camMat = new Mat(3, 3, CvType.CV_64FC1);

        camMat.put(0, 0, fx);
        camMat.put(0, 1, 0);
        camMat.put(0, 2, cx);
        camMat.put(1, 0, 0);
        camMat.put(1, 1, fy);
        camMat.put(1, 2, cy);
        camMat.put(2, 0, 0);
        camMat.put(2, 1, 0);
        camMat.put(2, 2, 0.0f);

        Size imageSize = new Size(zedCam.ImageWidth, zedCam.ImageHeight);

        //Make ZED and OpenCV versions of the image matrices.
        //Each grab, we'll fill the zedMat from the ZED SDK, copy it to cvMat, and run marker detection on it.
        //8U_C1(8 bits, one channel) as we're using a grayscale image for performance.
        //zedMat = new ZEDMat((uint)zedCam.ImageWidth, (uint)zedCam.ImageHeight, sl.ZEDMat.MAT_TYPE.MAT_8U_C1);
        //cvMat = SLMat2CVMat(zedMat, ZEDMat.MAT_TYPE.MAT_8U_C1);

        isInit = true;
    }
Ejemplo n.º 2
0
 /// <summary>
 /// Gets an instance of camera
 /// </summary>
 public static ZEDCamera GetInstance()
 {
     if (instance == null)
     {
         instance = new ZEDCamera();
     }
     return instance;
 }
Ejemplo n.º 3
0
 public void setConnectStatus(bool isConnected)
 {
     m_isConnected = isConnected;
     if (isConnected == false && m_camera != null)
     {
         m_camera = null;
     }
 }
    private void Awake()
    {
        oldInitStatus = ERROR_CODE.ERROR_CODE_LAST;
        if (!ZEDManager.IsStereoRig) //Without VR, we use a Screen Space - Overlay canvas.
        {
            warningmono = Instantiate(Resources.Load("PrefabsUI/Warning") as GameObject, transform);
            warningmono.SetActive(true);
            textmono       = warningmono.GetComponentInChildren <Text>();
            textmono.color = Color.white;

            if (!ZEDCamera.CheckPlugin())
            {
                textmono.text = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.SDK_NOT_INSTALLED);
            }
            imagemono = warningmono.transform.GetChild(0).GetChild(1).gameObject;
            imagemono.transform.parent.gameObject.SetActive(true);
            ready = false;
        }
        else //In VR, we use two Screen Space - Camera canvases, one for each eye.
        {
            //Setup the left warning prefab
            warningleft = Instantiate(Resources.Load("PrefabsUI/Warning_VR") as GameObject,
                                      ZEDManager.Instance.GetLeftCameraTransform());
            warningleft.SetActive(true);
            warningleft.GetComponent <Canvas>().worldCamera =
                ZEDManager.Instance.GetLeftCameraTransform().GetComponent <Camera>();
            warningleft.GetComponent <Canvas>().planeDistance = 1;
            textleft       = warningleft.GetComponentInChildren <Text>();
            textleft.color = Color.white;
            imageleft      = warningleft.transform.GetChild(0).GetChild(1).gameObject;
            imageleft.transform.parent.gameObject.SetActive(true);

            //Setup the right warning prefab
            warningright = Instantiate(Resources.Load("PrefabsUI/Warning_VR") as GameObject,
                                       ZEDManager.Instance.GetRightCameraTransform());
            warningright.SetActive(true);
            warningright.GetComponent <Canvas>().worldCamera =
                ZEDManager.Instance.GetRightCameraTransform().GetComponent <Camera>();
            warningright.GetComponent <Canvas>().planeDistance = 1;
            textright       = warningright.GetComponentInChildren <Text>();
            textright.color = Color.white;
            imageright      = warningright.transform.GetChild(0).GetChild(1).gameObject;
            imageright.transform.parent.gameObject.SetActive(true);

            if (!ZEDCamera.CheckPlugin())
            {
                textleft.text  = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.SDK_NOT_INSTALLED);
                textright.text = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.SDK_NOT_INSTALLED);
            }

            ready = false;
        }
    }
Ejemplo n.º 5
0
        public CameraParas GetCameraPara()
        {
            ZEDCamera             zedCam  = zedManager.zedCamera;
            CalibrationParameters para    = zedCam.GetCalibrationParameters();
            CameraParas           fypPara = new CameraParas();

            fypPara.cx = para.leftCam.cx;
            fypPara.cy = para.leftCam.cy;
            fypPara.fx = para.leftCam.fx;
            fypPara.fy = para.leftCam.fy;
            fypPara.ResolutionWidth  = (int)para.leftCam.resolution.width;
            fypPara.ResolutionHeight = (int)para.leftCam.resolution.height;
            return(fypPara);
        }
Ejemplo n.º 6
0
        public Zed(InitParameters parameters = null, string svoPath = null)
        {
            camera = ZEDCamera.GetInstance();

            mats = new List <ZEDMat>();

            if (parameters == null)
            {
                parameters                        = new InitParameters();
                parameters.resolution             = RESOLUTION.HD720;
                parameters.depthMode              = DEPTH_MODE.QUALITY;
                parameters.depthStabilization     = true;
                parameters.enableRightSideMeasure = true; // isStereoRig;

                parameters.coordinateUnit       = UNIT.MILLIMETER;
                parameters.depthMinimumDistance = 200f;
                //parameters.depthMinimumDistance = 0.2f;
            }

            if (svoPath != null)
            {
                parameters.pathSVO = svoPath;
            }

            this.initParameters = parameters;

            // runtime parameters
            runtimeParameters = new RuntimeParameters()
            {
                sensingMode = SENSING_MODE.FILL,
                enableDepth = true
            };

            // create the camera
            camera.CreateCamera(true);
        }
Ejemplo n.º 7
0
 private void button1_Click(object sender, EventArgs e)
 {
     MessageBox.Show("Is: " + ZEDCamera.CheckPlugin());
 }
Ejemplo n.º 8
0
 private void Start()
 {
     manager        = FindObjectOfType(typeof(ZEDManager)) as ZEDManager;
     spatialMapping = new ZEDSpatialMapping(transform, ZEDCamera.GetInstance(), manager);
 }
Ejemplo n.º 9
0
    public override void OnInspectorGUI()
    {
        var cameraIsReady = ZEDCamera.GetInstance().IsCameraReady;

        displayText = ZEDSpatialMapping.display ? "Hide Mesh" : "Display Mesh";
        serializedObject.Update();
        EditorGUILayout.BeginHorizontal();

        GUILayout.Label("Mesh Parameters", EditorStyles.boldLabel);
        EditorGUILayout.EndHorizontal();
        EditorGUILayout.BeginHorizontal();
        GUILayout.FlexibleSpace();
        EditorGUILayout.EndHorizontal();

        var newResolution =
            (ZEDSpatialMapping.RESOLUTION)EditorGUILayout.EnumPopup("Resolution", spatialMapping.resolution_preset);

        if (newResolution != spatialMapping.resolution_preset)
        {
            resolution.enumValueIndex = (int)newResolution;
            serializedObject.ApplyModifiedProperties();
        }

        var newRange = (ZEDSpatialMapping.RANGE)EditorGUILayout.EnumPopup("Range", spatialMapping.range_preset);

        if (newRange != spatialMapping.range_preset)
        {
            range.enumValueIndex = (int)newRange;
            serializedObject.ApplyModifiedProperties();
        }

        EditorGUILayout.BeginHorizontal();
        filterParameters.enumValueIndex =
            (int)(FILTER)EditorGUILayout.EnumPopup("Mesh Filtering", (FILTER)filterParameters.enumValueIndex);
        isFilteringEnable.boolValue = true;


        EditorGUILayout.EndHorizontal();

        GUI.enabled = !spatialMapping.IsRunning;

        isTextured.boolValue = EditorGUILayout.Toggle("Texturing", isTextured.boolValue);

        GUI.enabled = cameraIsReady;

        EditorGUILayout.BeginHorizontal();
        if (!spatialMapping.IsRunning)
        {
            if (GUILayout.Button("Start Spatial Mapping"))
            {
                if (!ZEDSpatialMapping.display)
                {
                    spatialMapping.SwitchDisplayMeshState(true);
                }
                spatialMapping.StartSpatialMapping();
            }
        }
        else
        {
            if (spatialMapping.IsRunning && !spatialMapping.IsUpdateThreadRunning ||
                spatialMapping.IsRunning && spatialMapping.IsTexturingRunning)

            {
                GUILayout.FlexibleSpace();
                GUILayout.Label("Spatial mapping is finishing");
                Repaint();
                GUILayout.FlexibleSpace();
            }
            else
            {
                if (GUILayout.Button("Stop Spatial Mapping"))
                {
                    spatialMapping.StopSpatialMapping();
                }
            }
        }

        EditorGUILayout.EndHorizontal();

        GUI.enabled = cameraIsReady;
        if (GUILayout.Button(displayText))
        {
            spatialMapping.SwitchDisplayMeshState(!ZEDSpatialMapping.display);
        }
        GUI.enabled = true;
        GUILayout.Label("Mesh Storage", EditorStyles.boldLabel);
        saveWhenOver.boolValue = EditorGUILayout.Toggle("Save Mesh (when stop)", saveWhenOver.boolValue);


        EditorGUILayout.BeginHorizontal();

        meshPath.stringValue = EditorGUILayout.TextField("Mesh Path", meshPath.stringValue);

        if (GUILayout.Button("...", optionsButtonBrowse))
        {
            meshPath.stringValue = EditorUtility.OpenFilePanel("Mesh file", "", "ply,obj,bin");
            serializedObject.ApplyModifiedProperties();
        }

        EditorGUILayout.EndHorizontal();
        EditorGUILayout.BeginHorizontal();
        //GUI.enabled = cameraIsReady;
        GUILayout.FlexibleSpace();

        GUI.enabled = File.Exists(meshPath.stringValue) && cameraIsReady;
        if (GUILayout.Button("Load"))
        {
            spatialMapping.LoadMesh(meshPath.stringValue);
        }

        EditorGUILayout.EndHorizontal();

        serializedObject.ApplyModifiedProperties();

        if (!cameraIsReady)
        {
            Repaint();
        }
    }
Ejemplo n.º 10
0
 public void setCamera(ZEDCamera camera)
 {
     m_camera = camera;
 }