How to minimize OpenCv library size? - opencv

I'm looking to minimize the size of my android ndk built library.
I have started with the pre-built OpenCv libraries for Android and as of now the size of my lib is about 3MB. How can I minimize it's size?
I only need read/write files capability, png encode/decode, jpeg decoder and the typical image manipulation functions from OpenCv such as resize and cvtColor.
Any pointers greatly appreciated!

You've probably moved on with your project by now, Jona, but others not using the cmake-gui may like a command-line example. i.e. if you didn't want the CCALIB module, you could build like this:
cmake -DBUILD_OPENCV_CCALIB=OFF [other cmake flags] ../
Manipulating build flags may not cover all the module exclusions you would like, however, it's probably a good place to start. To see the list of flag options, open CMakeLists.txt file (top of the opencv source directory).
Turning on/off flags also won't break your builds as much as manually commenting-out code.

The OpenCV library has several modules, you might consider leaving out modules like 'highgui' and 'gpu', and maybe more depending on what you need and don't need. Anyhow, I am not quite sure what you need. Maybe you should use a different smaller library instead, as reading, writing, decoding, converting, etc are not really Computer Vision operations, like a Hough transform or a distance map
One you might consider is cimg btw, you can easily strip that one down as it simply just defines more and more functions as part of the cimg class.
Good luck!

Related

Device handling in Nim

I am looking for a library that could capture streams of images from webcam or USB camera, and then converting image data into multidimensional matrices, in order to do some mathematical operation on them; afterward saving the result as a png file.
I am stuck in the first step. It seems there is only opencv to capture images from camera, which uses highgui.dll for the job. Unfortunately after installing opencv using nimble install opencv, and running a simple code
import opencv/imgproc
import opencv/highgui
import opencv/core
var capture = captureFromCam(CAP_ANY)
the error could not load: (lib|)opencv_highgui(249|231|)(d|).dll arises. Opencv cannot find the library to import necessary functions from it. So far I could not find any way to overcome this issue. In standard libraries of Nim, there are two libraries serial and winim that if I am not wrong, are handling device ports. I could not find a simple way to use them. The question is, what is the proper library for handling devices and how to use them in a simple manner?
For the rest of the job (manipulating image data) I think pixie is a good library to use. It would be good to know, if there is better library, in simplicity and performance.
As Christoph said, the nim package seems years out of date. However if you download Version 249 and put the right dlls into your directory or link them through your nimble file, your code will run.
For your code you would need to copy from opencv\build\x64\vc12\bin files opencv_core249.dll, opencv_highgui249.dll and opencv_imgproc249.dll
You might want to instead just write a quick wrapper for the functions you need from a newer version yourself since you probably only need a few functions. You can look at the nim-opencv library for how to wrap functions.
Or you could use a different application to capture the footage and nim to process it.

How to build opencv that only support decode jpeg?

I just need to call cv::imread("xxx.jpg"), how can I compile the most simple lib of opencv?
You'd better use other frameworks other than OpenCV. OpenCV is extremely heavy for this kind of job. It's mainly focused on image processing.
Maybe you can use OpenImageIO, freeimage or other libs.
You can refer to these posts:
Reading an image file in C/C++
https://products.fileformat.com/image/cpp/openimageio

27MB IPA with just GStreamer iOS Framework... how do I make much smaller?

I'm very interested in using GStreamer's iOS framework http://docs.gstreamer.com/display/GstSDK/Installing+for+iOS+development for video streaming, but when I add the framework to a blank project and add a few lines of code to take advantage of its powerful features, the final IPA is 27MB. This is just way to big to be adding to my project, what is the best way to go about stripping this down the the bare necessities as I'm sure I'm only using a small percent of the code that is included in the SDK.
Here's a pic showing the package contents of the IPA:
Thanks!
In the gst_ios_main.h you can disable all the plugins that you don't need (make sure to enable linker optimizations so that unused code is removed). If that's not enough, you can build your own stripped down version of the iOS binaries with http://cgit.freedesktop.org/gstreamer/cerbero/ (you need to remove things from the .package and .recipe files to only build what you need). Just disabling things from gst_ios_main.h should be enough in 99% of the cases though.
Note that by default you'll build applications for multiple architectures, as such the resulting application will be rather large. Depending on your use case you can drop some architectures.
On another note, gstreamer.com is providing an completely outdated version of GStreamer and is in no way related to the GStreamer project. The official website is http://gstreamer.freedesktop.org .
SDKs have their source code encapsulated away from you, the user. You get access only to header files. Thus you just can't extract some class from it because you don't have access to the implementation file.
Of course if this library is opensource you can attempt to isolate one class, but sometimes everything is so deeply connected, that it is close to impossible.

Intel AVCSR - (Lip reading to augment Voice Recognition)

I am interested in using a library that supports lip reading to augment audio/voice recognition. I found out that Intel's AVCSR (which was bundled with OpenCV library) would be an interesting option to consider. Would there be any other libraries that can be used to achieve the same (lip reading to augment voice recognition)?
Also I have not been able to locate a source to download this library from. I already tried the OpenCV package from SourceForge (http://sourceforge.net/projects/opencvlibrary/) but it does not seem to have the AVCSR packages/files. Could someone who has already worked with something similar point me to the place where I can find these source files (either within OpenCV or elsewhere)?
Thank you.

Optimizing for a smaller .cod (.jar) file

The RIM compiler performs extra optimization and compression on the resulting ".jar" while building the final .cod file, but there are things that can be done by the developer to significantly reduce the final .cod file size.
One such thing would be to run PNGCrush, OptiPNG, or a similar tool to reduce the size of the included .png files. In an application with a large number of image files (such as an app featuring a custom UI), this can yield a significant reduction in the final .cod file size.
How can I optimize the final .cod file for size? Something to be done in the .java code itself? Something to be done in the project structure? Something to be done to the files or resources?
Good question!
Compression (GZip, ZLib) may be useful when installing large bin/txt/xml files
And that's what they say in RIM:
Setting appropriate access
Avoid creating interfaces
Use static inner classes
Avoid unnecessary field initialization
Import individual classes
Also, interesting facts:
All images was PNG format. I want to
know why : compile with JDE 4.5 -->
900k, compile JDE 4.2, 2.6.1, 4.7 -->
1800k. What is difference ? Thanks !
Seems that JDE 4.5 uses more optimization techniques than older JDE
versions.
Check the image below, it produced by PngOut from 55 K png image. It's size is 3427 bytes
I think you most certainly want to consider a shrinker (and optimizer/obfusticator) like ProGuard (http://sourceforge.net/projects/proguard/). This can shrink your Java code by collapsing full class names into shortened versions, removing unused code, etc. Along the way it can improve the efficiency of the code. It's great. The only hard part is modifying your build to optimize the generated class files before the RIM build stuff gets its hands on it to make a .cod.
A good approach is to GZIP all resources and then use net.rim.device.api.compress.GZIPInputStream class to load compressed files. That way you don't have to implement decompress code by yourself.
Also you can use pngout for optimizing image resources.
Make sure that you use PNG-8 instead of PNG-24 when possible. Try to minimize number of colors in palette. After this, use PngOut.
As for ProGuard, I have problems on old BB devices when using optimize feachure of Progruard ("-dontoptimize" switch) - so use it carefully, although it is a great tool.

Resources