コード例 #1
0
    private byte[] BuildSDSLFrame(ShapeClip[] clips)
    {
        MemoryStream stream = new MemoryStream();
        stream.WriteByte((byte)0x02 + 128);

        // (3 positionComponents + 3 normalComponents) * (4 floatBytes)
        var payload_length = clips.Length * (3 + 3) * 4;
        if (payload_length > UInt16.MaxValue)
        {
            stream.WriteByte(127);
            var lengthBytes = ToBigEndianBytes<ulong>(payload_length);
            stream.Write(lengthBytes, 0, lengthBytes.Length);
        }
        else if (payload_length > 125)
        {
            stream.WriteByte(126);
            var lengthBytes = ToBigEndianBytes<ushort>(payload_length);
            stream.Write(lengthBytes, 0, lengthBytes.Length);
        }
        else
        {
            stream.WriteByte((byte)payload_length);
        }

        for (int i = 0; i < clips.Length; i++)
        {
            ShapeClip clip = clips[i];

            // position
            foreach (float comp in clip.Position.ToArray()) stream.Write(BitConverter.GetBytes(comp), 0, 4);
            stream.Write(BitConverter.GetBytes(0.0f), 0, 4);

            // normal
            stream.Write(BitConverter.GetBytes(0.0f), 0, 4);
            stream.Write(BitConverter.GetBytes(0.0f), 0, 4);
            stream.Write(BitConverter.GetBytes(1.0f), 0, 4);
        }

        return stream.ToArray();
    }
コード例 #2
0
    private byte[] BuildDriverFrame(ShapeClip[] clips)
    {
        MemoryStream stream = new MemoryStream();
        stream.WriteByte((byte)0x02 + 128);

        // (2 positionComponents + 1 rotationComponents) * (4 floatBytes)
        var payload_length = clips.Length * (2 + 1) * 4;
        if (payload_length > UInt16.MaxValue)
        {
            stream.WriteByte(127);
            var lengthBytes = ToBigEndianBytes<ulong>(payload_length);
            stream.Write(lengthBytes, 0, lengthBytes.Length);
        }
        else if (payload_length > 125)
        {
            stream.WriteByte(126);
            var lengthBytes = ToBigEndianBytes<ushort>(payload_length);
            stream.Write(lengthBytes, 0, lengthBytes.Length);
        }
        else
        {
            stream.WriteByte((byte)payload_length);
        }

        for (int i = 0; i < clips.Length; i++)
        {
            ShapeClip clip = clips[i];

            // position
            stream.Write(BitConverter.GetBytes(clip.Position.X), 0, 4);
            stream.Write(BitConverter.GetBytes(clip.Position.Y), 0, 4);

            // rotation
            stream.Write(BitConverter.GetBytes((float)clip.Angle), 0, 4);
        }

        return stream.ToArray();
    }
コード例 #3
0
    public ShapeClip[] DetectClips(IplImage copy, int threshold = 230)
    {
        //using (IplImage copy = image.Clone())
        {
            Cv.Threshold(copy, copy, threshold, 255, ThresholdType.Binary);

            // find contours
            CvSeq <CvPoint> contours;
            CvMemStorage    storage = new CvMemStorage();
            using (IplImage contourImage = copy.Clone())
                Cv.FindContours(contourImage, storage, out contours, CvContour.SizeOf, ContourRetrieval.Tree, ContourChain.ApproxSimple);

            List <ShapeClip> result = new List <ShapeClip>();
            for (CvSeq <CvPoint> contour = contours; contour != null; contour = contour.HNext)
            {
                ShapeClip clip = DetectClip(contour, copy);
                if (clip != null)
                {
                    result.Add(clip);
                }
            }
            return(result.ToArray());
        }
    }