iOS之身份证号码识别
来源:互联网 发布:ubuntu 12.04 qq 编辑:程序博客网 时间:2024/06/01 09:15
from: http://fengdeng.github.io/2016/08/18/iOS%E5%AE%9E%E7%8E%B0%E8%BA%AB%E4%BB%BD%E8%AF%81%E5%8F%B7%E7%A0%81%E8%AF%86%E5%88%AB/
##Begin
这里使用到两个C++的库
- OpenCV
- Tesseract
OpenCV
在这里实现图像处理,Tesseract
在这里实现数字识别
先上效果图:隐私打码谢谢
###0x00 获取视频流
iOS里获取视频流比较简单,当然OpenCV里也有这功能,这里只说前一种。大家可以直接搜 AVCaptureSession
,这里我就直接上代码了。
在回调里获取到图片,并且转化为UIImage
-(void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection{ CVImageBufferRef ref = CMSampleBufferGetImageBuffer(sampleBuffer); CIImage* ciImage = [[CIImage alloc]initWithCVPixelBuffer:ref]; CIContext *context = [CIContext contextWithOptions:nil]; CGImageRef cgImage = [context createCGImage:ciImage fromRect:[ciImage extent]]; UIImage * image = [[UIImage alloc]initWithCGImage:cgImage]; CGImageRelease(cgImage);}
###0x01 OpenCV处理图片
集成OpenCV的方法很简单,直接使用Cocospod就可以了。
pod 'OpenCV', '~> 3.0.0'
OpenCV地址
这里说下主要的对身份证的处理
灰度图
cvtColor(dst, dst, COLOR_BGR2GRAY);
二值化
threshold(dst, dst, 80, 255, THRESH_BINARY);
腐蚀
erode(dst,dst,Mat(27,27,CV_8U),Point(-1,-1),2);
轮廓检测
Mat c = dst.clone();vector<vector<Point>> contours;findContours(c, contours, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE,cvPoint(0, 0));//除去太长或者太短的轮廓int cmin = 35;int cmax = 800;vector<std::vector<cv::Point>>::iterator itc = contours.begin();while(itc != contours.end()){ Rect rect = boundingRect(*itc); if(itc->size() < cmin || itc->size() > cmax || rect.width < 40 || rect.height < 40){ //std::cout << "EraseSize: " << itc->size() << std::endl; itc = contours.erase(itc); } else{ ++itc;};}
取出身份证号码区域
vector<Rect> rects;Rect rr = Rect(0,0,0,0);std::vector<std::vector<cv::Point>>::const_iterator itContours = contours.begin();for ( ; itContours!=contours.end(); ++itContours){ Rect rect = boundingRect(*itContours); rects.push_back(rect); //std::cout << "Size: " << rect << std::endl; if (rect.width > rr.width && rect.width > rect.height * 5) { rr = rect; }}
###0x02 Tesseract进行数字识别
集成OpenCV的方法也很简单,直接使用了别人封装好的一个库,当然也可以自己编译直接使用C++的。
pod 'TesseractOCRiOS', '~> 4.0.0'
GitHub地址
直接识别
self.tesseract = [[G8Tesseract alloc] initWithLanguage:@"chi_sim"];tesseract.charWhitelist = @"0123456789";self.tesseract.image = [i g8_blackAndWhite]; // Optional: Limit the area of the image Tesseract should recognize on to a rectangleself.tesseract.rect = CGRectMake(0, 0, i.size.width, i.size.height); // Optional: Limit recognition time with a few secondsself.tesseract.maximumRecognitionTime = 2.0; // Start the recognition[self.tesseract recognize]; // Retrieve the recognized textNSLog(@"识别:%@", [self.tesseract recognizedText]);
阅读全文
0 0
- iOS之身份证号码识别
- iOS身份证号码识别
- iOS身份证号码识别
- iOS身份证号码识别
- iOS身份证号码识别
- IOS之身份证号码校验
- iOS开发之身份证号码校验
- 谈谈计算机图像识别技术之身份证号码识别
- iOS开发之身份证号码的验证
- 手机识别身份证号码
- IOS之手势识别
- ios之手势识别
- iOS AVCaptureSession实现获取摄像头图像,并识别图片中身份证号码
- 身份证号码识别 Opencv3.3.0(C++)
- 【python 图像识别】python 身份证号码识别
- ios身份证号码判断
- iOS 判断身份证号码
- iOS 判断身份证号码
- spark streaming
- 年度重磅:2017微软技术暨生态大会将于10月23日北京召开!
- form和ajax的重定向
- 我的程序员之路
- Java抽象类与接口比较
- iOS之身份证号码识别
- 画NRF51822 PCB错误总结
- JavaScript Date 对象应用
- Python 函数式编程(高阶函数、把函数作为参数、map()函数、reduce()函数、filter()函数、自定义排序函数、函数返回函数、闭包、匿名函数、装饰器decorator)
- Android:一
- Javascript中几种较为流行的继承方式
- 确保线程安全的几种方法
- 反射(转载)
- 关于文字溢出(text-overflow)及相关延伸