public static Bitmap Rotation(Bitmap sourceImage, double angle, bool keepSize) { var filter = new RotateBilinear(angle, keepSize); //filter.FillColor = Color.FromArgb(128, 128, 128); Bitmap clone24 = new Bitmap(sourceImage.Width, sourceImage.Height, PixelFormat.Format24bppRgb); using (Graphics gr = Graphics.FromImage(clone24)) { gr.DrawImage(sourceImage, new Rectangle(0, 0, clone24.Width, clone24.Height)); } var rotated = filter.Apply(clone24); clone24.Dispose(); var returnBmp = new Bitmap(rotated.Width, rotated.Height, PixelFormat.Format32bppArgb); using (Graphics gr = Graphics.FromImage(returnBmp)) { gr.DrawImage(rotated, new Rectangle(0, 0, returnBmp.Width, returnBmp.Height)); } rotated.Dispose(); return(returnBmp); }
//Generally don't have to change this private void video_NewFrame(object sender, NewFrameEventArgs eventArgs) { img = (Bitmap)eventArgs.Frame.Clone(); //Bitmap image = (Bitmap)img; Bitmap img2; RotateBilinear ro = new RotateBilinear(Rotatevid, true); img2 = ro.Apply(img); if (zoomvid > 0) { img3 = zoom(img2, new Size(zoomvid, zoomvid)); } else { img3 = img2; } myCanvas.g = Graphics.FromImage(img3); myCanvas.Run(x, y, shapeselect, ColourSelect, SizeSelect, weightselect, clearbut); myCanvas.g.Dispose(); viewFinder.Image = img3; //viewFinder.Image = img; }
private void RotateImage() { DocumentSkewChecker skewChecker = new DocumentSkewChecker(); skewChecker.MaxSkewToDetect = 45; double angle = skewChecker.GetSkewAngle(_recogimg); //Максимальный угол, при котором идет поворот - 45 градусов, после этого изображение не поворачивается if (Math.Abs(angle) < 45) { RotateBilinear rotationFilter = new RotateBilinear(-angle, true); rotationFilter.FillColor = Color.Black; _recogimg = rotationFilter.Apply(_recogimg); _markersimg = rotationFilter.Apply(_markersimg); } }
public Bitmap DocumentAlign(Bitmap image) { try { // get grayscale image from current image Bitmap grayImage = (image.PixelFormat == PixelFormat.Format8bppIndexed) ? AForge.Imaging.Image.Clone(image) : AForge.Imaging.Filters.Grayscale.CommonAlgorithms.BT709.Apply(image); // threshold it using adaptive Otsu thresholding OtsuThreshold threshold = new OtsuThreshold(); threshold.ApplyInPlace(grayImage); // get skew angle DocumentSkewChecker skewChecker = new DocumentSkewChecker(); double angle = skewChecker.GetSkewAngle(grayImage); if ((angle < -skewChecker.MaxSkewToDetect) || (angle > skewChecker.MaxSkewToDetect)) { throw new ApplicationException(); } // create rotation filter RotateBilinear rotationFilter = new RotateBilinear(-angle); rotationFilter.FillColor = Color.White; // rotate image applying the filter return(rotationFilter.Apply(image)); } catch { Console.WriteLine("Failed determining skew angle. Is it reallly a scanned document?"); return(image); } }
public bool Deskew() { System.Drawing.Bitmap memoryImageT = new System.Drawing.Bitmap(System.Drawing.Image.FromFile( archivo)); Emgu.CV.Image <Emgu.CV.Structure.Gray, Byte> imgOrig = new Emgu.CV.Image <Emgu.CV.Structure.Gray, Byte>(memoryImageT); System.Drawing.Bitmap bmp = imgOrig.ToBitmap(); UnmanagedImage unmanagedImage = UnmanagedImage.FromManagedImage(bmp); DocumentSkewChecker skewChecker = new DocumentSkewChecker(); double angle = skewChecker.GetSkewAngle(unmanagedImage); // create rotation filter archivo = ruta + "files/imagen.bmp"; Console.WriteLine("El angulo de inclinacion del documento es " + angle.ToString()); if (angle != 0) { RotateBilinear rotationFilter = new RotateBilinear(-angle); rotationFilter.FillColor = Color.White; // rotate image applying the filter Bitmap rotatedImage = rotationFilter.Apply(bmp); Emgu.CV.Image <Emgu.CV.Structure.Gray, byte> image = new Emgu.CV.Image <Emgu.CV.Structure.Gray, byte>(rotatedImage); guardarArchivo(image.Mat, "imagen"); return(true); } guardarArchivo(imgOrig.Mat, "imagen"); return(false); }
public static void ExecuteActivity(object Parameter) { WorkPackage WorkPackage = (WorkPackage)Parameter; Rectangle Assignment = (Rectangle)WorkPackage.Assignment; //Step 1: Deskew Bitmap ImageToDeskew; ImageToDeskew = WorkPackage.Image.Image; DocumentSkewChecker skewChecker = new DocumentSkewChecker(); skewChecker.MinBeta = -5; skewChecker.MaxBeta = 5; // get documents skew angle double angle = skewChecker.GetSkewAngle(ImageToDeskew); if (Math.Abs(angle) > 2) { Console.WriteLine(" Deskewing original image"); // create rotation filter RotateBilinear rotationFilter = new RotateBilinear(-angle); rotationFilter.FillColor = Color.White; // rotate image applying the filter Bitmap rotatedImage = rotationFilter.Apply(ImageToDeskew); //set the rotated image in the PageImage of the Workpackage WorkPackage.Image.Image = rotatedImage; } //WorkPackage WorkPackage = (WorkPackage)Parameter; //Rectangle Assignment = (Rectangle)WorkPackage.Assignment; int x = Assignment.X; int y = Assignment.Y; while (y < Assignment.Bottom) { x = 0; while (x < Assignment.Right) { if (WorkPackage.Image.Bytes[x, y] > WorkPackage.Image.Threshold) { WorkPackage.Image.BinaryBytes[x, y] = 0xFF; } else { WorkPackage.Image.BinaryBytes[x, y] = 0x0; } x++; } y++; } SignalWorkDone(); }
public static Bitmap skew(Bitmap source) // 기울어짐 바로잡기 { // create grayscale filter (BT709) Grayscale filter = new Grayscale(0.2125, 0.7154, 0.0721); // 8비트 grayscale 로 바꾸고 // apply the filter Bitmap grayImage = filter.Apply(source); // create instance of skew checker DocumentSkewChecker skewChecker = new DocumentSkewChecker(); // 8비트 grayscale 로 넣어줘야 함 // // get documents skew angle double angle = skewChecker.GetSkewAngle(grayImage); // 기울어진 각도를 얻고 Bitmap tmp = source; // convert to 24 bits per pixel source = imageProcess.Clone(tmp, PixelFormat.Format24bppRgb); // 로테이션 전에 24비트로 바꿔주고 // delete old image tmp.Dispose(); // create rotation filter RotateBilinear rotationFilter = new RotateBilinear(-angle); rotationFilter.FillColor = Color.White; // rotate image applying the filter Bitmap rotatedImage = rotationFilter.Apply(source); // 원래 이미지를 가져다가 각도만큼 돌리고(원래 이미지는 24비트로 넣어줘야함) return(rotatedImage); }
/// <summary> /// Crop the blob from the image /// </summary> private Bitmap CropBlob(BlobPanel blob, System.Drawing.Image source, int rotationAngel = 0) { // Create the target image, this is a squared image. int size = Math.Max(blob.Height, blob.Width); Bitmap newImage = new Bitmap(size, size, PixelFormat.Format24bppRgb); // Get the graphics object of the image. Graphics g = Graphics.FromImage(newImage); // Create the background color to use (the image we create is larger than the blob (as we squared it) // so this would be the color of the excess areas. Color bColor = Color.FromArgb((int)txtExtractedBackColor.Value, (int)txtExtractedBackColor.Value, (int)txtExtractedBackColor.Value); // Fill back color. g.FillRectangle(new SolidBrush(bColor), 0, 0, size, size); // Now we clip the blob from the PictureBox image. g.DrawImage(source, new Rectangle(0, 0, blob.Width, blob.Height), blob.Left, blob.Top, blob.Width, blob.Height, GraphicsUnit.Pixel); g.Dispose(); if (rotationAngel != 0) { RotateBilinear filter = new RotateBilinear(rotationAngel, true); filter.FillColor = bColor; // apply the filter newImage = filter.Apply(newImage); } // Resize the image. ResizeBilinear resizefilter = new ResizeBilinear((int)txtExportSize.Value, (int)txtExportSize.Value); newImage = resizefilter.Apply(newImage); return(newImage); }
private void trackBar1_Scroll(object sender, EventArgs e) { Bitmap b = (Bitmap)picOriginal.Image; RotateBilinear ro = new RotateBilinear(trackBar1.Value, true); Bitmap c = ro.Apply(b); this.picResult.Image = c; }
private void btnRotateLeft_Click(object sender, EventArgs e) { Bitmap image = (Bitmap)pictureBoxScan.Image; RotateBilinear ro = new RotateBilinear(180, true); Bitmap image2 = ro.Apply(image); pictureBoxScan.Image = image2; }
public Bitmap RotateImg(Bitmap bp, int angle) { RotateBilinear filter = new RotateBilinear(angle, true); // apply the filter Bitmap newImage = filter.Apply(bp); return(newImage); }
/// <summary> /// 旋转位图 /// </summary> /// <param name="bmp">源位图</param> /// <param name="angle">旋转角度</param> /// <returns>返回旋转后的位图</returns> public static Bitmap RotateImage(Bitmap bmp, double angle) { // create filter - rotate for 30 degrees keeping original image size RotateBilinear filter = new RotateBilinear(angle, true); // apply the filter return(filter.Apply(bmp)); }
public string Executar(string arquivoOrigem, int angulo, ImageFormat formatoSaida = null) { ImageInfo imageInfo; var bitmap = ImageDecoder.DecodeFromFile(arquivoOrigem, out imageInfo); var rotationPaisagem = new RotateBilinear(angulo) { FillColor = Color.White }; Bitmap imagemGirada; if (imageInfo.BitsPerPixel == 32) { var grayImage = Grayscale.CommonAlgorithms.Y.Apply(bitmap); imagemGirada = rotationPaisagem.Apply(grayImage); grayImage.Dispose(); } else { imagemGirada = rotationPaisagem.Apply(bitmap); } bitmap.Dispose(); var nomeArquivo = string.Format( "{0}{1}", Guid.NewGuid(), Path.GetExtension(arquivoOrigem)); var nomeGirado = Path.Combine( ConfiguracaoAjusteImagem.CaminhoPadrao, nomeArquivo); if (formatoSaida == null) { formatoSaida = ImageFormat.Png; } imagemGirada.Save(nomeGirado, formatoSaida); imagemGirada.Dispose(); return(nomeGirado); }
//private void RotateImage(Bitmap srcimg, int angle) //{ // if (srcimg == null) // throw new ArgumentNullException("image"); // if (!_rotatedimg_table.ContainsKey(angle)) // { // const double pi2 = Math.PI / 2.0; // // Why can't C# allow these to be const, or at least readonly // // *sigh* I'm starting to talk like Christian Graus :omg: // double oldWidth = _width; // double oldHeight = _height; // // Convert degrees to radians // double theta = ((double)angle) * Math.PI / 180.0; // double locked_theta = theta; // // Ensure theta is now [0, 2pi) // while (locked_theta < 0.0) // locked_theta += 2 * Math.PI; // double newWidth, newHeight; // int nWidth, nHeight; // The newWidth/newHeight expressed as ints // #region Explaination of the calculations // #endregion // double adjacentTop, oppositeTop; // double adjacentBottom, oppositeBottom; // // We need to calculate the sides of the triangles based // // on how much rotation is being done to the bitmap. // // Refer to the first paragraph in the explaination above for // // reasons why. // if ((locked_theta >= 0.0 && locked_theta < pi2) || // (locked_theta >= Math.PI && locked_theta < (Math.PI + pi2))) // { // adjacentTop = Math.Abs(Math.Cos(locked_theta)) * oldWidth; // oppositeTop = Math.Abs(Math.Sin(locked_theta)) * oldWidth; // adjacentBottom = Math.Abs(Math.Cos(locked_theta)) * oldHeight; // oppositeBottom = Math.Abs(Math.Sin(locked_theta)) * oldHeight; // } // else // { // adjacentTop = Math.Abs(Math.Sin(locked_theta)) * oldHeight; // oppositeTop = Math.Abs(Math.Cos(locked_theta)) * oldHeight; // adjacentBottom = Math.Abs(Math.Sin(locked_theta)) * oldWidth; // oppositeBottom = Math.Abs(Math.Cos(locked_theta)) * oldWidth; // } // newWidth = adjacentTop + oppositeBottom; // newHeight = adjacentBottom + oppositeTop; // nWidth = (int)Math.Ceiling(newWidth); // nHeight = (int)Math.Ceiling(newHeight); // Bitmap rotatedBmp = new Bitmap(nWidth, nHeight); // using (Graphics g = Graphics.FromImage(rotatedBmp)) // { // g.Clear(Color.White); // // This array will be used to pass in the three points that // // make up the rotated srcimg // Point[] points; // if (locked_theta >= 0.0 && locked_theta < pi2) // { // points = new Point[] { // new Point( (int) oppositeBottom, 0 ), // new Point( nWidth, (int) oppositeTop ), // new Point( 0, (int) adjacentBottom ) // }; // } // else if (locked_theta >= pi2 && locked_theta < Math.PI) // { // points = new Point[] { // new Point( nWidth, (int) oppositeTop ), // new Point( (int) adjacentTop, nHeight ), // new Point( (int) oppositeBottom, 0 ) // }; // } // else if (locked_theta >= Math.PI && locked_theta < (Math.PI + pi2)) // { // points = new Point[] { // new Point( (int) adjacentTop, nHeight ), // new Point( 0, (int) adjacentBottom ), // new Point( nWidth, (int) oppositeTop ) // }; // } // else // { // points = new Point[] { // new Point( 0, (int) adjacentBottom ), // new Point( (int) oppositeBottom, 0 ), // new Point( (int) adjacentTop, nHeight ) // }; // } // g.DrawImage(srcimg, points); // g.Dispose(); // } // //Console.WriteLine((int)angle); // _rotatedimg_table.Add(angle, rotatedBmp); // Rectangle bbx = BBX(rotatedBmp); // if (_max_width < bbx.Width) // { // _max_width = bbx.Width; // _max_width_idx = angle; // } // } //} //private void RotateImage(string path, int angle) //{ // Bitmap srcimg = new Bitmap(path); // if (srcimg == null) // throw new ArgumentNullException("image"); // if (!_rotatedimg_table.ContainsKey(angle)) // { // const double pi2 = Math.PI / 2.0; // // Why can't C# allow these to be const, or at least readonly // // *sigh* I'm starting to talk like Christian Graus :omg: // double oldWidth = _width; // double oldHeight = _height; // // Convert degrees to radians // double theta = ((double)angle) * Math.PI / 180.0; // double locked_theta = theta; // // Ensure theta is now [0, 2pi) // while (locked_theta < 0.0) // locked_theta += 2 * Math.PI; // double newWidth, newHeight; // int nWidth, nHeight; // The newWidth/newHeight expressed as ints // #region Explaination of the calculations // #endregion // double adjacentTop, oppositeTop; // double adjacentBottom, oppositeBottom; // // We need to calculate the sides of the triangles based // // on how much rotation is being done to the bitmap. // // Refer to the first paragraph in the explaination above for // // reasons why. // if ((locked_theta >= 0.0 && locked_theta < pi2) || // (locked_theta >= Math.PI && locked_theta < (Math.PI + pi2))) // { // adjacentTop = Math.Abs(Math.Cos(locked_theta)) * oldWidth; // oppositeTop = Math.Abs(Math.Sin(locked_theta)) * oldWidth; // adjacentBottom = Math.Abs(Math.Cos(locked_theta)) * oldHeight; // oppositeBottom = Math.Abs(Math.Sin(locked_theta)) * oldHeight; // } // else // { // adjacentTop = Math.Abs(Math.Sin(locked_theta)) * oldHeight; // oppositeTop = Math.Abs(Math.Cos(locked_theta)) * oldHeight; // adjacentBottom = Math.Abs(Math.Sin(locked_theta)) * oldWidth; // oppositeBottom = Math.Abs(Math.Cos(locked_theta)) * oldWidth; // } // newWidth = adjacentTop + oppositeBottom; // newHeight = adjacentBottom + oppositeTop; // nWidth = (int)Math.Ceiling(newWidth); // nHeight = (int)Math.Ceiling(newHeight); // Bitmap rotatedBmp = new Bitmap(nWidth, nHeight); // using (Graphics g = Graphics.FromImage(rotatedBmp)) // { // g.Clear(Color.White); // // This array will be used to pass in the three points that // // make up the rotated srcimg // Point[] points; // if (locked_theta >= 0.0 && locked_theta < pi2) // { // points = new Point[] { // new Point( (int) oppositeBottom, 0 ), // new Point( nWidth, (int) oppositeTop ), // new Point( 0, (int) adjacentBottom ) // }; // } // else if (locked_theta >= pi2 && locked_theta < Math.PI) // { // points = new Point[] { // new Point( nWidth, (int) oppositeTop ), // new Point( (int) adjacentTop, nHeight ), // new Point( (int) oppositeBottom, 0 ) // }; // } // else if (locked_theta >= Math.PI && locked_theta < (Math.PI + pi2)) // { // points = new Point[] { // new Point( (int) adjacentTop, nHeight ), // new Point( 0, (int) adjacentBottom ), // new Point( nWidth, (int) oppositeTop ) // }; // } // else // { // points = new Point[] { // new Point( 0, (int) adjacentBottom ), // new Point( (int) oppositeBottom, 0 ), // new Point( (int) adjacentTop, nHeight ) // }; // } // g.DrawImage(srcimg, points); // g.Dispose(); // } // //Console.WriteLine((int)angle); // _rotatedimg_table.Add(angle, rotatedBmp); // Rectangle bbx = BBX(rotatedBmp); // if (_max_width < bbx.Width) // { // _max_width = bbx.Width; // _max_width_idx = angle; // } // } //} private void RotateImage(Bitmap srcimg, int angle) { if (!_rotatedimg_table.ContainsKey(angle)) { RotateBilinear filter = new RotateBilinear(angle); Bitmap rotateimg = ImageUtils.InvertColors(filter.Apply(ImageUtils.InvertColors(srcimg))); _rotatedimg_table.Add(angle, rotateimg); } }
private void button1_Click(object sender, EventArgs e) { double width = Math.Floor(img1.Width / img1.HorizontalResolution); double height = Math.Floor(img1.Height / img1.VerticalResolution); label1.Text = img1.HorizontalResolution + " " + img1.VerticalResolution; img1 = Grayscale.CommonAlgorithms.BT709.Apply(img1); Threshold filter = new Threshold(150); filter.ApplyInPlace(img1); DocumentSkewChecker skewChecker = new DocumentSkewChecker(); double angle = skewChecker.GetSkewAngle(img1); RotateBilinear rotationFilter = new RotateBilinear(-angle); rotationFilter.FillColor = Color.White; img1 = rotationFilter.Apply(img1); pictureBox1.Image = img1; TesseractEngine engine = new TesseractEngine(@"C:\Users\moham\source\repos\pfe3\tessdata\", "fra", EngineMode.Default); if (((width == 3) && (height == 2)) || (width == 2 && height == 3)) { if ((width == 2 && height == 3)) { rotationFilter = new RotateBilinear(-90); rotationFilter.FillColor = Color.White; img1 = rotationFilter.Apply(img1); Console.WriteLine("if1"); } string ocrText = engine.Process(img1, new Rect(700, 450, 150, 100)).GetText(); engine.Dispose(); ocrText = ocrText.Replace(" ", " "); Console.WriteLine(ocrText + " " + ocrText.Length); if (ocrText.Length <= 9) { label1.Text = "carte national " + ocrText; } else { rotationFilter = new RotateBilinear(180); rotationFilter.FillColor = Color.White; img1 = rotationFilter.Apply(img1); engine = new TesseractEngine(@"C:\Users\moham\source\repos\pfe3\tessdata\", "fra", EngineMode.Default); ocrText = engine.Process(img1, new Rect(700, 450, 150, 100)).GetText(); engine.Dispose(); ocrText = ocrText.Replace(" ", ""); } label1.Text = "carte national " + ocrText; pictureBox1.Image = img1; engine.Dispose(); } else if ((width == 8 && height == 11) || (width == 11 && height == 8)) { } else { } }
private void trackBar2_Scroll(object sender, EventArgs e) { rotateLabel.Text = trackBar2.Value.ToString(); Bitmap image = (Bitmap)pictureBox1.Image; RotateBilinear rotate = new RotateBilinear(trackBar2.Value, true); Bitmap image2 = rotate.Apply(image); pictureBox2.Image = image2; }
public static Bitmap RotateBilinear(Bitmap bmp, int degree) { // create filter - rotate for 30 degrees keeping original image size RotateBilinear filter = new RotateBilinear(degree, true); // apply the filter Bitmap newImage = filter.Apply(bmp); return(newImage); }
public static System.Drawing.Image AforgeAutoCrop(Bitmap selectedImage) { Bitmap autoCropImage = null; try { autoCropImage = selectedImage; // create grayscale filter (BT709) Grayscale filter = new Grayscale(0.2125, 0.7154, 0.0721); Bitmap grayImage = filter.Apply(autoCropImage); // create instance of skew checker DocumentSkewChecker skewChecker = new DocumentSkewChecker(); // get documents skew angle double angle = 0; // skewChecker.GetSkewAngle(grayImage); // create rotation filter RotateBilinear rotationFilter = new RotateBilinear(-angle); rotationFilter.FillColor = Color.White; // rotate image applying the filter Bitmap rotatedImage = rotationFilter.Apply(grayImage); new ContrastStretch().ApplyInPlace(rotatedImage); new Threshold(50).ApplyInPlace(rotatedImage); BlobCounter bc = new BlobCounter(); bc.FilterBlobs = true; // bc.MinWidth = 500; //bc.MinHeight = 500; bc.ProcessImage(rotatedImage); Rectangle[] rects = bc.GetObjectsRectangles(); if (rects.Length == 0) { // CAN'T CROP } else if (rects.Length == 1) { autoCropImage = autoCropImage.Clone(rects[0], autoCropImage.PixelFormat);; } else if (rects.Length > 1) { // get largets rect Console.WriteLine("Using largest rectangle found in image "); var r2 = rects.OrderByDescending(r => r.Height * r.Width).ToList(); autoCropImage = autoCropImage.Clone(r2[0], autoCropImage.PixelFormat); } else { Console.WriteLine("Huh? on image "); } } catch (Exception ex) { //MessageBox.Show(ex.Message); //CAN'T CROP } return(autoCropImage); }
public IImage Apply(IImage image) { var filter = new DocumentSkewChecker(); var bitmap = image.ToBgr().Lock().AsAForgeImage(); var grayscale = new Grayscale(0.2125, 0.7154, 0.0721).Apply(bitmap); var angle = filter.GetSkewAngle(grayscale); var rotationFilter = new RotateBilinear(-angle); return(rotationFilter.Apply(grayscale).AsImage()); }
void goruntuGuncelle() { try { if (comboBox1.SelectedIndex == 0) { //resim döndürme filtresi tanımlandı //bu filtre sistemi yormuyor //diğerleri sistemi zorluyor //resim döndürme saat yönünün tersine doğru yapılıyor //fonksiyona paremetre olarak true verilirse resmin tamamı ekrana sığdırılmıyor //bazı yerler kırpılıyor //fakat resim boyutu (genişliği ve yükseliği) değişmiyor //görüntü daha güzel görünüyor //eğer false olursa resim küçültme büyütme işlemelerinde resim boyutuda (genişliği ve yükseliği) değişiyor //yani false olunca resim daima ekrana sığdırılıyor RotateNearestNeighbor boyutlandirmaFiltresi = new RotateNearestNeighbor(trackBar1.Value, tamEkran); //resim dosyasına filtre uygulandı pictureBox2.Image = boyutlandirmaFiltresi.Apply((Bitmap)pictureBox1.Image); //resim boyut değiştirme filtresi tanımlandı //bu filtre sistemi yormuyor //diğerleri sistemi zorluyor ResizeNearestNeighbor boyutlandirma = new ResizeNearestNeighbor(resim.Width + trackBar2.Value, resim.Height + trackBar2.Value); //resim dosyasına filtre uygulandı pictureBox2.Image = boyutlandirma.Apply((Bitmap)pictureBox1.Image); } if (comboBox1.SelectedIndex == 1) { //resim döndürme filtresi tanımlandı RotateBilinear boyutlandirmaFiltresi = new RotateBilinear(trackBar1.Value, tamEkran); //resim dosyasına filtre uygulandı pictureBox2.Image = boyutlandirmaFiltresi.Apply((Bitmap)pictureBox1.Image); //resim boyut değiştirme filtresi tanımlandı ResizeBicubic boyutlandirma = new ResizeBicubic(resim.Width + trackBar2.Value, resim.Height + trackBar2.Value); //resim dosyasına filtre uygulandı pictureBox2.Image = boyutlandirma.Apply((Bitmap)pictureBox1.Image); } if (comboBox1.SelectedIndex == 2) { //resim döndürme filtresi tanımlandı RotateBicubic boyutlandirmaFiltresi = new RotateBicubic(trackBar1.Value, tamEkran); //resim dosyasına filtre uygulandı pictureBox2.Image = boyutlandirmaFiltresi.Apply((Bitmap)pictureBox1.Image); //resim boyut değiştirme filtresi tanımlandı ResizeBilinear boyutlandirma = new ResizeBilinear(resim.Width + trackBar2.Value, resim.Height + trackBar2.Value); //resim dosyasına filtre uygulandı pictureBox2.Image = boyutlandirma.Apply((Bitmap)pictureBox1.Image); } } catch { } }
private void btnDondur_Click(object sender, EventArgs e) { DocumentSkewChecker skewChecker = new DocumentSkewChecker(); double angle = skewChecker.GetSkewAngle((Bitmap)pictureBox4.Image); RotateBilinear rotationFilter = new RotateBilinear(-angle); rotationFilter.FillColor = Color.White; // rotate image applying the filter Bitmap rotatedImage = rotationFilter.Apply((Bitmap)pictureBox4.Image); pictureBox1.Image = rotatedImage; }
private void CheckUp() { List <double> disttohight = new List <double>(); AForge.Point hightpoint = new AForge.Point((float)_markersimg.Width / 2.0f, 0); for (int iteration = 0; iteration < 4; iteration++) { FindCenterMarker(); // RotateBicubic rbf = new RotateBicubic(-90); RotateBilinear rbf = new RotateBilinear(-90); _markersimg = rbf.Apply(_markersimg); disttohight.Add(Geometry.EuclidianDistance(_tcmarker.Blob.CenterOfGravity, hightpoint)); } double mindist = disttohight.Min(); double angle = disttohight.IndexOf(mindist) * -90; RotateBilinear _recogimgrotator = new RotateBilinear(angle); _recogimg = _recogimgrotator.Apply(_recogimg); _markersimg = _recogimgrotator.Apply(_markersimg); }
/* * 4- do a feature detection/extraction with edge detection technique (maybe) to identify characters * (groups of connected pixels). (i don't know what's the best for character: edge, corner or blob detection...) * */ public void Detection(ref Bitmap image) { // create instance of skew checker DocumentSkewChecker skewChecker = new DocumentSkewChecker(); // get documents skew angle double angle = skewChecker.GetSkewAngle(image); // create rotation filter RotateBilinear rotationFilter = new RotateBilinear(-angle); rotationFilter.FillColor = Color.White; // rotate image applying the filter Bitmap rotatedImage = rotationFilter.Apply(image); }
public IEnumerable <Bitmap> Apply(Bitmap bitmap) { // assuming scanned background is white we need to invert for the algo to work var copy = new Invert().Apply(bitmap); copy = EnsureGrayscale(copy); new Threshold { ThresholdValue = 25 }.ApplyInPlace(copy); new FillHoles().ApplyInPlace(copy); var blobCounter = new BlobCounter { // set filtering options FilterBlobs = true, MinWidth = 50, MinHeight = 50, }; blobCounter.ProcessImage(copy); var blobs = blobCounter.GetObjectsInformation(); if (blobs.Any()) { var invertedOriginal = new Invert().Apply(bitmap); foreach (var blob in blobs) { // use inverted source to ensure correct edge colors blobCounter.ExtractBlobsImage(invertedOriginal, blob, false); var blobImage = blob.Image.ToManagedImage(); // straighten var angle = new DocumentSkewChecker().GetSkewAngle(EnsureGrayscale(blobImage)); var rotationFilter = new RotateBilinear(-angle) { FillColor = Color.Black }; blobImage = rotationFilter.Apply(blobImage); // crop blobImage = new ExtractBiggestBlob().Apply(blobImage); new Invert().ApplyInPlace(blobImage); yield return(blobImage); } } else { yield return(bitmap); } }
/// <summary> /// 图片校正处理 /// </summary> /// <param name="bitmap">预处理的图片</param> /// <returns></returns> public static Bitmap ImageCorrection(Bitmap bitmap) { if (bitmap == null) { return(null); } var skewChecker = new DocumentSkewChecker(); double angle = skewChecker.GetSkewAngle(bitmap); RotateBilinear rotationFilter = new RotateBilinear(-angle); rotationFilter.FillColor = Color.White; bitmap = rotationFilter.Apply(bitmap); return(bitmap); }
private static Bitmap Deskewimage(Bitmap image) { // create instance of skew checker DocumentSkewChecker skewChecker = new DocumentSkewChecker(); // get documents skew angle double angle = skewChecker.GetSkewAngle(image); // create rotation filter RotateBilinear rotationFilter = new RotateBilinear(-angle) { FillColor = Color.White }; // rotate image applying the filter return(rotationFilter.Apply(image)); }
private void GirarArquivo(string arquivoOrigem, string arquivoGirado, double angulo) { var rotationPaisagem = new RotateBilinear(angulo) { FillColor = Color.White }; var bitmap = ImageDecoder.DecodeFromFile(arquivoOrigem); var novaImagem = rotationPaisagem.Apply(bitmap); bitmap.Dispose(); this.SalvarComo(novaImagem, arquivoGirado, System.Drawing.Imaging.ImageFormat.Jpeg, 8); novaImagem.Dispose(); }
private void button7_Click(object sender, EventArgs e) { string path = OriPath + "\\test.jpg"; string pathoutput2 = OriPath + "\\testoutput2.jpg"; string pathoutput3 = OriPath + "\\testoutput3.jpg"; string pathoutput4 = OriPath + "\\testoutput4.jpg"; string pathoutput5 = OriPath + "\\testoutput5.jpg"; string pathoutput6 = OriPath + "\\testoutput6.jpg"; string pathoutput7 = OriPath + "\\testoutput7.jpg"; Bitmap image = new Bitmap(path); // 普通最近领算法 ResizeNearestNeighbor filter = new ResizeNearestNeighbor(4000, 3000); // 双线性插值 ResizeBicubic filter2 = new ResizeBicubic(4000, 3000); // 双三次插值 ResizeBilinear filter3 = new ResizeBilinear(4000, 3000); // create filter - rotate for 30 degrees keeping original image size RotateNearestNeighbor filter4 = new RotateNearestNeighbor(30, true); RotateBilinear filter5 = new RotateBilinear(30, true); RotateBicubic filter6 = new RotateBicubic(30, true); // apply the filter Bitmap newImage = filter.Apply(image); newImage.Save(pathoutput2); newImage = filter2.Apply(image); newImage.Save(pathoutput3); newImage = filter3.Apply(image); newImage.Save(pathoutput4); newImage = filter4.Apply(image); newImage.Save(pathoutput5); newImage = filter5.Apply(image); newImage.Save(pathoutput6); newImage = filter6.Apply(image); newImage.Save(pathoutput7); }
public Bitmap RotateImg(Bitmap bp, int angle) { //Bitmap rotatedImage = new Bitmap(bp.Width, bp.Height); //using (Graphics g = Graphics.FromImage(rotatedImage)) //{ // g.TranslateTransform(bp.Width / 2, bp.Height / 2); //set the rotation point as the center into the matrix // g.RotateTransform(angle); //rotate // g.TranslateTransform(-bp.Width / 2, -bp.Height / 2); //restore rotation point into the matrix // g.DrawImage(bp, new Point(0, 0)); //draw the image on the new bitmap //} //return rotatedImage; RotateBilinear filter = new RotateBilinear(angle, true); // apply the filter Bitmap newImage = filter.Apply(bp); return(newImage); }
private void trackBar1_Scroll(object sender, EventArgs e) { try { Bitmap image = (Bitmap)ReviewPicture_Box_.Image; RotateBilinear ro = new RotateBilinear(trackBar1.Value, true); if (image != null) { trackBar1.Enabled = true; Bitmap image2 = ro.Apply(image); TrackingImage_Box.Image = image2; } } catch (System.IO.FileNotFoundException) { MessageBox.Show("There was an error." + "Check the path to the bitmap."); } }