// void ArucoDetection() {
        //     // Detect ArUco markers
        //     Dictionary dict = Aruco.getPredefinedDictionary(Aruco.DICT_4X4_1000);
        //     Aruco.detectMarkers(cached_initMat, dict, corners, ids);
        //     Aruco.drawDetectedMarkers(cached_initMat, corners, ids);
        //     // Debug.Log("AD - 93: Markers Detected");
        //     // Debug.LogFormat("Corners: {0}", corners.Count);

        //     // Get desired corner of marker
        //     Point[] src_point_array = new Point[POINT_COUNT];
        //     for (int i = 0; i < corners.Count; i++) {
        //         int aruco_id = (int) (ids.get(i, 0)[0]);
        //         int src_i = arucoTosrc(aruco_id);
        //         int corner_i = aruco_id % 4;

        //         // Debug.LogFormat("AD - 101: aruco_id: {0}; corner_i: {1}; src_i: {2}", aruco_id, corner_i, src_i);

        //         // Store corner[i] into spa[src_i]
        //         src_point_array[src_i] = new Point(corners[i].get(0, corner_i)[0], corners[i].get(0, corner_i)[1]);

        //         // Display the corner as circle on outMat.
        //         Imgproc.circle(cached_initMat, src_point_array[src_i], 10, new Scalar(255, 255, 0));
        //     }

        //     // Converting to Ray values for Raycast
        //     Camera _cam = Camera.main;
        //     if (_cam != null) {
        //         for (int i = 0; i < POINT_COUNT; i++) {
        //             if (src_point_array[i] != null) {
        //                 src_ray_array[i] = _cam.ScreenPointToRay(
        //                     new Vector3((float) src_point_array[i].x,(float) src_point_array[i].y, 0)).direction;
        //             }
        //         }
        //     }
        //     // Debug.LogFormat("Detected Direction: {0}", src_ray_array[0]);
        //     // Debug.LogFormat("Camera Direction: {0}", _cam.transform.forward);

        //     // Count non-null source points
        //     bool spa_full = (count_src_nulls() == 7);

        //     // Check if have valid faces
        //     for (int i = 0; i < FACE_COUNT; i++) {
        //         // faceX_full[i] = check_faces(i);
        //         faceX_full[i] = check_faces(i);
        //     }

        //     // Core.flip(cached_initMat, outMat, 0);
        // }

        /// Sets the projected ScreenPoints of the world coordinate values in src_world_array
        /// from the PoV of the RGB Camera.
        void SetC1ScreenPoints()
        {
            Camera _camera = Camera.main;

            MatrixToTransform(camera_pose, rgb_camera);

            Debug.LogFormat("Camera Pose: {0} \n old transform: {1}, {2}, {3} \n new transform: {4}, {5}, {6}", camera_pose, _camera.transform.position, _camera.transform.rotation, _camera.transform.localScale, rgb_camera.transform.position, rgb_camera.transform.rotation, rgb_camera.transform.localScale);

            MLCVCameraIntrinsicCalibrationParameters intrinsicParam;

            MLCamera.GetIntrinsicCalibrationParameters(out intrinsicParam);

            Debug.LogFormat("Camera Pose: {0} \n Left Eye Pose: {1} \n Intrinsics: FOV -- {5} vs {2} \n Focal Length -- {6} vs. {3} \n Principal Point -- {7} vs. {4} \n Sensor Size {8} vs. {9} x {10} \n Camera Size: {11} x {12} \n Camera Rect: {13}",
                            camera_pose,
                            rgb_camera.GetStereoViewMatrix(Camera.StereoscopicEye.Left),
                            intrinsicParam.FOV, intrinsicParam.FocalLength, intrinsicParam.PrincipalPoint,
                            _camera.fieldOfView, _camera.focalLength, _camera.lensShift,
                            _camera.sensorSize, intrinsicParam.Width, intrinsicParam.Height,
                            rgb_camera.pixelWidth, rgb_camera.pixelHeight,
                            rgb_camera.pixelRect);

            rgb_camera.fieldOfView           = intrinsicParam.FOV;
            rgb_camera.focalLength           = intrinsicParam.FocalLength.x;
            rgb_camera.sensorSize            = new Vector2(intrinsicParam.Width, intrinsicParam.Height);
            rgb_camera.usePhysicalProperties = true;

            for (int i = 0; i < POINT_COUNT; i++)
            {
                Vector3 world_pos  = src_world_array[i];
                Vector3 c1_vector3 = rgb_camera.WorldToScreenPoint(world_pos);
                c1_point_array[i] = new Point(((c1_vector3.x * 2) - 128) / SCALE_FACTOR, (c1_vector3.y * 2) / SCALE_FACTOR);
            }
        }
示例#2
0
    /// <summary>
    /// Once privileges have been granted, enable the camera and callbacks.
    /// </summary>
    private void StartCapture()
    {
        if (!_hasStarted)
        {
            lock (_cameraLockObject)
            {
                EnableMLCamera();
                MLCVCameraIntrinsicCalibrationParameters cameraIntrinsics;
                MLCamera.GetIntrinsicCalibrationParameters(out cameraIntrinsics);

                Debug.Log("Camera is connected:" + cameraIntrinsics.FOV);
                _results.cameraIntrinsics = new SerializableCameraIntrinsics
                {
                    Distortion     = cameraIntrinsics.Distortion,
                    FocalLength    = cameraIntrinsics.FocalLength,
                    FOV            = cameraIntrinsics.FOV,
                    Height         = cameraIntrinsics.Height,
                    PrincipalPoint = cameraIntrinsics.PrincipalPoint,
                    Width          = cameraIntrinsics.Width
                };

                MLCamera.OnRawImageAvailable += OnCaptureRawImageComplete;
                MLCamera.OnCaptureCompleted  += OnCaptureCompleted;
            }
            MLInput.OnControllerButtonDown += OnButtonDown;

            _hasStarted = true;
        }
    }
        /// <summary>
        /// Setup the text field for camera intrinsic values.
        /// Precondition: MLCamera must be successfully started.
        /// </summary>
        void SetupCameraIntrinsics()
        {
            MLCVCameraIntrinsicCalibrationParameters parameters;
            MLResult result = MLCamera.GetIntrinsicCalibrationParameters(out parameters);

            if (result.IsOk)
            {
                _intrinsicValuesText.text = CalibrationParametersToString(parameters);
            }
            else
            {
                Debug.LogErrorFormat("Error: RawVideoCaptureExample failed to GetIntrinsicCalibrationParameters. Reason: {0}", result);
            }
        }