private void timer1_Tick(object sender, EventArgs e) { //image = wc.GetCurrentImage(); //picOriginalImage.Image = image; //Bitmap analyzingImage = new Bitmap(image); Bitmap img2 = new Bitmap(picOriginalImage.Image); if (rdEdgeDetection.Checked) { #region Sobel edge detection //UnsafeBitmap uBitmap = new UnsafeBitmap((Bitmap)wc.GetCurrentImage()); //ConvMatrix cmx = new ConvMatrix(); //ConvMatrix cmy = new ConvMatrix(); //cmx.TopLeft = -1; //cmx.TopMid = 0; //cmx.TopRight = 1; //cmx.MidLeft = -2; //cmx.Pixel = 0; //cmx.MidRight = 2; //cmx.BottomLeft = -1; //cmx.BottomMid = 0; //cmx.BottomRight = 1; //cmy.TopLeft = 1; //cmy.TopMid = 2; //cmy.TopRight = 1; //cmy.MidLeft = 0; //cmy.Pixel = 0; //cmy.MidRight = 0; //cmy.BottomLeft = -1; //cmy.BottomMid = -2; //cmy.BottomRight = -1; //uBitmap.SobelEdgeDetector(cmx, cmy); //image = uBitmap.Bitmap; #endregion #region Canny Edge Detection //timer1.Stop(); Bitmap temBM = new Bitmap(img2); UnsafeBitmap uBitmap = new UnsafeBitmap(temBM); uBitmap.MakeGreyUnsafeFaster(); cannyEdge.ApplyCannyEdgeDetection(uBitmap.Bitmap); //analyzingImage = cannyEdge.Image; img2 = cannyEdge.Image; //timer1.Start(); #endregion } else if (rdChangeDetection.Checked) { if (previousImage != null) { Bitmap temBM = null; temBM = new Bitmap(img2); ChangeDetection cd = new ChangeDetection(previousImage, temBM); previousImage = new Bitmap(temBM); cd.ApplyChangeDetection(); img2 = cd.resultImage; } else { Bitmap temBM = null; temBM = new Bitmap(img2); previousImage = temBM; } } else { // do nothing here } picAnalyzedImage.Image = img2; //wc.GetCurrentImage(); }
private void ProcessImage(Bitmap img2) { //image = wc.GetCurrentImage(); image = new Bitmap(img2); //picOriginalImage.Image = image; //Bitmap analyzingImage = new Bitmap(image); //Bitmap img2 = new Bitmap(picOriginalImage.Image); if (rdEdgeDetection.Checked) { #region Sobel edge detection //UnsafeBitmap uBitmap = new UnsafeBitmap((Bitmap)wc.GetCurrentImage()); //ConvMatrix cmx = new ConvMatrix(); //ConvMatrix cmy = new ConvMatrix(); //cmx.TopLeft = -1; //cmx.TopMid = 0; //cmx.TopRight = 1; //cmx.MidLeft = -2; //cmx.Pixel = 0; //cmx.MidRight = 2; //cmx.BottomLeft = -1; //cmx.BottomMid = 0; //cmx.BottomRight = 1; //cmy.TopLeft = 1; //cmy.TopMid = 2; //cmy.TopRight = 1; //cmy.MidLeft = 0; //cmy.Pixel = 0; //cmy.MidRight = 0; //cmy.BottomLeft = -1; //cmy.BottomMid = -2; //cmy.BottomRight = -1; //uBitmap.SobelEdgeDetector(cmx, cmy); //image = uBitmap.Bitmap; #endregion #region Canny Edge Detection //timer1.Stop(); Bitmap temBM = new Bitmap(image); UnsafeBitmap uBitmap = new UnsafeBitmap(temBM); uBitmap.MakeGreyUnsafeFaster(); cannyEdge.ApplyCannyEdgeDetection(uBitmap.Bitmap); //analyzingImage = cannyEdge.Image; image = cannyEdge.Image; //timer1.Start(); #endregion } else if (rdChangeDetection.Checked) { if (previousImage != null) { Bitmap temBM = null; temBM = new Bitmap(image); ChangeDetection cd = new ChangeDetection(previousImage, temBM); previousImage = new Bitmap(temBM); cd.ApplyChangeDetection(); image = cd.resultImage; } else { Bitmap temBM = null; temBM = new Bitmap(img2); previousImage = temBM; } } else if (rdFollowLaserDot.Checked) { UnsafeBitmap _ubit = new UnsafeBitmap(image); Point laserLocation = _ubit.LaserDotsRecognizer(); Graphics g = Graphics.FromImage(image); using (Pen pen = new Pen(Color.FromArgb(160, 255, 160), 3)) { g.DrawLine(pen, new Point(laserLocation.X, 0), new Point(laserLocation.X, 240)); g.DrawLine(pen, new Point(0, laserLocation.Y), new Point(320, laserLocation.Y)); } g.Dispose(); if (laserLocation.X > 180) { _frmPanTilt.IncreaseTrackBarValueBy("tbMotor2", -1); } else if (laserLocation.X < 140) { _frmPanTilt.IncreaseTrackBarValueBy("tbMotor2", 1); } if (laserLocation.Y > 140) { _frmPanTilt.IncreaseTrackBarValueBy("tbMotor1", -1); } else if (laserLocation.Y < 100) { _frmPanTilt.IncreaseTrackBarValueBy("tbMotor1", 1); } } else if (rdLineFollowing.Checked) { FollowLine fl = new FollowLine(image); string direction = fl.ChooseDirection(); // draw 2 lines that cross at line we are following Graphics g = Graphics.FromImage(image); using (Pen pen = new Pen(Color.FromArgb(160, 255, 160), 1)) { g.DrawLine(pen, new Point(fl.CenterX, 0), new Point(fl.CenterX, 240)); // vertical g.DrawLine(pen, new Point(fl.LeftBorder, 0), new Point(fl.LeftBorder, 240)); // vertical g.DrawLine(pen, new Point(fl.RightBorder, 0), new Point(fl.RightBorder, 240)); // vertical //g.DrawLine(pen, new Point(0, laserLocation.Y), new Point(320, laserLocation.Y)); // horizontal } g.Dispose(); } else { // do nothing here } picAnalyzedImage.Image = image; //wc.GetCurrentImage(); }