Friday 15 January 2016

Opencv C++ Code for Drawing a Chessboard Pattern-Amazing Effects

This OpenCV Tutorial is about drawing a Chess Board Pattern.
Refer the Code Below:

//Opencv Example of Drawing a Chess Board Pattern
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace cv;
 
int main( )
{ 
 int a=400/8;
  // Create black empty images
  Mat image = Mat::zeros( 400, 400, CV_8UC3 );
   
  // Draw a rectangle ( 5th argument is not -ve)  
  for(int y=0;y<=3;y++)
  for(int x=0;x<=3;x++)
  {
  rectangle( image, Point( x*a*2, y*a*2), Point( a*(2*x+1), a*(2*y+1)), Scalar( 255, 255, 255 ), -1, 4 );
  imshow("Image1",image);
  waitKey( 250 );
  }
  for(int y=0;y<=3;y++)
  for(int x=0;x<=3;x++){
  rectangle( image, Point( a*(2*x+1), a*(2*y+1)), Point( (x+1)*a*2, (y+1)*a*2), Scalar( 255, 255,255 ), -1, 4 );
  imshow("Image1",image);
  waitKey( 250 );
  }
  waitKey( 0 );
  return(0);
}

Output:

Opencv-Example-Draw-ChessBoard-Pattern

No comments:

Post a Comment