Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Opencv Custom Compile

Tags:

ios

opencv

I'm trying to reduce opencv2.framework size for ios. My project using only core,imgproc and highgui modules. How can I compile with only those modules? or is there an alternative for reducing size?

Thanks.

like image 501
ervanux Avatar asked Apr 02 '13 07:04

ervanux


1 Answers

I ran into this issue now with version 3.1, and nebuto's answer is close, but not complete as of now. The following was able to produce the desired result by updating the build_framework.py file.

def getCMakeArgs(self, arch, target):
    args = [
        "cmake",
        "-GXcode",
        "-DBUILD_SHARED_LIBS=OFF",
        "-DBUILD_opencv_core=ON",
        "-DBUILD_opencv_imgcodecs=OFF",
        "-DBUILD_opencv_imgproc=ON",
        "-DBUILD_opencv_world=OFF",
        "-DBUILD_opencv_gpu=OFF",
        "-DBUILD_opencv_calib3d=OFF",
        "-DBUILD_opencv_contrib=OFF",
        "-DBUILD_opencv_features2D=OFF",
        "-DBUILD_opencv_flann=OFF",
        "-DBUILD_opencv_highgui=ON",
        "-DBUILD_opencv_legacy=OFF",
        "-DBUILD_opencv_ml=OFF",
        "-DBUILD_opencv_nonfree=OFF",
        "-DBUILD_opencv_objdetect=OFF",
        "-DBUILD_opencv_photo=OFF",
        "-DBUILD_opencv_stitching=OFF",
        "-DBUILD_opencv_video=OFF",
        "-DBUILD_opencv_videoio=OFF",
        "-DBUILD_opencv_videostab=OFF",
        "-DAPPLE_FRAMEWORK=ON",
        "-DCMAKE_INSTALL_PREFIX=install",
        "-DCMAKE_BUILD_TYPE=Release",
    ]
    return args

This update also includes two new modules that appear to have not existed in 2.4.6.

For some additional savings, you can likely remove the i386 settings for simulator builds which is located at the bottom of the file. If your app is iOS 9 and above, and you wish to omit 32 bit devices, you can also take out the armv7 option as well.

b = Builder(args.opencv, args.contrib,
    [
        ("armv7", "iPhoneOS"),
        ("armv7s", "iPhoneOS"),
        ("arm64", "iPhoneOS"),
        #("i386", "iPhoneSimulator"),
        ("x86_64", "iPhoneSimulator"),
    ])
b.build(args.out)
like image 100
CodeBender Avatar answered Sep 18 '22 06:09

CodeBender