private void picShow_MouseUp(object sender, MouseEventArgs e) { if (isDrag == true) { isDrag = false; int x1, y1, x2, y2; Image source = Image.FromFile(xmlInfo.ImgFile.FullName); ImageProcess.InOrder(startPoint, e.Location, out x1, out y1, out x2, out y2, source); var p1 = new Point(x1, y1); var p2 = new Point(x2, y2); if (ImageProcess.isRectangle(p1, p2)) { p1 = ImageProcess.ResizedToSource(startPoint, source.Size, picShow.Image.Size); p2 = ImageProcess.ResizedToSource(e.Location, source.Size, picShow.Image.Size); FormClass formClass = new FormClass(ImageProcess.CropRectangle(p1, p2, source), Control.MousePosition); formClass.ShowDialog(); if (formClass.result != -1) { ImageProcess.InOrder(p1, p2, out x1, out y1, out x2, out y2, source); MyObject myObject = new MyObject(formClass.result, x1, y1, x2, y2); xmlInfo.AddObject(myObject); tempBitmap = ImageProcess.DrawRectangle(startPoint, e.Location, tempBitmap, true, 2, myObject.Color); UpdateObjectList(); } } picShow.Image = tempBitmap; GC.Collect(); } }
public FormClass(Image image, Point Location) { InitializeComponent(); picShowOriginalS = picShow.Size; picShowOriginalL = picShow.Location; foreach (var name in ConfigFile.Classes) { lsvType.Items.Add(new ListViewItem(name) { ForeColor = new MyObject(name, 0, 0, 0, 0).Color }); } picShow.Image = null; picShow.Size = picShowOriginalS; picShow.Location = picShowOriginalL; ImageProcess.FitSizeAndShow((Bitmap)image, picShow); Point pos = new Point(Location.X - 354 - 57 / 2, Location.Y - 20); if (pos.X + this.Width > Screen.GetWorkingArea(this).Width) { pos.X = Screen.GetWorkingArea(this).Width - this.Width; } if (pos.Y + Height > Screen.GetWorkingArea(this).Height) { pos.Y = Screen.GetWorkingArea(this).Height - Height; } this.Location = pos; }
private void initFileList() { lvwFiles.Clear(); lvwFiles.Columns.Add("Image List", 252); ImageList imgList = new ImageList(); //Init thumbnail image list imgList.ColorDepth = ColorDepth.Depth24Bit; imgList.ImageSize = new Size(64, 64); this.lvwFiles.BeginUpdate(); for (int i = 0; i < imageFiles.ImgFileList.Count(); i++) { try { var currImage = Image.FromFile(imageFiles.ImgFileList.ElementAt(i).FullName); imgList.Images.Add(ImageProcess.FixedSize(currImage, imgList.ImageSize, Color.White)); GC.Collect(); ListViewItem listViewItem = new ListViewItem(); listViewItem.ImageIndex = i; listViewItem.Text = imageFiles.ImgFileList.ElementAt(i).Name; listViewItem.Tag = imageFiles.ImgFileList[i]; lvwFiles.Items.Add(listViewItem); } catch (OutOfMemoryException) { MessageBox.Show("Read file failed:" + imageFiles.ImgFileList.ElementAt(i).Name); } } lvwFiles.SmallImageList = imgList; this.lvwFiles.EndUpdate(); }
private void picShow_MouseMove(object sender, MouseEventArgs e) { if (isDrag == true) { picShow.Image = ImageProcess.DrawRectangle(startPoint, e.Location, tempBitmap, false, 2, Color.Black); GC.Collect(); } }
private void lvwObject_SelectedIndexChanged(object sender, EventArgs e) { if (lvwObject.SelectedIndices.Count == 1) { Image source = Image.FromFile(xmlInfo.ImgFile.FullName); MyObject selected = (MyObject)lvwObject.SelectedItems[0].Tag; picShow.Image = tempBitmap; picShow.Image = ImageProcess.DrawRectangle(ImageProcess.SourceToResized(selected.Min, source.Size, tempBitmap.Size), ImageProcess.SourceToResized(selected.Max, source.Size, tempBitmap.Size), tempBitmap, true, 4, selected.Color); GC.Collect(); } }
private void showImage() { picShow.Image = null; picShow.Size = picShowOriginalS; picShow.Location = picShowOriginalL; Bitmap source = (Bitmap)Image.FromFile(((FileInfo)lvwFiles.SelectedItems[0].Tag).FullName); ImageProcess.FitSizeAndShow(source, picShow); UpdateObjectList(); tempBitmap = (Bitmap)picShow.Image; for (int i = 0; i < xmlInfo.ObjectList.Count(); i++) { tempBitmap = ImageProcess.DrawRectangle(ImageProcess.SourceToResized(xmlInfo.ObjectList[i].Min, source.Size, tempBitmap.Size), ImageProcess.SourceToResized(xmlInfo.ObjectList[i].Max, source.Size, tempBitmap.Size), tempBitmap, true, 2, xmlInfo.ObjectList[i].Color); } picShow.Image = tempBitmap; }
private void lvwObject_DoubleClick(object sender, EventArgs e) { Image source = Image.FromFile(xmlInfo.ImgFile.FullName); MyObject selected = (MyObject)lvwObject.SelectedItems[0].Tag; FormClass formClass = new FormClass(ImageProcess.CropRectangle(selected.Min, selected.Max, source), Control.MousePosition); formClass.ShowDialog(); if (formClass.result == -1) { xmlInfo.DelObject(selected); } else { xmlInfo.DelObject(selected); selected.NameID = formClass.result; xmlInfo.AddObject(selected); } showImage(); }
private void UpdateObjectList() { lvwObject.Clear(); lvwObject.Columns.Add("Object List", 252); ImageList imgList = new ImageList(); imgList.ImageSize = new Size(64, 64); imgList.ColorDepth = ColorDepth.Depth24Bit; lvwObject.BeginUpdate(); for (int i = 0; i < xmlInfo.ObjectList.Count(); i++) { var currImage = Image.FromFile(ConfigFile.WorkDirectory.FullName + "\\" + xmlInfo.ObjectList[i].Name + "_240px\\" + xmlInfo.ImgFile.Name + "_" + xmlInfo.ObjectList[i].xmin + "_" + xmlInfo.ObjectList[i].ymin + "_" + xmlInfo.ObjectList[i].xmax + "_" + xmlInfo.ObjectList[i].ymax + ".bmp"); imgList.Images.Add(ImageProcess.FixedSize(currImage, imgList.ImageSize, Color.White)); GC.Collect(); ListViewItem listViewItem = new ListViewItem(); listViewItem.ImageIndex = i; listViewItem.Text = xmlInfo.ObjectList[i].Name; listViewItem.ForeColor = xmlInfo.ObjectList[i].Color; listViewItem.Tag = xmlInfo.ObjectList[i]; lvwObject.Items.Add(listViewItem); } lvwObject.SmallImageList = imgList; lvwObject.EndUpdate(); }
private void initImageFileList() { if (ConfigFile.ExistCropImage) { int cropImageCount = 0; ImgFileList = new List <FileInfo>(); ImagePairList = new List <ImagePair>(); var allImageFile = ConfigFile.WorkDirectory.EnumerateFiles("*", SearchOption.TopDirectoryOnly).Where(s => GlobalSettings.SupportExtension.Contains(s.Extension.ToLower())); foreach (var file in allImageFile) { if (file.Name.StartsWith(ConfigFile.CropImagePrefix) && file.Name.EndsWith(ConfigFile.CropImageSuffix + file.Extension)) { cropImageCount++; var cropImage = file; string imageName = cropImage.Name.Substring(ConfigFile.CropImagePrefix.Length, cropImage.Name.Length - (ConfigFile.CropImagePrefix + ConfigFile.CropImageSuffix + file.Extension).Length); var imageFile = allImageFile.Where(s => s.Name.Substring(0, s.Name.Length - s.Extension.Length).Equals(imageName)); switch (imageFile.Count()) { case 1: ImagePairList.Add(new ImagePair(imageFile.First(), cropImage)); ImgFileList.Add(imageFile.First()); break; case 0: MessageBox.Show("Can not find the image corresponding to " + cropImage.Name, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); break; default: MessageBox.Show("Find more than one images corresponding to " + cropImage.Name, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); break; } } } if (ConfigFile.Classes.Count() == 2) { DialogResult dialogResult = MessageBox.Show("Find " + cropImageCount.ToString() + " crop image and " + ImagePairList.Count() + " pairs.\nWould you like to process auto generate?", "Information", MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (dialogResult == DialogResult.Yes) { foreach (var imagepair in ImagePairList) { XMLInfo xmlInfo = new XMLInfo(imagepair.Image); try { var targetList = ImageProcess.TargetObject((Bitmap)Image.FromFile(imagepair.CropImage.FullName)); var nonTargetList = ImageProcess.NonTargetObject((Bitmap)Image.FromFile(imagepair.CropImage.FullName), targetList, 4); foreach (var tar in targetList) { xmlInfo.AddObject(tar); } foreach (var nontar in nonTargetList) { xmlInfo.AddObject(nontar); } xmlInfo.SaveToFile(); } catch (Exception) { MessageBox.Show("Happened unknown error during the process of " + imagepair.Image.Name, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } } } } else { ImgFileList = ConfigFile.WorkDirectory.EnumerateFiles("*", SearchOption.TopDirectoryOnly).Where(s => GlobalSettings.SupportExtension.Contains(s.Extension.ToLower())).ToList(); } }
public void AddObject(MyObject myobject) { var sourceimg = Image.FromFile(ImgFile.FullName); if (!Directory.Exists(imgFile.DirectoryName + "\\" + myobject.Name)) { Directory.CreateDirectory(imgFile.DirectoryName + "\\" + myobject.Name); } if (!Directory.Exists(imgFile.DirectoryName + "\\" + myobject.Name + "_240px")) { Directory.CreateDirectory(imgFile.DirectoryName + "\\" + myobject.Name + "_240px"); } ImageProcess.CropRectangle(new Point(myobject.xmin, myobject.ymin), new Point(myobject.xmax, myobject.ymax), sourceimg).Save(imgFile.DirectoryName + "\\" + myobject.Name + "\\" + imgFile.Name + "_" + myobject.xmin + "_" + myobject.ymin + "_" + myobject.xmax + "_" + myobject.ymax + ".bmp", ImageFormat.Bmp); Image image240 = ImageProcess.Crop240Rectangle(new Point(myobject.xmin, myobject.ymin), new Point(myobject.xmax, myobject.ymax), sourceimg); ImageProcess.FixedSize(image240, new Size(240, 240), Color.Black).Save(imgFile.DirectoryName + "\\" + myobject.Name + "_240px\\" + imgFile.Name + "_" + myobject.xmin + "_" + myobject.ymin + "_" + myobject.xmax + "_" + myobject.ymax + ".bmp", ImageFormat.Bmp); root.Add ( new XElement ( "object", new XElement ( "name", myobject.Name ), new XElement ( "pose", "Unspecified" ), new XElement ( "truncated", "0" ), new XElement ( "difficult", "0" ), new XElement ( "bndbox", new XElement ( "xmin", myobject.xmin.ToString() ), new XElement ( "ymin", myobject.ymin.ToString() ), new XElement ( "xmax", myobject.xmax.ToString() ), new XElement ( "ymax", myobject.ymax.ToString() ) ) ) ); SaveToFile(); }