1

ロボットを制御し て三目並べゲームを実行するようになりましたが、opencv
ライブラリを使用してゲーム ボードと内側の正方形を認識する方法がわかりませんでした。アルゴリズムを使用して、ゲーム ボードと 9X9 ゲームの正方形のコーナーを取得する方法を知りたいです。

これは私がコーナーを取得するものです

バイナリ イメージ:

cvFindContours:

#include <stdio.h>
#include <fcntl.h>
#include <cv.h>
#include <cxcore.h>
#include <highgui.h>

int main(void){ 
IplImage *img=NULL;
IplImage *gray=NULL;
CvMemStorage* contour_storage;
CvSeq* contours=NULL;
CvPoint2D32f *corners;

img = cvLoadImage("tictactoe.bmp",CV_LOAD_IMAGE_COLOR);
gray = cvCreateImage( cvGetSize(img), IPL_DEPTH_8U, 1 );

cvSmooth( img, img, CV_GAUSSIAN, 3, 0, 0, 0);
cvCvtColor(img, gray, CV_RGB2GRAY);
cvAdaptiveThreshold(gray, gray, 128,CV_ADAPTIVE_THRESH_MEAN_C, CV_THRESH_BINARY_INV, 3, 5);
cvNamedWindow( "Threshold", CV_WINDOW_AUTOSIZE);
cvShowImage("Threshold", gray);

contour_storage = cvCreateMemStorage(0);
corners = (CvPoint2D32f *)malloc(sizeof(CvPoint2D32f)*9);
cvFindContours(gray, contour_storage, &contours, sizeof (CvContour), CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE, cvPoint(0,0));
cvDrawContours(img, contours, CV_RGB(255,0,0), CV_RGB(0,255,0), 2, 4, 8, cvPoint(0,0));

cvNamedWindow("Calibration", CV_WINDOW_AUTOSIZE);
cvShowImage( "Calibration", img);

cvWaitKey(0);

return 0;
}

ゲームを行うための画像処理までどのように処理するのだろうか

このプログラムは、ARM を使用して組み込みボードを実行するために C コードと OpenCv 1.x を使用することに限定されています。

opencvを使ってこのゲームを開発する方法を教えてください

4

1 に答える 1

2

I only used the c++ interface up to now, so I don't know about the exact names of the functions you'll have to call. Nevertheless, here's a description of a rough algorithm I would use to achieve what you want, so you have a few keywords you can look up:

  • As the camera image is clearly distorted, recognizable by the curved board lines, you should start by calibrating your camera. If you always use the same camera, or at least the same model with the same focal length, you'll only have to do this once. A quick tutorial on this can be found here. This is a more detailed tutorial, with more mathematics, unfortunately he uses the c++ functions.

  • The next step would be detecting the cells of your board. I think this can be achieved more easily by using a Hough Line Transform (also c++) and then calculating the line intersections and thus you can define your cells.

  • If you want your software to automatically take it's turn, you can use a motion detector to determine if there's currently no motion and then act. Background subtraction is an easy way to do this. I didn't find a suitable explanation on this, just do a google search.

  • After that you'll have to find circles and crosses. Circles are the easier part, as there's also a Hough Circle Transform. Crosses are more tricky. I would estimate the length of the crosses lines by taking the diagonals of your cells into account and the again use a Hough Line Detector.

Everything I mentioned here gets explained in detail (but not too theoretically) in this book, which I found very helpful when learning OpenCV. They even use the C-Interface.

于 2012-11-20T13:33:20.170 に答える