コード例 #1
0
    private Rect ScreenSpaceRectFromCamSpaceRectData(RectangleIntData camSpaceRectData, Rect bgTextureViewPortRect, bool isTextureMirrored, CameraDevice.VideoModeData videoModeData)
    {
        Vector2 topLeft     = QCARRuntimeUtilities.CameraFrameToScreenSpaceCoordinates(new Vector2((float)camSpaceRectData.leftTopX, (float)camSpaceRectData.leftTopY), bgTextureViewPortRect, isTextureMirrored, videoModeData);
        Vector2 bottomRight = QCARRuntimeUtilities.CameraFrameToScreenSpaceCoordinates(new Vector2((float)camSpaceRectData.rightBottomX, (float)camSpaceRectData.rightBottomY), bgTextureViewPortRect, isTextureMirrored, videoModeData);

        return(QCARRuntimeUtilities.CalculateRectFromLandscapeLeftCorners(topLeft, bottomRight, isTextureMirrored));
    }
コード例 #2
0
    public override bool GetRegionOfInterest(out Rect detectionRegion, out Rect trackingRegion)
    {
        QCARAbstractBehaviour behaviour = (QCARAbstractBehaviour)UnityEngine.Object.FindObjectOfType(typeof(QCARAbstractBehaviour));

        if (behaviour == null)
        {
            Debug.LogError("QCAR Behaviour could not be found");
            detectionRegion = new Rect();
            trackingRegion  = new Rect();
            return(false);
        }
        Rect viewportRectangle       = behaviour.GetViewportRectangle();
        bool videoBackGroundMirrored = behaviour.VideoBackGroundMirrored;

        CameraDevice.VideoModeData videoMode = CameraDevice.Instance.GetVideoMode(behaviour.CameraDeviceMode);
        IntPtr detectionROI = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(RectangleIntData)));
        IntPtr trackingROI  = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(RectangleIntData)));

        QCARWrapper.Instance.TextTrackerGetRegionOfInterest(detectionROI, trackingROI);
        RectangleIntData camSpaceRectData = (RectangleIntData)Marshal.PtrToStructure(detectionROI, typeof(RectangleIntData));
        RectangleIntData data3            = (RectangleIntData)Marshal.PtrToStructure(trackingROI, typeof(RectangleIntData));

        Marshal.FreeHGlobal(detectionROI);
        Marshal.FreeHGlobal(trackingROI);
        detectionRegion = this.ScreenSpaceRectFromCamSpaceRectData(camSpaceRectData, viewportRectangle, videoBackGroundMirrored, videoMode);
        trackingRegion  = this.ScreenSpaceRectFromCamSpaceRectData(data3, viewportRectangle, videoBackGroundMirrored, videoMode);
        return(true);
    }
コード例 #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);
    }
コード例 #4
0
    private Rect ScreenSpaceRectFromCamSpaceRectData(RectangleIntData camSpaceRectData, Rect bgTextureViewPortRect,
        bool isTextureMirrored, CameraDevice.VideoModeData videoModeData)
    {
        Vector2 topLeftSSLandscape = QCARRuntimeUtilities.CameraFrameToScreenSpaceCoordinates(new Vector2(camSpaceRectData.leftTopX, camSpaceRectData.leftTopY),
                                                                                              bgTextureViewPortRect, isTextureMirrored, videoModeData);
        Vector2 bottomRightSSLandscape = QCARRuntimeUtilities.CameraFrameToScreenSpaceCoordinates(new Vector2(camSpaceRectData.rightBottomX, camSpaceRectData.rightBottomY),
                                                                                              bgTextureViewPortRect, isTextureMirrored, videoModeData);

        return QCARRuntimeUtilities.CalculateRectFromLandscapeLeftCorners(topLeftSSLandscape, bottomRightSSLandscape, isTextureMirrored);
    }