在学习CImg时,官方教程上有个例子写的非常详细,代码如下:
#include "CImg.h"
using namespace cimg_library;
int main() {
CImg<unsigned char> image("lena.jpg"), visu(500,400,1,3,0);
const unsigned char red[] = { 255,0,0 }, green[] = { 0,255,0 }, blue[] = { 0,0,255 };
image.blur(2.5);
CImgDisplay main_disp(image,"Click a point"), draw_disp(visu,"Intensity profile");
while (!main_disp.is_closed() && !draw_disp.is_closed()) {
main_disp.wait();
if (main_disp.button() && main_disp.mouse_y()>=0) {
const int y = main_disp.mouse_y();
visu.fill(0).draw_graph(image.get_crop(0,y,0,0,image.width()-1,y,0,0),red,1,1,0,255,0);
visu.draw_graph(image.get_crop(0,y,0,1,image.width()-1,y,0,1),green,1,1,0,255,0);
visu.draw_graph(image.get_crop(0,y,0,2,image.width()-1,y,0,2),blue,1,1,0,255,0).display(draw_disp);
}
}
return 0;
}
本想编译运行一下看看是怎么一回事,可是编译后运行时却出现下面的问题:
PS D:\linjiafengyang\Code\CV\CImg_latest\CImg-2.2.1_pre030218> g++ -o main1.exe .\Ex1.1.cpp -O2 -lgdi32
PS D:\linjiafengyang\Code\CV\CImg_latest\CImg-2.2.1_pre030218> ./main1
无效参数 - "C:\\WINDOWS\\Temp\\86ew44GS.pnm"
'gm.exe' 不是内部或外部命令,也不是可运行的程序
或批处理文件。
无效参数 - "C:\\WINDOWS\\Temp\\guOIMGi0.pnm"
'gm.exe' 不是内部或外部命令,也不是可运行的程序
或批处理文件。
无效参数 - "C:\\WINDOWS\\Temp\\66682Ky8.pnm"
'gm.exe' 不是内部或外部命令,也不是可运行的程序
或批处理文件。
[CImg] *** CImgIOException *** [instance(0,0,0,0,0000000000000000,non-shared)] CImg<unsigned char>::load(): Failed to recognize format of file 'lena.jpg'.
terminate called after throwing an instance of 'cimg_library::CImgIOException'
what(): [instance(0,0,0,0,0000000000000000,non-shared)] CImg<unsigned char>::load(): Failed to recognize format of file 'lena.jpg'.
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
参考到这篇博客https://www.cnblogs.com/sheshouyanhun/p/3784837.html,安装ImageMagick,官网下载binary release版本https://www.imagemagick.org/script/install-source.php#windows,下载完安装即可。