Ask Your Question
1

How to create a chess-board

asked 2014-02-07 04:26:39 -0600

Agribot gravatar image

Hi I'm a newby starting to understand openCV and it's use to create and display graphics on the screen of my laptop.

I'd like to use opencv to draw a chess-board (not the checker pattern often used to calibrate, that's not a chess board) and to display that.

Then I'd like to create small images for each of the chess pieces and then then place each on the chess board.

create a chess board display it create each piece select a position on the board place the piece at that position display that

Can you point me towards some example opencv solution in C or C++ code that could show me how that can be done ?

I'm using Microsoft Visual Studio 2010 Express for C++ version

Thanks

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
3

answered 2014-02-07 07:58:41 -0600

Haris gravatar image

updated 2014-02-07 10:52:36 -0600

Check this example

    int blockSize=75;
    int imageSize=blockSize*8;
    Mat chessBoard(imageSize,imageSize,CV_8UC3,Scalar::all(0));
    unsigned char color=0;

     for(int i=0;i<imageSize;i=i+blockSize){
      color=~color;
       for(int j=0;j<imageSize;j=j+blockSize){
       Mat ROI=chessBoard(Rect(i,j,blockSize,blockSize));
       ROI.setTo(Scalar::all(color));
       color=~color;
      }
     }
    imshow("Chess board", chessBoard);

image description

edit flag offensive delete link more

Comments

2

+1. now go and procedurally generate the figures ;)

berak gravatar imageberak ( 2014-02-07 08:10:54 -0600 )edit

Question Tools

Stats

Asked: 2014-02-07 04:26:39 -0600

Seen: 10,756 times

Last updated: Feb 07 '14