Пример #1
0
    /// <summary>
    /// Creates an OpenCV version of a ZEDMat.
    /// In this sample, we only ever use 8U_C1 (for grayscale image) but you can call it yourself
    /// for any ZEDMat type and get a properly-formatted OpenCV Mat.
    /// </summary>
    /// <param name="zedmat">Source ZEDMat.</param>
    /// <param name="zedmattype">Type of ZEDMat - data type and channel number. Depends on the type of image
    /// it represents. See summaries of each enum value to choose the type, as you can't currently
    /// retrieve the material type from an instantiated ZEDMat.</param>
    /// <returns>OpenCV Mat formatted correctly so that you can copy data from the source ZEDMat into it.</returns>
    private static Mat SLMat2CVMat(sl.ZEDMat zedmat, ZEDMat.MAT_TYPE zedmattype)
    {
        int cvmattype = SLMatType2CVMatType(zedmattype);
        Mat cvmat     = new Mat(zedmat.GetHeight(), zedmat.GetWidth(), cvmattype);

        return(cvmat);
    }
Пример #2
0
    /// <summary>
    /// Constructor that assigns values required for transformations later on.
    /// This is necessary because detections are frozen in a particular frame, and results should not change
    /// in subsequent frames when the camera moves.
    /// </summary>
    /// <param name="odata">Raw sl.ObjectData data that this instance represents.</param>
    /// <param name="viewingmanager">ZEDManager assigned to the ZED camera that detected the object.</param>
    /// <param name="campos">World position of the left ZED camera when the object was detected.</param>
    /// <param name="camrot">World rotation of the left ZED camera when the object was detected.</param>
    public DetectedObject(ObjectDataSDK odata, ZEDManager viewingmanager, Vector3 campos, Quaternion camrot)
    {
        objectData             = odata;
        detectingZEDManager    = viewingmanager;
        camPositionAtDetection = campos;
        camRotationAtDetection = camrot;

        maskMat = new ZEDMat(odata.mask);
        //maskTexture = ZEDMatToTexture_CPU(maskMat);
    }
Пример #3
0
    /// <summary>
    /// Converts the given zedMat to an Alpha8 (8-bit single channel) texture.
    /// Assumes you are giving it the ZEDMat from an Object Detection mask, and is therefore 8-bit single channel.
    /// </summary>
    private static Texture2D ZEDMatToTexture_CPU(sl.ZEDMat zedmat, bool flipYcoords = false)
    {
        int width  = zedmat.GetWidth(); //Shorthand.
        int height = zedmat.GetHeight();


        IntPtr maskpointer = zedmat.GetPtr(sl.ZEDMat.MEM.MEM_CPU);

        if (maskpointer != IntPtr.Zero && zedmat.IsInit())
        {
            byte[] texbytes = new byte[zedmat.GetStepBytes() * height];

            System.Runtime.InteropServices.Marshal.Copy(zedmat.GetPtr(sl.ZEDMat.MEM.MEM_CPU), texbytes, 0, texbytes.Length);

            if (flipYcoords)
            {
                byte[] flippedbytes = new byte[texbytes.Length];
                int    steplength   = zedmat.GetWidthBytes();
                for (int i = 0; i < texbytes.Length; i += steplength)
                {
                    Array.Copy(texbytes, i, flippedbytes, flippedbytes.Length - i - steplength, steplength);
                }

                texbytes = flippedbytes;
            }

            Texture2D zedtex = new Texture2D(width, height, TextureFormat.Alpha8, false, false);
            zedtex.anisoLevel = 0;
            zedtex.LoadRawTextureData(texbytes);
            zedtex.Apply(); //Slight bottleneck here - it forces the CPU and GPU to sync.

            return(zedtex);
        }
        else
        {
            Debug.LogError("Pointer to texture was null - returning null.");
            return(null);
        }
    }
Пример #4
0
 /// <summary>
 /// Duplicates a Mat by copying all its data into a new one (deep copy).
 /// </summary>
 /// <param name="source"></param>
 public void Clone(ZEDMat source)
 {
     dllz_mat_clone(_matInternalPtr, source._matInternalPtr);
 }
Пример #5
0
 /// <summary>
 /// Copies data from another Mat into this one(deep copy).
 /// </summary>
 /// <param name="src">Source Mat from which to copy.</param>
 /// <param name="copyType">The To and From memory types.</param>
 /// <returns>ERROR_CODE (as an int) indicating if the copy was successful, or why it wasn't.</returns>
 public int SetFrom(ZEDMat src, COPY_TYPE copyType = COPY_TYPE.COPY_TYPE_CPU_CPU)
 {
     return(dllz_mat_set_from(_matInternalPtr, src._matInternalPtr, (int)copyType));
 }