我已编写此代码以使用opencv
库从网络摄像头捕获照片。
#include <opencv2/highgui/highgui.hpp>
#include<windows.h>
#include<iostream>
using namespace std;
using namespace cv;
void camcapture()
{
VideoCapture cap(0);
char name[100];
int i=0;
while(1){
Sleep(1000);
sprintf(name,"%s%d.jpg","test",i++);
Mat save_img;
cap >> save_img;
if(save_img.empty())
{
std::cerr << "Something is wrong with the webcam, could not get frame." << std::endl;
}
// Save the frame into a file
imwrite(name, save_img); // A JPG FILE IS BEING SAVED
printf("image %s saved\n",name);
}
}
int main()
{
camcapture();
}
然后我静态链接到一些必需的opencv库,使其可移植。当我编译代码时,可执行文件的大小是4.73, 有没有办法减少可执行文件的大小而不影响可移植性? 我不想动态链接库。 这是编译日志。
Build started on: 25-10-2016 at 22:52.58
Build ended on: 25-10-2016 at 22:53.00
-------------- Build: Release in cvtest (compiler: GNU GCC Compiler)---------------
mingw32-g++.exe -Wall -fexceptions -O2 -ID:\open\opencv\mybuild4\install\include -ID:\open\opencv\mybuild4\install\include\opencv -ID:\open\opencv\mybuild4\install\include\opencv2 -c D:\c_cpp_codes\cvtest\main.cpp -o obj\Release\main.o
mingw32-g++.exe -LD:\open\opencv\mybuild4\install\x86\mingw\staticlib -o bin\Release\cvtest.exe obj\Release\main.o -s D:\open\opencv\mybuild4\lib\libopencv_world310.a D:\open\opencv\mybuild4\3rdparty\lib\liblibjpeg.a D:\open\opencv\mybuild4\3rdparty\lib\liblibwebp.a D:\open\opencv\mybuild4\3rdparty\lib\liblibtiff.a D:\open\opencv\mybuild4\3rdparty\lib\liblibpng.a D:\open\opencv\mybuild4\3rdparty\lib\liblibjasper.a D:\open\opencv\mybuild4\3rdparty\lib\libIlmImf.a D:\open\opencv\mybuild4\3rdparty\lib\libzlib.a C:\MinGW\lib\Vfw32.Lib C:\MinGW\lib\Uuid.Lib C:\MinGW\lib\Ole32.Lib C:\MinGW\lib\OleAut32.Lib
Output file is bin\Release\cvtest.exe with size 4.73 MB
Process terminated with status 0 (0 minute(s), 1 second(s))
0 error(s), 0 warning(s) (0 minute(s), 1 second(s))
答案 0 :(得分:1)
这取决于您想要如何使用它。除了注释中的响应,您还可以使用可执行的打包程序,如UPX。