Tuesday, 12 January 2016

OpenCV C++ Code for Drawing a Square wave

This Opencv Tutorial is about drawing a Square wave.
In the previous Opencv tutorial we learnt about drawing a Square.
http://opencv-hub.blogspot.in/2016/01/opencv-c-code-for-drawing-square.html Thus this tutorial is just an extension of that tutorial.
Here is the OPENCV C++ code for drawing a Square Wave:

//Opencv Code for Drawing a Square-Wave
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
using namespace cv;
using namespace std;
 
int main( )
{   
  int count=0,a=0,b=50,i=0,j=50;
  // Create black empty images
  Mat image = Mat::zeros( 500, 500, CV_8UC3 );
  
  for(a=0;a<500;)
  {
   count++;
   if(count%2==0)
   {  
    i=a+50;
    j=b;
    
   }
   else{
    i=a;
    if(j==50){
     j=100;}
    else{
     j=50;
    }
    
   }
  // Draw a line 
  line( image, Point( a, b ), Point( i, j), Scalar( 255, 255, 0 ), 2, 8 );
  
     imshow("Image",image);
     waitKey( 250 );
  a=i;
  b=j;
  }
 
   waitKey( 0 );
  return(0);
}

Output:
Opencv C++ Tutorial for Drawing a Square wave

No comments:

Post a Comment