「認識」を、要素の特徴/特性を検出し、それらを私たちの経験で見られる既知の要素の特徴と比較する能力として定義する場合があります。類似した特徴を持つオブジェクトは、おそらく類似したオブジェクトです。特徴の量と複雑さが高ければ高いほど、同様のオブジェクトを識別する能力が大きくなります。
形状の場合、角度の数、角度の値、辺の数、辺のサイズなどの幾何学的プロパティを使用できます。したがって、タスクを達成するには、画像処理アルゴリズムを使用して、図面からそのような特徴を抽出する必要があります。
以下に、この概念を実際に示す非常に単純なアプローチを示します。角の数を使ってさまざまな形を認識します。私が言ったように、「機能の量と複雑さが高ければ高いほど、類似したオブジェクトを識別する能力は大きくなります」。角の数という 1 つの特徴のみを使用しているため、いくつかの異なる種類の形状を区別できます。角の数が同じ形状は判別しません。したがって、アプローチを改善するために、新しい機能を追加することがあります。
アップデート:
このタスクをリアルタイムで実行するために、特徴をリアルタイムで抽出できます。描画するオブジェクトが三角形で、ユーザーが他の図形の 4 番目の辺を描画している場合、ユーザーは三角形を描画していないことがわかります。正確さのレベルについては、目的のオブジェクトの特徴ベクトルと描画されたオブジェクトの間の距離を計算できます。
入力:

アルゴリズム
- 目的の特徴を低解像度で検出できるため、入力画像を縮小します。
- 各オブジェクトをセグメント化して、個別に処理します。
- 各オブジェクトについて、その特徴を抽出します。この場合はコーナーの数だけです。
- 特徴を使用して、オブジェクトの形状を分類します。
ソフトウェア:
以下に示すソフトウェアは、Java で開発され、Marvin Image Processing Frameworkを使用しています。ただし、任意のプログラミング言語とツールを使用できます。
import static marvin.MarvinPluginCollection.floodfillSegmentation;
import static marvin.MarvinPluginCollection.moravec;
import static marvin.MarvinPluginCollection.scale;
public class ShapesExample {
public ShapesExample(){
// Scale down the image since the desired features can be extracted
// in a lower resolution.
MarvinImage image = MarvinImageIO.loadImage("./res/shapes.png");
scale(image.clone(), image, 269);
// segment each object
MarvinSegment[] objs = floodfillSegmentation(image);
MarvinSegment seg;
// For each object...
// Skip position 0 which is just the background
for(int i=1; i<objs.length; i++){
seg = objs[i];
MarvinImage imgSeg = image.subimage(seg.x1-5, seg.y1-5, seg.width+10, seg.height+10);
MarvinAttributes output = new MarvinAttributes();
output = moravec(imgSeg, null, 18, 1000000);
System.out.println("figure "+(i-1)+":" + getShapeName(getNumberOfCorners(output)));
}
}
public String getShapeName(int corners){
switch(corners){
case 3: return "Triangle";
case 4: return "Rectangle";
case 5: return "Pentagon";
}
return null;
}
private static int getNumberOfCorners(MarvinAttributes attr){
int[][] cornernessMap = (int[][]) attr.get("cornernessMap");
int corners=0;
List<Point> points = new ArrayList<Point>();
for(int x=0; x<cornernessMap.length; x++){
for(int y=0; y<cornernessMap[0].length; y++){
// Is it a corner?
if(cornernessMap[x][y] > 0){
// This part of the algorithm avoid inexistent corners
// detected almost in the same position due to noise.
Point newPoint = new Point(x,y);
if(points.size() == 0){
points.add(newPoint); corners++;
}else {
boolean valid=true;
for(Point p:points){
if(newPoint.distance(p) < 10){
valid=false;
}
}
if(valid){
points.add(newPoint); corners++;
}
}
}
}
}
return corners;
}
public static void main(String[] args) {
new ShapesExample();
}
}
ソフトウェア出力:
figure 0:Rectangle
figure 1:Triangle
figure 2:Pentagon