Here is a simple program to display image attributes like width, height, size and etc. This program assumes that you have OpenCV library alredy installed on you system.

#include <iostream>
#include <iomanip>
#include "cv.h"
#include "highgui.h"

using namespace std;

int main( int argc, char** argv )

{

// Create an IplImage object *image 
IplImage *image = cvLoadImage( argv[1]);

// Display Image Attributes by accessing a IplImage object's data members

cout << left << setfill(' ') <<  setw(15) << "Image filename:" << argv[1] << endl;

cout << setw(15) << "Width:" <<  image->width << endl;
cout << setw(15) << "Height:" <<  image->height << endl;

cout << setw(15) << "Pixel Depth:" <<  image->depth << endl;
cout << setw(15) << "Channels:" <<  image->nChannels << endl;

cout << setw(15) << "Width Step:" <<  image->widthStep << endl;
cout << setw(15) << "Image Size:" <<  image->imageSize << endl;

return 0;
}

Compile with:

g++ `pkg-config opencv --cflags --libs` imageattr.cpp -o imageattr

OUTPUT SAMPLE:

./imageattr re_dsc00056.jpg
Image filename:re_dsc00056.jpg
Width: 1148
Height: 644
Pixel Depth: 8
Channels: 3
Width Step: 3444
Image Size: 2217936

Free Linux eBooks

Linux Technical Writer

LinuxCareer, Casual, Volunteer, Home Based

Do you wish to join Linuxcareer.com project and find out how to be a technical writer? We are now looking for volunteers to help us write tutorials and share them with Linux community

  • Casual work from home
  • 10 articles / year

Any active Linuxcareer.com’s author will be entitled to following benefits:

  • actively participate in Linuxcareer.com’s decision making process
  • feedback and help

APPLY

Do you have the right skills?

Our IT Skills Watch page reflects an up to date IT skills demand leaning towards the Linux and Unix environment. We have considered a number of skills and operating systems.

See the result...

Linux Online Training

Learn to run Linux servers and prepare for LPI certification with Linux Academy. 104 available video lessons with PDF course notes with your own server!

Go to top