c#从形状中检测并裁剪图像

时间:2018-03-26 05:32:14

标签: c# image-processing ocr

我一直在寻找开放的简历,但无法找到我需要的东西,或者如何去做。

我试图从图像中检测椭圆,然后使用ocr读取其内部的文本。

sample image

谢谢

 private void Form1_Load(object sender, EventArgs e)
    {
        pictureBox1.Image = Image.FromFile(@"./IMG/1.jpg");
        pictureBox2.Image = Image.FromFile(@"./IMG/3.jpg");
    }

    private void startDetection(Image inputImage, CamEnum _camName)
    {
        try
        {
            if (inputImage == null)
            {
                return;
            }

            Image image = (Image)inputImage.Clone();

            CvSize size = new CvSize(image.Width, image.Height);
            IplImage dst = cvlib.CvCreateImage(size, 8, 3);

            if (image.PixelFormat == PixelFormat.Format24bppRgb)
            {
                dst = cvlib.ToIplImage((Bitmap)image, false);
            }
            else if (image.PixelFormat == PixelFormat.Format8bppIndexed)
            {
                cvlib.CvCreateImage(size, 8, 1);
                IplImage iplImage = cvlib.ToIplImage((Bitmap)image, false);
                cvlib.CvCvtColor(ref iplImage, ref dst, 8);
            }
            else
            {
                // throw not support format ex;
            }
            houghCircleDetection((object)dst, _camName);

        }
        catch (Exception ex)
        {

        }
    }

    private void houghCircleDetection(object img, CamEnum camName)
    {
        try
        {
            IplImage image1 = (IplImage)img;
            CvSize size = cvlib.CvGetSize(ref image1);
            IplImage image2 = cvlib.CvCreateImage(size, 8, 3);
            IplImage image3 = cvlib.CvCreateImage(size, 8, 1);
            IplImage pImage = this.preprocessImage(image1, camName);
            cvlib.CvCanny(ref pImage, ref image3, Math.Max(42 / 2.0, 1.0), 42, 3);
            CvSeq pCircles = HoughAlgorithm.DetectCircles(pImage, camName);
            cvlib.CvCopy(ref image1, ref image2);
            HoughAlgorithm.DrawCircles(image2, pCircles);
            if (camName == CamEnum.Cam1)
            {
                pictureBox_Result1.Image = (Image)cvlib.ToBitmap(image2, false);
                toolStripMenuItem_Result1.Text = pCircles.total.ToString();
            }
            else
            {
                pictureBox_Result2.Image = (Image)cvlib.ToBitmap(image2, false);
                toolStripMenuItem_Result2.Text = pCircles.total.ToString();
            }
        }
        catch (Exception ex)
        {

        }
    }

 }
}

我确定somone是否更了解如何解决这个问题。 我确定somone是否更好地了解如何解决这个问题。 我确定somone是否更了解如何解决这个问题。

谢谢

0 个答案:

没有答案