private void yIQToolStripMenuItem_Click(object sender, EventArgs e) { for (int i = 0; i < FileListBox.Items.Count; i++) { FileListBox.SelectedItem = i; FileListBox.Refresh(); OriginalImg1.Load(files[i]); OriginalImg2.SetSize(OriginalImg1); EasyImage.Oper(EArithmeticLogicOperation.Copy, new EC24(0, 0, 0), OriginalImg2); OriginalImg1.ColorSystem = EColorSystem.Rgb; EColorLookup1.ConvertFromRgb(EColorSystem.Yiq); EColorLookup1.Transform(OriginalImg1, OriginalImg2); //EC24Image2.Draw(pbImg2.CreateGraphics(), ScalingRatio); string path = settings.set_path() + "\\" + Path.GetFileName(files[i]); if (!Directory.Exists(settings.set_path())) { Directory.CreateDirectory(settings.set_path()); } OriginalImg2.SaveJpeg(path); } MessageBox.Show("YIQ轉換完成", "通知"); }
private void grayToolStripMenuItem_Click(object sender, EventArgs e) { for (int i = 0; i < FileListBox.Items.Count; i++) { FileListBox.SelectedItem = i; FileListBox.Refresh(); OriginalImg1.Load(files[i]); GrayImg1.SetSize(OriginalImg1); EasyImage.Oper(EArithmeticLogicOperation.Copy, new EBW8(0), GrayImg1); EasyImage.Convert(OriginalImg1, GrayImg1); string path = settings.set_path() + "\\" + Path.GetFileName(files[i]); if (!Directory.Exists(settings.set_path())) { Directory.CreateDirectory(settings.set_path()); } GrayImg1.SaveJpeg(path); } MessageBox.Show("灰階化轉換完成", "通知"); }
private void excelToolStripMenuItem_Click(object sender, EventArgs e) { Excel_APP1 = new Excel.Application(); Excel_WB1 = Excel_APP1.Workbooks.Add(); Excel_WS1 = new Excel.Worksheet(); saveFileDialog1.Filter = "Excel|*.xlsx"; saveFileDialog1.Title = "Save a Excel"; Excel_WS1 = Excel_WB1.Worksheets[1]; Excel_WS1.Name = "Data"; Excel_APP1.Cells[1, 1] = "圖片(.jpg)"; Excel_APP1.Cells[1, 2] = "Profile下"; Excel_APP1.Cells[1, 3] = "Profile上"; OriginalImg1.Load(files[0]); /*============================計算scaling ratio============================*/ float PictureBoxSizeRatio = (float)pbImg1.Width / pbImg1.Height; float ImageSizeRatio = (float)OriginalImg1.Width / OriginalImg1.Height; if (ImageSizeRatio > PictureBoxSizeRatio) { ScalingRatio = (float)pbImg1.Width / OriginalImg1.Width; } else { ScalingRatio = (float)pbImg1.Height / OriginalImg1.Height; } /*=========================================================================*/ for (int i = 0; i < FileListBox.Items.Count; i++) { FileListBox.SelectedIndex = i; FileListBox.Refresh(); OriginalImg1.Load(files[i]); OriginalImg1.Draw(pbImg1.CreateGraphics(), ScalingRatio); //EC24Image2.SetSize(EC24Image1); //EasyImage.Oper(EArithmeticLogicOperation.Copy, new EC24(0, 0, 0), EC24Image2); //EC24Image1.ColorSystem = EColorSystem.Rgb; //EColorLookup1.ConvertFromRgb(EColorSystem.Yiq); //EColorLookup1.Transform(EC24Image1, EC24Image2); //EC24Image2.Draw(pbImg2.CreateGraphics(), ScalingRatio); GrayImg1.SetSize(OriginalImg1); EasyImage.Oper(EArithmeticLogicOperation.Copy, new EBW8(0), GrayImg1); EasyImage.Convert(OriginalImg1, GrayImg1); //轉灰階 //EasyImage.Oper(EArithmeticLogicOperation.Subtract, GrayImg1, BackgroundGray, GrayImg1); //EasyImage.Threshold(GrayImg1, GrayImg1, 56); //EasyImage.OpenBox(GrayImg1, GrayImg1, settings.set_value_3()); GrayImg1.Draw(pbImg2.CreateGraphics(), ScalingRatio); EasyImage.ImageToLineSegment(GrayImg1, In, 1485, 700, 1683, 700); //設定車子進入的偵測線,判斷車子是否準備進來 EasyImage.ImageToLineSegment(GrayImg1, Out, 1485, 400, 1683, 400); //設定車子出去的偵測線,判斷車子是否準備出去 Excel_APP1.Cells[2 + i, 1] = Path.GetFileNameWithoutExtension(files[i]); Excel_APP1.Cells[2 + i, 2] = getProfileValueSum(In); Excel_APP1.Cells[2 + i, 3] = getProfileValueSum(Out); //Console.WriteLine(files[i]); } if (saveFileDialog1.ShowDialog() == DialogResult.OK && saveFileDialog1.FileName != "") { Excel_WB1.SaveAs(saveFileDialog1.FileName); } Excel_WS1 = null; Excel_WB1.Close(); Excel_WB1 = null; Excel_APP1.Quit(); Excel_APP1 = null; }
private void vehicleToolStripMenuItem_Click(object sender, EventArgs e) { float PictureBoxSizeRatio, ImageSizeRatio; codedImage1ObjectSelection.FeretAngle = 0.00f; codedImage1Encoder.GrayscaleSingleThresholdSegmenter.WhiteLayerEncoded = true; codedImage1Encoder.GrayscaleSingleThresholdSegmenter.BlackLayerEncoded = false; codedImage1Encoder.SegmentationMethod = ESegmentationMethod.GrayscaleSingleThreshold; codedImage1Encoder.GrayscaleSingleThresholdSegmenter.Mode = EGrayscaleSingleThreshold.MinResidue; OriginalImg1.Load(files[0]); /*============================計算scaling ratio============================*/ PictureBoxSizeRatio = (float)pbImg1.Width / pbImg1.Height; ImageSizeRatio = (float)OriginalImg1.Width / OriginalImg1.Height; if (ImageSizeRatio > PictureBoxSizeRatio) { ScalingRatio = (float)pbImg1.Width / OriginalImg1.Width; } else { ScalingRatio = (float)pbImg1.Height / OriginalImg1.Height; } /*=========================================================================*/ for (int i = 0; i < FileListBox.Items.Count; i++) { FileListBox.SelectedIndex = i; FileListBox.Refresh(); OriginalImg1.Load(files[i]); OriginalImg1.Draw(pbImg1.CreateGraphics(), ScalingRatio); GrayImg1.SetSize(OriginalImg1); EasyImage.Oper(EArithmeticLogicOperation.Copy, new EBW8(0), GrayImg1); EasyImage.Convert(OriginalImg1, GrayImg1); //轉灰階 EasyImage.Median(BackgroundGray, BackgroundGray); EasyImage.Median(GrayImg1, GrayImg1); EasyImage.Oper(EArithmeticLogicOperation.Subtract, GrayImg1, BackgroundGray, GrayImg1); EasyImage.Threshold(GrayImg1, GrayImg1, unchecked ((uint)EThresholdMode.MinResidue)); EasyImage.ErodeBox(GrayImg1, GrayImg1, 1); //侵蝕 EasyImage.CloseBox(GrayImg1, GrayImg1, 10); //閉合 codedImage1ObjectSelection.FeretAngle = 0.00f; codedImage1Encoder.Encode(GrayImg1, codedImage1); codedImage1ObjectSelection.Clear(); codedImage1ObjectSelection.AddObjects(codedImage1); codedImage1ObjectSelection.AttachedImage = GrayImg1; codedImage1ObjectSelection.RemoveUsingUnsignedIntegerFeature(EFeature.RunCount, 1000, ESingleThresholdMode.Less); //移除RunCount小於1000的物件 if (codedImage1ObjectSelection.ElementCount > 0) { Console.WriteLine("(" + codedImage1ObjectSelection.GetElement(0).BoundingBoxCenterX + ", " + codedImage1ObjectSelection.GetElement(0).BoundingBoxCenterY + ")"); } codedImage1.DrawFeature(pbImg1.CreateGraphics(), EDrawableFeature.BoundingBox, codedImage1ObjectSelection, ScalingRatio); // 把車的框框畫出來 GrayImg1.Draw(pbImg2.CreateGraphics(), ScalingRatio); Console.WriteLine(files[i]); } }