private void LoadLabelAndLocationFromTxt(string fileName, imgInfo imgInfo)
        {
            if (!File.Exists(fileName))
            {
                return;
            }

            imgInfo.regionInfoList.Clear();
            using (StreamReader sr = new StreamReader(fileName))
            {
                string line;
                while ((line = sr.ReadLine()) != null)
                {
                    string[] labelAndLoc = new string[5];
                    labelAndLoc = line.Split(' ');
                    int      label = Convert.ToInt32(labelAndLoc[0]);
                    double[] loc   = new double[4];
                    loc[0] = Convert.ToDouble(labelAndLoc[1]);
                    loc[1] = Convert.ToDouble(labelAndLoc[2]);
                    loc[2] = Convert.ToDouble(labelAndLoc[3]);
                    loc[3] = Convert.ToDouble(labelAndLoc[4]);
                    Bitmap    t = new Bitmap(imgInfo.imagePath);
                    Rectangle r = ConvertLocationToRect(t, loc);
                    imgInfo.regionInfoList.Add(new regionInfo(label, r, loc));
                    t.Dispose();
                }
            }
        }
Пример #2
0
        public frmShowImg(imgInfo info)
        {
            this.m_imgInfo = info;
            InitializeComponent();
            mybitmap = new Bitmap(
                pictureBox1.ClientRectangle.Width,
                pictureBox1.ClientRectangle.Height,
                PixelFormat.Format32bppArgb);

            this.MouseWheel += new MouseEventHandler(frmShowImg_MouseWheel);
            setShowPara();
            ZoomAndRefreshBitmap();
        }
 private void DrawRegion(imgInfo imgIn, ref Image <Bgr, byte> image)
 {
     foreach (regionInfo ri in imgIn.regionInfoList)
     {
         Bitmap bmp = image.ToBitmap();
         selectedGraphics = Graphics.FromImage(bmp);
         selectedGraphics.DrawRectangle(new Pen(Color.Red), ri.rect);
         selectedGraphics.DrawString($"{ri.labelIndex}-{labelSet[ri.labelIndex]}"
                                     , new Font("Arial", 9), new SolidBrush(Color.Red), ri.rect.X, ri.rect.Y);
         image = new Image <Bgr, byte>(bmp);
     }
     /// Update final image
     Img_viewer.Source = ImgConverter.ToBitmapSource(image.ToBitmap());
 }
        private void SaveROIToTxtFile(imgInfo imgInfo)
        {
            string txtFile = mImgInfoList[cImgIndex].imagePath.Replace(".jpg", ".txt");

            if (!File.Exists(txtFile))
            {
                File.Create(txtFile).Dispose();
            }

            using (StreamWriter sw = new StreamWriter(txtFile))
            {
                foreach (regionInfo r in imgInfo.regionInfoList)
                {
                    sw.WriteLine($"{r.labelIndex} {r.location[0]} {r.location[1]} {r.location[2]} {r.location[3]}");
                }
            }
        }
        private void UpdateListBox(imgInfo imgIn)
        {
            LB_regionRectangles.Items.Clear();
            LB_outPutRegionValues.Items.Clear();
            foreach (regionInfo r in imgIn.regionInfoList)
            {
                Label l = new Label();
                l.Content  = $"Class{r.labelIndex}, ({r.rect.X}, {r.rect.Y}, {r.rect.Width}, {r.rect.Height})";
                l.FontSize = 12;
                LB_regionRectangles.Items.Add(l);

                Label l2 = new Label();
                l2.Content  = $"Class{r.labelIndex}, ({r.location[0]}, {r.location[1]}, {r.location[2]}, {r.location[3]})";
                l2.FontSize = 12;
                LB_outPutRegionValues.Items.Add(l2);
            }
        }