コード例 #1
0
    private bool OnProcessTexture(WebCamTexture input, ref Texture2D output,
                                  ARucoUnityHelper.TextureConversionParams textureParameters)
    {
        textureParameters.FlipHorizontally = false;
        if (!float.TryParse(patternSizeString.value, out squareSizeMeters))
        {
            return(false);
        }

        squareSizeMeters = float.Parse(patternSizeString.value);

        mat = ARucoUnityHelper.TextureToMat(input, textureParameters);

        //Debug.Log("Width: " + mat.Width + " Height: " + mat.Height);

        imageWidth  = mat.Width;
        imageHeight = mat.Height;


        Cv2.CvtColor(mat, grayMat, ColorConversionCodes.BGR2GRAY);

        if (reset)
        {
            ResetCalibrationImmediate();
            reset = false;
        }

        if (captureFrame)
        {
            RegisterCurrentCalib();
            captureFrame = false;
        }

        if (calibrate)
        {
            StartCalibrateAsync();
            calibrate = false;
        }


        output = ARucoUnityHelper.MatToTexture(mat, output);

        mat.Release();
        return(true);
    }
コード例 #2
0
    private bool ProcessTexture(WebCamTexture input, ref Texture2D output,
                                ARucoUnityHelper.TextureConversionParams textureParameters)
    {
        imgBuffer = ARucoUnityHelper.TextureToMat(input, textureParameters);
        //Debug.Log("New image Assigned");

        timeCount += Time.deltaTime;

        if (threadCounter == 0 && timeCount >= markerDetectorPauseTime)
        {
            imgBuffer.CopyTo(img);
            Interlocked.Increment(ref threadCounter);
            timeCount = 0;
        }

        updateThread = true;

        if (outputImage)
        {
            if (drawMarkerOutlines)
            {
                CvAruco.DrawDetectedMarkers(img, corners, ids);
            }

            output = ARucoUnityHelper.MatToTexture(img, output);
            //Debug.Log("Marker image Rendered");
            outputImage = false;
        }
        else
        {
            output = ARucoUnityHelper.MatToTexture(imgBuffer, output);
            //Debug.Log("Camera image Rendered");
        }

        imgBuffer.Release();
        return(true);
    }
コード例 #3
0
    unsafe void OnCameraFrameReceived(ARCameraFrameEventArgs eventArgs)
    {
        //Get the latest image
        XRCameraImage image;

        if (!cameraManager.TryGetLatestImage(out image))
        {
            return;
        }

        timeCount += Time.deltaTime;

        //select the format of the texture
        var format = TextureFormat.RGBA32;

        //check if the texture changed, and only if so create a new one with the new changes
        if (texture == null || texture.width != image.width || texture.height != image.height)
        {
            texture = new Texture2D(image.width, image.height, format, false);
        }

        //mirror on the Y axis so that it fits open cv standarts
        var conversionParams = new XRCameraImageConversionParams(image, format, CameraImageTransformation.MirrorY);

        // try to apply raw texture data to the texture
        var rawTextureData = texture.GetRawTextureData <byte>();

        try
        {
            image.Convert(conversionParams, new IntPtr(rawTextureData.GetUnsafePtr()), rawTextureData.Length);
        }
        finally
        {
            //every Mat must be released before new data is assigned!
            image.Dispose();
        }

        //apply texture
        texture.Apply();

        texParam.FlipHorizontally = false;

        //create a Mat class from the texture
        imgBuffer = ARucoUnityHelper.TextureToMat(texture, texParam);

        // Increment thread counter
        if (threadCounter == 0 && timeCount >= markerDetectorPauseTime &&
            arCamera.velocity.magnitude <= maxPositionChangePerFrame && cameraPoseTracker.rotationChange <= maxRotationChangePerFrameDegrees)
        {
            //copy the buffer data to the img Mat
            imgBuffer.CopyTo(img);
            Interlocked.Increment(ref threadCounter);
            timeCount = 0;
        }

        updateThread = true;

        //Show the texture if needed
        if (showOpenCvTexture)
        {
            openCvTexture.texture = ARucoUnityHelper.MatToTexture(imgBuffer, texture);
        }

        //release imgBuffer Mat
        imgBuffer.Release();
    }