スキャンした画像を処理するC#アプリケーションを開発しています。スキャンされた画像には、以下に示すように12個の長方形のサブ領域が含まれています。
各領域の位置と寸法を特定するのに役立つライブラリまたはコードサンプルはありますか?
助けて。codeproject(http://www.codeproject.com/Articles/265354/Playing-Card-Recognition-Using-AForge-Net-Framewor)で記事を検索しましたが、必要な解決策があります。2つのプロジェクトがあります。最初のプロジェクトPlayingCardRecognition、ファイルを作成しました
TestCard.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; }
}
}
TestCardCollection.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ファイルを変更し、 Recognizeメソッドから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;
}
2番目のプロジェクトPlayingCardRecognition_SampleImagestest.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枚の画像が表示されますが、領域が間違っています。下の画像のように表示されます。画像の戻りを表示 なぜですか?ここでの私のプロジェクト
私の英語に感謝し、申し訳ありません。