下面是一个简单的程序,用于显示图像的宽度,高度,大小等属性。
此程序假定我们在系统上安装了OpenCV库。
#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; }
编译:
g++ `pkg-config opencv --cflags --libs` imageattr.cpp -o imageattr
输出示例:
./imageattr test.jpg Image filename:test.jpg Width: 1148 Height: 644 Pixel Depth: 8 Channels: 3 Width Step: 3444 Image Size: 2217936
日期:2020-07-07 20:54:34 来源:oir作者:oir