我試圖減少爲iOS的opencv2.framework大小。我的項目只使用核心,imgproc和highgui模塊。我怎樣才能編譯只有這些模塊?還是有減少尺寸的替代方案?Opencv自定義編譯
謝謝。
我試圖減少爲iOS的opencv2.framework大小。我的項目只使用核心,imgproc和highgui模塊。我怎樣才能編譯只有這些模塊?還是有減少尺寸的替代方案?Opencv自定義編譯
謝謝。
只需從模塊文件夾中刪除模塊,並從頭文件中刪除包含行。並編譯。在這之前閱讀CMakeLists.txt的依賴關係。
例如,對於highgui模塊;
ocv_define_module(imgproc opencv_core)
由於v2.4.6的OpenCV有一個自定義Python腳本緩解工作 (plateforms> IOS> build_framework.py)
你只需要在cmake的行添加標誌,以使自定義編譯。
例如:我只需要的lib imgproc,幷包括所有的頭到存檔,我現在的CMake這ressembles:
cmakeargs = ("-GXcode " +
"-D BUILD_SHARED_LIBS=OFF "+
"-D BUILD_opencv_core=ON "+
"-D BUILD_opencv_imgproc=ON "+
"-D BUILD_opencv_world=ON "+
"-D BUILD_opencv_gpu=OFF "+
"-D BUILD_opencv_calib3d=OFF "+
"-D BUILD_opencv_contrib=OFF "+
"-D BUILD_opencv_features2D=OFF "+
"-D BUILD_opencv_flann=OFF "+
"-D BUILD_opencv_highgui=OFF "+
"-D BUILD_opencv_legacy=OFF "+
"-D BUILD_opencv_ml=OFF "+
"-D BUILD_opencv_nonfree=OFF "+
"-D BUILD_opencv_objdetect=OFF "+
"-D BUILD_opencv_photo=OFF "+
"-D BUILD_opencv_stitching=OFF "+
"-D BUILD_opencv_video=OFF "+
"-D BUILD_opencv_videostab=OFF "+
"-DCMAKE_BUILD_TYPE=Release " +
"-DCMAKE_TOOLCHAIN_FILE=%s/platforms/ios/cmake/Toolchains/Toolchain-%s_Xcode.cmake " +
"-DCMAKE_INSTALL_PREFIX=install") % (srcroot, target)
不要忘記補充核心和世界LIB爲他們是強制性的。 執行python腳本> profite。
之後,手動將lib添加到您的項目中,並刪除標題> opencv.hpp中留下的麻煩的導入標題,你應該很好去!
我現在遇到3.1版本的這個問題,nebuto的答案是接近的,但到目前爲止還沒有完成。通過更新build_framework.py文件,以下能夠產生所需的結果。
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
此更新還包括兩個看起來在2.4.6中不存在的新模塊。
對於一些額外的節省,您可能會刪除位於文件底部的模擬器構建的i386設置。如果您的應用程序是iOS 9或更高版本,並且您希望省略32位設備,則也可以取出armv7選項。
b = Builder(args.opencv, args.contrib,
[
("armv7", "iPhoneOS"),
("armv7s", "iPhoneOS"),
("arm64", "iPhoneOS"),
#("i386", "iPhoneSimulator"),
("x86_64", "iPhoneSimulator"),
])
b.build(args.out)