---------------------------------------------------------------------------------------------------------------
Description::
This is a C++ program to show the use of trace funtion which is inbuilt in the opencv library. Trace function takes 1 parameter. Parameter is mat object for image.This function returns the sum of diagonal elements of matrix
---------------------------------------------------------------------------------------------------------------
Program::
#include <opencv2/opencv.hpp>
using namespace cv;
#include <iostream>
int main( int argc, char** argv )
{
char* imageName = argv[1]; //image file
Mat image; //mat object for storing data
image = imread( imageName, IMREAD_COLOR ); //read file
if( argc != 2 || !image.data )
{
printf( " No image data \n " );
return -1;
}
Scalar obj;
obj=trace(image);
cout<<obj<<endl;
namedWindow( imageName, WINDOW_NORMAL );
imshow( imageName, image ); //show window containing images
waitKey(0); //to exit
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