コード例 #1
0
    Texture2D RLE2alpha8(RLERaw rle, bool flipVertical)
    {
        Texture2D texture = new Texture2D(rle.size[0], rle.size[1], TextureFormat.Alpha8, false);

        byte[] pixelBuffer = new byte[rle.size[0] * rle.size[1]];
        byte[] ret;
        int    runningIndex = rle.size[0] * rle.size[1] - 1;

        // rle to array
        for (int i = rle.counts.Count - 1; i > -1; --i)
        {
            if (i % 2 == 1)
            {
                for (int j = 0; j < rle.counts[i]; ++j)
                {
                    pixelBuffer[runningIndex - j] = 0xFF;
                }
            }
            runningIndex -= rle.counts[i];
        }
        if (flipVertical)
        {
            byte[] temp = new byte[pixelBuffer.Length];
            for (int i = 0; i < rle.size[1]; ++i)
            {
                Array.Copy(pixelBuffer, i * rle.size[0], temp, pixelBuffer.Length - rle.size[0] * (i + 1), rle.size[0]);
            }
            ret = temp;
        }
        else
        {
            ret = pixelBuffer;
        }
        texture.LoadRawTextureData(ret);
        texture.Apply();
        return(texture);
    }
コード例 #2
0
    RLEncoding createRLEncoding4Image(string folderName, string imageName, int maskID)
    {
        RLEncoding newEncoding = new RLEncoding(); // new single encoding for one instance of (image)

        newEncoding.annotations = new List <Annotation>();
        int i = 0;

        foreach (string t in focusTags)
        {
            int[]               boundingBox;                                          // = new int[1];
            List <int>          codedMask;                                            // = new List<int>();
            List <Vector3Int[]> objectRectangles;                                     // = new List<Vector3Int[]>();

            objectRectangles = probeImageCorners(probeWidthHalf, probeHeightHalf, t); // assuming simple landscape // ok
            if (objectRectangles.Count == 0)
            {
                continue;
            }
            // get RLE for each line, {row: {start: length}} :
            Dictionary <int, Dictionary <int, int> > lineAnnotation = rectangles2Lines1Tag(objectRectangles, t);
            // get bounding box from line RLE:
            boundingBox = RLELines2BoundingBox(lineAnnotation);
            // get RLE for whole image composed from RLE of each line:
            codedMask = getRLEFromLines(screenshotWidth, screenshotHeight, lineAnnotation);

            // save the RLE of image into serializable class:
            newEncoding.file_name = folderName + imageName; // image name
            newEncoding.image_id  = myPath.currentID;       // image name
            newEncoding.height    = screenshotHeight;       // image height
            newEncoding.width     = screenshotWidth;        // image width
            Annotation annotation = new Annotation();
            RLERaw     rawRLE     = new RLERaw();
            annotation.bbox = boundingBox;

            // Define materials for each object // TODO set this in YAML
            string materialID;
            if (t.Contains("sp"))
            {
                if (t.Contains("Pi")) // spPill sponge Pill
                {
                    materialID = "pill - foam";
                }
                else if (t.Contains("pG"))   // spG sponge Green
                {
                    materialID = "cylinder - foam";
                }
                else
                {
                    materialID = "box - foam";
                }
            }
            else if (t.Contains("die"))
            {
                if (t.Contains("dieB"))
                {
                    materialID = "dice - soft plastic";
                }
                else
                {
                    materialID = "dice - foam";
                }
            }
            else
            {
                materialID = "unknown";
            }
            annotation.material_id  = materialID; // material of focus, e.g. foam
            annotation.image_id     = myPath.currentID;
            annotation.bbox_mode    = 0;
            annotation.mask_file    = Path.Combine("images/", maskID.ToString() + "-" + i.ToString() + ".png");
            rawRLE.counts           = codedMask;
            rawRLE.size             = new int[] { screenshotWidth, screenshotHeight };
            annotation.segmentation = rawRLE;
            newEncoding.annotations.Add(annotation);
            i++;
        }
        return(newEncoding);
    }