??.首先下載opencv.framework加入到項目中,創(chuàng)建pch文件,并且添加代碼,在運用到openCV的地方我們需要將.m的改為.mm.
#ifdef __cplusplus
#import <opencv2/opencv.hpp>
#endif
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#endif
添加庫:CoreVideo.framework, AssetsLibrary.framework, CoreMedia.framework.
??接下來我們需要導(dǎo)入以下文件,鏈接我會放在最后提供下載
文件.png
??運行
1.配置發(fā)生錯誤
Undefined symbols for architecture x86_64:
"_jpeg_free_large", referenced from:
_free_pool in opencv2(jmemmgr.o)
"_jpeg_free_small", referenced from:
_free_pool in opencv2(jmemmgr.o)
_self_destruct in opencv2(jmemmgr.o)
"_jpeg_get_large", referenced from:
_alloc_large in opencv2(jmemmgr.o)
_realize_virt_arrays in opencv2(jmemmgr.o)
"_jpeg_get_small", referenced from:
_jinit_memory_mgr in opencv2(jmemmgr.o)
_alloc_small in opencv2(jmemmgr.o)
"_jpeg_mem_available", referenced from:
_realize_virt_arrays in opencv2(jmemmgr.o)
"_jpeg_mem_init", referenced from:
_jinit_memory_mgr in opencv2(jmemmgr.o)
"_jpeg_mem_term", referenced from:
_jinit_memory_mgr in opencv2(jmemmgr.o)
_self_destruct in opencv2(jmemmgr.o)
"_jpeg_open_backing_store", referenced from:
_realize_virt_arrays in opencv2(jmemmgr.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
這里是因為缺少了libjpeg.a,解決辦法是,安裝:libjpeg-turbo.dmg (鏈接在最后),安裝好后,在終端cd 自己的項目,輸入lipo -info /opt/libjpeg-turbo/lib/libjpeg.a
將會出現(xiàn)以下內(nèi)容:
Architectures in the fat file: /opt/libjpeg-turbo/lib/libjpeg.a are: i386 x86_64 armv6 armv7 armv7s arm64
然后將/opt/libjpeg-turbo/lib/libjpeg.a 加到你的工程里面,運行.
2.可能發(fā)生的錯誤
dyld: Library not loaded: /opt/libjpeg-turbo/lib/libjpeg.62.dylib
Referenced from: /Users/malata/Library/Developer/CoreSimulator/Devices/5A63F3E9-9097-46F6-879C-66C26135B5AA/data/Containers/Bundle/Application/33C4EED6-79E7-48A5-B798E65FF127F640/LocationManager.app/LocationManager
Reason: no suitable image found. Did find:
/opt/libjpeg-turbo/lib/libjpeg.62.dylib: mach-o, but not built for iOS simulator
解決辦法:將添加進入工程的libjpeg.a 在Build phases -> Link binary with Libraries 把required 改成 optional。
??配置好了,接下來是碼字了,在vc中導(dǎo)入#import "CVWrapper.h",并且將.m改成.mm.
NSMutableArray *arr = [[NSMutableArray alloc]init];
[arr addObject:[UIImage imageNamed:@"aa.jpg"]];
[arr addObject:[UIImage imageNamed:@"bb.jpg"]];
UIImage * image = [CVWrapper processWithArray:arr];
NSString *pathStr = [NSHomeDirectory() stringByAppendingPathComponent:@"/Documents/test.jpg"];
[UIImageJPEGRepresentation(image, 1.0) writeToFile:pathStr atomically:YES];
NSLog(@"%@",pathStr); //直接通過路徑查看圖片
??下載鏈接 https://pan.baidu.com/s/1gfn1oZL
以上xiao