使用openCV拼接图片

🍎.首先下载opencv.framework加入到项目中,创建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.
🍎接下来我们需要导入以下文件,链接我会放在最后提供下载

文件.png

🍎运行
1.配置发生错误

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将会出现以下内容:
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.可能发生的错误

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中导入#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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容