---------------------------------------------------------------------------------------------------------------
Description::
This is a C++ program to flip the input image by the use of flip funtion which is inbuilt in the opencv library. flip function takes 3 parametres. FIrst is mat object for input image, second is mat object for another desired output image and last parameter is integer value 0 or 1. 0 is used if desired output is water image and 1 is used if the desired result is the mirror image of the corresponding input image.
---------------------------------------------------------------------------------------------------------------
Program::
#include <opencv2/opencv.hpp>
using namespace cv;
int main( int argc, char** argv )
{
char* ImageFile = argv[1]; //image file
Mat image;
image = imread( ImageFile, IMREAD_COLOR ); //reading file
if( argc != 2 || !image.data )
{
printf( " No image data \n " );
return -1;
}
Mat flip1,flip2; //Mat object for storing data
flip(image,flip1,0); //flipping image (like water reflection)
imwrite( "/home/crmgogo/Pictures/flip1.jpg", flip1 );
flip(image,flip2,1); //flipping image (like mirror image)
imwrite( "/home/crmgogo/Pictures/flip2.jpg", flip2 );
namedWindow( imageName, WINDOW_NORMAL );
namedWindow( "Flip 1", WINDOW_NORMAL );
namedWindow( "Flip 2", WINDOW_NORMAL );
imshow( imageName, image );
imshow( "Flip 1", flip1 ); //displaying windows
imshow( "Flip 2", flip2 );
waitKey(0);
return 0;
}
---------------------------------------------------------------------------------------------------------------
Commands to run program on terminal::
$ g++ -ggdb `pkg-config --cflags filename` -o `basename filename .cpp` filename `pkg-config --libs opencv`
$ ./cvopen filename
---------------------------------------------------------------------------------------------------------------
Output::
Comments