获取云脉账户和密码(下载api前给的,不是云脉的登录账号),
下载云脉行驶证识别demo
http://www.yunmaiocr.com/member?action=down&filename=行驶证识别接口文档下载&filepath=/html/download/Saas_driving_scan(demo).zip
添加framework
CoreText.framework
CoreData.framework
libxml2.dylib
CFNetwork.framework
MobileCoreServices.framework
AssetsLibrary.framework
libz.dylib
CoreGraphics.framework
UIKit.framework
Foundation.framework
SystemConfiguration.framework
从demo copy文件
Camera文件夹
Verify文件夹
Hot card文件夹
ASIHttpRequest文件夹
Config.h
Package.h
Package.m
xproj处理非
Camera文件夹
Verify文件夹
Hot card文件夹
ASIHttpRequest文件夹
在Package.m中的uploadPackage: andindexPath: 方法里面替代username,psd
.h
{
UIImagePickerController *_pickerController;
NSString *_dataStr;
UIActionSheet *progressSheet;
UIProgressView *progressBar;
UIActivityIndicatorView *activityView;
UIButton *cancelButton;
NSInteger progressValue;
}
.m
#import "PackageAPI.h"
#import "Config.h"
#import "EditingViewController.h"
#import "RegisterViewController.h"
@interface RegisterViewController ()<UIImagePickerControllerDelegate, UINavigationControllerDelegate>
@property (strong, nonatomic) NSString *resultStr;
@end
@implementation RegisterViewController
//开始拍照
-(void)startScan{
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
_pickerController = [[UIImagePickerController alloc] init];
_pickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
_pickerController.delegate = self;
_pickerController.showsCameraControls = YES;
//[imagePicker.view setBackgroundColor:[UIColor blackColor]];
[self presentViewController:_pickerController animated:true completion:nil];
}
else
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"提示" message:@"由于您的设备暂不支持摄像头,您无法使用该功能!" delegate:nil cancelButtonTitle:nil otherButtonTitles:@"确认", nil];
[alertView show];
}
}
//开始识别
- (void)startRec:(UIImage *)image
{
NSData *sendImageData = UIImageJPEGRepresentation(image, 0.75);
dispatch_source_t timer=dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, dispatch_get_main_queue());
dispatch_source_set_timer(timer, dispatch_time(DISPATCH_TIME_NOW, 0ull*NSEC_PER_SEC), DISPATCH_TIME_FOREVER, 1ull*NSEC_PER_SEC);
dispatch_source_set_event_handler(timer, ^{
PackageAPI *package = [[PackageAPI alloc] init];
self.resultStr = [package uploadPackage:sendImageData andindexPath:0];
[self performSelectorOnMainThread:@selector(recongnitionResult:) withObject:self.resultStr waitUntilDone:YES];
dispatch_source_cancel(timer);
});
dispatch_source_set_cancel_handler(timer, ^{
NSLog(@"cancel");
});
//启动
dispatch_resume(timer);
}
-(void)recongnitionResult:(id)sender
{
_dataStr= sender;
// [SVProgressHUD dismiss];
if ([_dataStr length])
{
if ([_dataStr isEqualToString:ERROR_SERVER]) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示"
message:ERROR_SERVER
delegate:nil
cancelButtonTitle:nil
otherButtonTitles:@"确定", nil];
[alert show];
return;
}
if ([_dataStr isEqualToString:ERROR_TIMEOUT]) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示"
message:ERROR_TIMEOUT
delegate:nil
cancelButtonTitle:nil
otherButtonTitles:@"确定", nil];
[alert show];
return;
}
if ([_dataStr isEqualToString:ERROR_NULL]) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示"
message:ERROR_NULL
delegate:nil
cancelButtonTitle:nil
otherButtonTitles:@"确定", nil];
[alert show];
return;
}
EditingViewController *edit = [[EditingViewController alloc] init];
edit.dataSource = [self makeCardResultWithStr:_dataStr];
[self.navigationController pushViewController:edit animated:YES];
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示"
message:ERROR_NULL
delegate:nil
cancelButtonTitle:nil
otherButtonTitles:@"确定", nil];
[alert show];
return;
}
}
- (NSString *)makeCardResultWithStr:(NSString*)dataStr
{
if (!dataStr.length)
return nil;
return dataStr;
}
#pragma mark -
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *image;
// NSString *currSysVer = [[UIDevice currentDevice] systemVersion];
image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
UIImageOrientation orientation = [image imageOrientation];
CGImageRef imRef = [image CGImage];
int texWidth = CGImageGetWidth(imRef);
int texHeight = CGImageGetHeight(imRef);
float imageScale = 1;
if(orientation == UIImageOrientationUp && texWidth < texHeight)
image = [UIImage imageWithCGImage:imRef scale:imageScale orientation: UIImageOrientationLeft];
else if((orientation == UIImageOrientationUp && texWidth > texHeight) || orientation == UIImageOrientationRight)
image = [UIImage imageWithCGImage:imRef scale:imageScale orientation: UIImageOrientationUp];
else if(orientation == UIImageOrientationDown)
image = [UIImage imageWithCGImage:imRef scale:imageScale orientation: UIImageOrientationDown];
else if(orientation == UIImageOrientationLeft)
image = [UIImage imageWithCGImage:imRef scale:imageScale orientation: UIImageOrientationUp];
NSLog(@"originalImage width = %f height = %f",image.size.width,image.size.height);
//拍照完成开始识别
[self startRec:image];
//currentTag = 0;
[picker dismissViewControllerAnimated:true completion:nil];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[picker dismissViewControllerAnimated:true completion:nil];
}