private void UpdateWordResultPoses(Camera arCamera, IEnumerable <QCARManagerImpl.WordResultData> wordResults)
    {
        QCARBehaviour qcarbehaviour = (QCARBehaviour)Object.FindObjectOfType(typeof(QCARBehaviour));

        if (qcarbehaviour == null)
        {
            Debug.LogError("QCAR Behaviour could not be found");
            return;
        }

        // required information to transform camera frame coordinates into screen space coordinates:
        Rect bgTextureViewPortRect = qcarbehaviour.GetViewportRectangle();
        bool isMirrored            = qcarbehaviour.VideoBackGroundMirrored;

        CameraDevice.VideoModeData videoModeData = qcarbehaviour.GetVideoMode();

        foreach (var wrd in wordResults)
        {
            var wordResult = (WordResultImpl)mTrackedWords[wrd.id];

            var position = arCamera.transform.TransformPoint(wrd.pose.position);

            var wrdOrientation = wrd.pose.orientation;
            var rotation       = arCamera.transform.rotation *
                                 wrdOrientation *
                                 Quaternion.AngleAxis(270, Vector3.left);

            wordResult.SetPose(position, rotation);
            wordResult.SetStatus(wrd.status);

            var obb = new OrientedBoundingBox(wrd.orientedBoundingBox.center, wrd.orientedBoundingBox.halfExtents,
                                              wrd.orientedBoundingBox.rotation);
            wordResult.SetObb(QCARRuntimeUtilities.CameraFrameToScreenSpaceCoordinates(obb, bgTextureViewPortRect,
                                                                                       isMirrored, videoModeData));
        }

        // update word behaviours if enabled:
        if (mWordPrefabCreationMode == WordPrefabCreationMode.DUPLICATE)
        {
            UpdateWordBehaviourPoses();
        }
    }
Ejemplo n.º 2
0
    /// <summary>
    /// Defines the areas of the image in screen coordinates where text can be detected and tracked.
    /// </summary>
    public override bool SetRegionOfInterest(Rect detectionRegion, Rect trackingRegion)
    {
        QCARBehaviour qcarbehaviour = (QCARBehaviour)Object.FindObjectOfType(typeof(QCARBehaviour));

        if (qcarbehaviour == null)
        {
            Debug.LogError("QCAR Behaviour could not be found");
            return(false);
        }

        // required information to transform screen space coordinates into camera frame coordinates:
        Rect bgTextureViewPortRect = qcarbehaviour.GetViewportRectangle();
        bool isMirrored            = qcarbehaviour.VideoBackGroundMirrored;

        CameraDevice.VideoModeData videoModeData = CameraDevice.Instance.GetVideoMode(qcarbehaviour.CameraDeviceMode);

        // depending on the current orientation, different corner points of the rect have to be taken
        // - they need to span a rectangle in the camera frame coordinate system
        Vector2 detectionLeftTop, detectionRightBottom, trackingLeftTop, trackingRightBottom;

        QCARRuntimeUtilities.SelectRectTopLeftAndBottomRightForLandscapeLeft(detectionRegion, isMirrored, out detectionLeftTop, out detectionRightBottom);
        QCARRuntimeUtilities.SelectRectTopLeftAndBottomRightForLandscapeLeft(trackingRegion, isMirrored, out trackingLeftTop, out trackingRightBottom);

        // transform the coordinates into camera frame coord system
        QCARRenderer.Vec2I camFrameDetectionLeftTop     = QCARRuntimeUtilities.ScreenSpaceToCameraFrameCoordinates(detectionLeftTop, bgTextureViewPortRect, isMirrored, videoModeData);
        QCARRenderer.Vec2I camFrameDetectionRightBottom = QCARRuntimeUtilities.ScreenSpaceToCameraFrameCoordinates(detectionRightBottom, bgTextureViewPortRect, isMirrored, videoModeData);
        QCARRenderer.Vec2I camFrameTrackingLeftTop      = QCARRuntimeUtilities.ScreenSpaceToCameraFrameCoordinates(trackingLeftTop, bgTextureViewPortRect, isMirrored, videoModeData);
        QCARRenderer.Vec2I camFrameTrackingRightBottom  = QCARRuntimeUtilities.ScreenSpaceToCameraFrameCoordinates(trackingRightBottom, bgTextureViewPortRect, isMirrored, videoModeData);

        if (QCARWrapper.Instance.TextTrackerSetRegionOfInterest(camFrameDetectionLeftTop.x, camFrameDetectionLeftTop.y, camFrameDetectionRightBottom.x, camFrameDetectionRightBottom.y,
                                                                camFrameTrackingLeftTop.x, camFrameTrackingLeftTop.y, camFrameTrackingRightBottom.x, camFrameTrackingRightBottom.y, (int)CurrentUpDirection) == 0)
        {
            Debug.LogError(string.Format("Could not set region of interest: ({0}, {1}, {2}, {3}) - ({4}, {5}, {6}, {7})",
                                         detectionRegion.x, detectionRegion.y, detectionRegion.width, detectionRegion.height,
                                         trackingRegion.x, trackingRegion.y, trackingRegion.width, trackingRegion.height));
            return(false);
        }

        return(true);
    }
Ejemplo n.º 3
0
    /// <summary>
    /// Returns the areas of the image in screen coordinates where text can be detected and tracked.
    /// </summary>
    public override bool GetRegionOfInterest(out Rect detectionRegion, out Rect trackingRegion)
    {
        QCARBehaviour qcarbehaviour = (QCARBehaviour)Object.FindObjectOfType(typeof(QCARBehaviour));

        if (qcarbehaviour == null)
        {
            Debug.LogError("QCAR Behaviour could not be found");
            detectionRegion = new Rect();
            trackingRegion  = new Rect();
            return(false);
        }

        // required information to transform camera frame to screen space coordinates:
        Rect bgTextureViewPortRect = qcarbehaviour.GetViewportRectangle();
        bool isMirrored            = qcarbehaviour.VideoBackGroundMirrored;

        CameraDevice.VideoModeData videoModeData = CameraDevice.Instance.GetVideoMode(qcarbehaviour.CameraDeviceMode);

        IntPtr detectionROIptr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(RectangleIntData)));
        IntPtr trackingROIptr  = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(RectangleIntData)));

        // get current region of interest from native
        QCARWrapper.Instance.TextTrackerGetRegionOfInterest(detectionROIptr, trackingROIptr);

        RectangleIntData detectionROIcamSpace = (RectangleIntData)Marshal.PtrToStructure(detectionROIptr, typeof(RectangleIntData));
        RectangleIntData trackingROIcamSpace  = (RectangleIntData)Marshal.PtrToStructure(trackingROIptr, typeof(RectangleIntData));

        Marshal.FreeHGlobal(detectionROIptr);
        Marshal.FreeHGlobal(trackingROIptr);

        // calculate screen space rect for detection and tracking regions:
        detectionRegion = ScreenSpaceRectFromCamSpaceRectData(detectionROIcamSpace, bgTextureViewPortRect, isMirrored, videoModeData);
        trackingRegion  = ScreenSpaceRectFromCamSpaceRectData(trackingROIcamSpace, bgTextureViewPortRect, isMirrored, videoModeData);

        return(true);
    }