Home>

I want to send the marker center coordinates to MarkerTracking using the marker angular coordinates obtained with LiveSketchScript.
At present, you can refer to each variable itself, but you cannot know how to handle point2f and you cannot assign a numerical value.

LiveSketchScript side

mt.WStartp = corners;

I want to put the center coordinates in the

part and put it in WStartp.

If i run this way

OpenCvSharp.Point2f [] []
UnityEngine.Debug: Log (Object)
MarkerTracking: Update () (at Assets/MarkerTracking.cs: 26)


It just comes out on the console and doesn't contain any numbers.
How can I get and calculate the contents of point2f?

Thank you.

using OpenCvSharp;
using OpenCvSharp.Demo;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MarkerTracking: MonoBehaviour
{
    LiveSketchScript LSS;
    public Point2f [] [] WStartp, WEndo, CStartp, CEndp;
    // DefaultTrackableEventHandler DTE;
    bool Count = false;
    Vector2 WposST, WposED, CposST, CposED, Ccal;
    float Dist;
    // Start is called before the first frame update
    void Start ()
    {
        // DTE = this.gameObject.GetComponent<DefaultTrackableEventHandler>();
    }
    // Update is called once per frame
    void Update ()
    {
        if (WStartp! = null)
        {
            Debug.Log (WStartp);
        }
        if (Input.GetKeyDown ("return"))
            {
                Debug.Log (WStartp);
                if (Count == false)
                {
                    // WposST = GameObject.Find ("WorldMarker"). Transform.position;
                    // CposST = this.gameObject.transform.position;
                    Count = true;
                }
                else if (Count)
                {
                    Ccal = CposED-(WposED-WposST);
                    Dist = Vector3.Distance (CposST, Ccal);
                    Debug.Log (Dist);
                    Count = false;
                }
            }
            if (Count)
            {
                WposED = GameObject.Find ("WorldMarker"). Transform.position;
                CposED = this.gameObject.transform.position;
            }
    }
}
namespace OpenCvSharp.Demo
{
    using UnityEngine;
    using OpenCvSharp;
    using Aruco;
    public class LiveSketchScript: WebCamera
    {
        MarkerTracking mt;
        protected override void Awake ()
        {
            base.Awake ();
            this.forceFrontalCamera = true;
            var thread_mgr = GameObject.Find ("SampleRaw") as GameObject;
            mt = thread_mgr.GetComponent<MarkerTracking>();
        }
        // Our sketch generation function
        protected override bool ProcessTexture (WebCamTexture input, ref Texture2D output)
        {
            // Create default parameres for detection
            DetectorParameters detectorParameters = DetectorParameters.Create ();
            // Dictionary holds set of all available markers
            Dictionary dictionary = CvAruco.GetPredefinedDictionary (PredefinedDictionaryName.Dict6X6_250);
            // Variables to hold results
            Point2f [] [] corners;
            int [] ids;
            Point2f [] [] rejectedImgPoints;
            // Create Opencv image from unity texture
            Mat mat = Unity.TextureToMat (input);
            // Convert image to grasyscale
            Mat grayMat = new Mat ();
            Cv2.CvtColor (mat, grayMat, ColorConversionCodes.BGR2GRAY);
            // Detect and draw markers
            CvAruco.DetectMarkers (grayMat, dictionary, out corners, out ids, detectorParameters, out rejectedImgPoints);
            CvAruco.DrawDetectedMarkers (mat, corners, ids);
            mt.WStartp = corners;
            output = Unity.MatToTexture (mat);

            return true;
        }
    }
}