private CommandHandler[] handlers = new CommandHandler[256];    // 指令包处理器

        public override void before()
        {
            // 加载配置文件
            Configs.init(System.IO.Directory.GetCurrentDirectory() + "\\" + "config.ini");

            // 键盘映射初始化
            KeyMapping.init();

            // RLE压缩处理器初始化
            RLEncoding.init();

            // TODO: 单个可处理包大小不能超过400k
            this.byteBuffer = new ByteWriter(4096 * 100);

            // 包指令处理器
            handlers[Command.HEARTBEAT]       = heartbeat;
            handlers[Command.CONTROL_REQUEST] = requestControl;
            handlers[Command.CLOSE_REQUEST]   = closeControl;
            handlers[Command.GET_CLIPBOARD]   = readClipboard;
            handlers[Command.SET_CLIPBOARD]   = writeClipboard;
            handlers[Command.HID_COMMAND]     = hidCommandExec;
            handlers[Command.LIST_FILES]      = listFiles;
            handlers[Command.DOWNLOAD_FILE]   = transferFile;
            handlers[Command.UPLOAD_FILE]     = writeFile;
        }
Esempio n. 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);
    }