1

I have written this code to capture the photo from webcam using opencv library.

#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();

}

then i statically linked with some of the required opencv library to make it portable. when i compile the code the size of the executable is 4.73, Is there any way to reduce the size of executable without affecting the portability ? i don't want to link the libraries dynamically. here is the compilation log.

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))
Rafih_m
  • 76
  • 4

1 Answers1

1

It depends how you want to use it. In addition to responses in comments, you can use executable packer, like UPX.

Kajtek
  • 29
  • 4