android 名片识别 简书,iOS 自己实现 名片识别 三 图片处理
主題: 圖片處理
聲明:下面這些圖片僅供學習使用
0.png
1.剪切圖片
根據矩形特征剪切圖片
// @property (nonatomic , strong) CIImage *img;
//@property (nonatomic , strong) CIRectangleFeature *feature;
_img = [_img imageByCroppingToRect:_feature.bounds];
1.png
2.圖形矯正
根據特征修正圖片 , 這一步很重要 , 是否做這一步直接影響識別精度
NSDictionary *para = @{
@"inputTopLeft": [CIVector vectorWithCGPoint:_feature.topLeft],
@"inputTopRight": [CIVector vectorWithCGPoint:_feature.topRight],
@"inputBottomLeft": [CIVector vectorWithCGPoint:_feature.bottomLeft],
@"inputBottomRight": [CIVector vectorWithCGPoint:_feature.bottomRight]
};
_img = [_img imageByApplyingFilter:@"CIPerspectiveCorrection" withInputParameters:para];
2.png
3. 灰度處理
主要用來做文字識別所以直接去掉色彩信息
CIColor *filterInputcolor = [CIColor colorWithRed:0.75 green:0.75 blue:0.75];
//只有在主動設置的時候才丟棄顏色信息
//CIColorMonochrome 單色濾鏡
_img = [_img imageByApplyingFilter:@"CIColorMonochrome" withInputParameters:@{kCIInputColorKey : filterInputcolor}];
3.png
4.提升亮度
會損失一部分背景紋理 飽和度不能太高
NSDictionary *para = @{
kCIInputSaturationKey : @(0.35), //飽和度
kCIInputBrightnessKey : @(0.2), //亮度
kCIInputContrastKey : @(1.1) //對比度
};
//CIColorControls 調整飽和度、亮度和對比度值
_img = [_img imageByApplyingFilter:@"CIColorControls" withInputParameters:para];
4.png
5. 曝光調節
_img = [_img imageByApplyingFilter:@"CIExposureAdjust" withInputParameters:@{kCIInputEVKey : @(0.65)}];
5.png
6.高斯模糊
查資料的時候都推薦這個,不過看不懂有什么用
_img = [_img imageByApplyingGaussianBlurWithSigma:0.4];
6.png
7.增強文字輪廓(描邊)
NSDictionary* para = @{
kCIInputRadiusKey : @(2.5), //獲取或設置要檢測的最小要素的半徑。
kCIInputIntensityKey : @(0.5), //獲取或設置增強對比度的強度
};
_img = [_img imageByApplyingFilter:@"CIUnsharpMask" withInputParameters:para];
7.png
8.調低亮度,增加對比度
使圖片字體更黑
NSDictionary *para = @{
kCIInputSaturationKey : @(0.35), //飽和度
kCIInputBrightnessKey : @(-0.7), //亮度
kCIInputContrastKey : @(1.9) //對比度
};
//CIColorControls 調整飽和度、亮度和對比度值
_img = [_img imageByApplyingFilter:@"CIColorControls" withInputParameters:para];
9.png
9.增加曝光
使上一步調黑的背景變白
_img = [_img imageByApplyingFilter:@"CIExposureAdjust" withInputParameters:@{kCIInputEVKey : @(0.65)}];
10.png
至此圖片的處理已經完成,剩下的就交給識別模塊了
文字位置檢測 , 裁剪 (文字位置檢測與裁剪實現后,與不裁剪對比,明顯不裁剪效果更好,所以把名片作為一個整體來識別了)
總結
以上是生活随笔為你收集整理的android 名片识别 简书,iOS 自己实现 名片识别 三 图片处理的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: service 层 拼接的html 代码
- 下一篇: bootstraptable查看详情_b