-2

我正在开发一个 C# 应用程序来处理扫描的图像。扫描的图像包含 12 个矩形子区域,如下所示。

是否有任何库或代码示例可以帮助我识别每个区域的位置和尺寸?

样本扫描图像

帮我。我在 codeproject 中搜索了一篇文章(http://www.codeproject.com/Articles/265354/Playing-Card-Recognition-Using-AForge-Net-Framewor)有我想要的解决方案。它有2个项目。第一个项目 PlayingCardRecognition,我创建了文件

测试卡.cs

using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;

namespace PlayingCardRecognition
{
    public class TestCard
    {
        public string name { get; set; }
        public Bitmap bitmap { get; set; }
        public Point[] point { get; set; }
    }
}

测试卡集合.cs

using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;

namespace PlayingCardRecognition
{
    public class TestCardCollection : CollectionBase
    {
        public void Add(TestCard card)
        {
            this.List.Add(card);
        }
    }
}

我更改了文件CardRecognizer.cs,我添加了一个从识别方法更改的方法ExtractImages

public TestCardCollection ExtractImages(Bitmap source)
    {
        TestCardCollection col = new TestCardCollection();
        Bitmap temp = source.Clone() as Bitmap; //Clone image to keep original image

        FiltersSequence seq = new FiltersSequence();
        seq.Add(Grayscale.CommonAlgorithms.BT709);  //First add  grayScaling filter
        seq.Add(new OtsuThreshold()); //Then add binarization(thresholding) filter
        temp = seq.Apply(source); // Apply filters on source image

        //Extract blobs from image whose size width and height larger than 150
        BlobCounter extractor = new BlobCounter();
        extractor.FilterBlobs = true;
        extractor.MinWidth = extractor.MinHeight = 150;
        extractor.MaxWidth = extractor.MaxHeight = 350;
        extractor.ProcessImage(temp);

        //Will be used transform(extract) cards on source image 
        QuadrilateralTransformation quadTransformer = new QuadrilateralTransformation();

        //Will be used resize(scaling) cards 
        ResizeBilinear resizer = new ResizeBilinear(CardWidth, CardHeight);

        Blob[] blobs = extractor.GetObjectsInformation();

        for (int i = 0; i < blobs.Length; i++)
        {
            Blob blob = blobs[i];
            TestCard card = new TestCard();
            card.name = "" + i;


            List<IntPoint> edgePoints = extractor.GetBlobsEdgePoints(blob);
            //Calculate/Find corners of card on source image from edge points
            List<IntPoint> corners = PointsCloud.FindQuadrilateralCorners(edgePoints);
            if (corners.Count < 4)
                quadTransformer.SourceQuadrilateral = new List<IntPoint>(edgePoints);
            else
                quadTransformer.SourceQuadrilateral = corners; //Set corners for transforming card 
            quadTransformer.AutomaticSizeCalculaton = true;

            Bitmap cardImg = quadTransformer.Apply(source); //Extract(transform) card image

            if (cardImg.Width > cardImg.Height) //If card is positioned horizontally
                cardImg.RotateFlip(RotateFlipType.Rotate90FlipNone); //Rotate
            card.bitmap = resizer.Apply(cardImg); //Normalize card size

            IntPoint[] cornerIntPoints = corners.ToArray();

            Point[] corner = new Point[cornerIntPoints.Length];
            for (int z = 0; z < cornerIntPoints.Length; z++)
            {
                corner[z].X = cornerIntPoints[z].X;
                corner[z].Y = cornerIntPoints[z].Y;
            }
            card.point = corner;
            col.Add(card);
        }

        return col;
    }

第二个项目 PlayingCardRecognition_SampleImages 我有test.cs文件

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using AForge.Imaging.Filters;
using PlayingCardRecognition;

namespace PlayingCardRecognition_SampleImages
{
    public partial class test : Form
    {
        public test()
        {
            InitializeComponent();
            ResizeBilinear resizer = new ResizeBilinear(pictureBox1.Width, pictureBox1.Height);
            Bitmap bm = Properties.Resources.testtrip;
            pictureBox1.Image = resizer.Apply(bm);

        }
        private CardRecognizer recognizer = new CardRecognizer();

        private void button1_Click(object sender, EventArgs e)
        {
            int w = 0;
            TestCardCollection col =  recognizer.ExtractImages(Properties.Resources.testtrip);
            foreach (TestCard card in col)
            {
                PictureBox pic = new PictureBox();
                pic.Image = card.bitmap;
                pic.Width = card.bitmap.Width;
                pic.Height = card.bitmap.Height;
                pic.Location = new Point(w, 0);
                pnMain.Controls.Add(pic);
                w += card.bitmap.Width + 10;
            }
        }
    }
}

我调用了 ExtractImages方法,我得到了 12 张图像但区域错误它如下图所示。显示图像返回 为什么?我的项目在这里

感谢和抱歉我的英语。

4

1 回答 1

1

查看 OpenCV,我认为它有一个 .Net 版本。

基本上,您需要定义什么是区域。然后使用边缘来分割它们,因为它们是矩形的。通常,您可以使用图像处理工具(即 Matlab 图像处理工具箱)来测试您的算法并确保它有效,然后编写 C#。

于 2012-12-20T04:59:07.423 回答