iOS 自己實(shí)現(xiàn) 名片識(shí)別 三 圖片處理

1. iOS 自己實(shí)現(xiàn) 名片識(shí)別 一 功能分析,模塊劃分

2. iOS 自己實(shí)現(xiàn) 名片識(shí)別 二 相機(jī)模塊制作

3. iOS 自己實(shí)現(xiàn) 名片識(shí)別 三 圖片處理

4. iOS 自己實(shí)現(xiàn) 名片識(shí)別 四 圖片轉(zhuǎn)文字以及歸類

主題: 圖片處理

聲明:下面這些圖片僅供學(xué)習(xí)使用

0.png

1.剪切圖片

根據(jù)矩形特征剪切圖片

// @property (nonatomic , strong) CIImage *img;
//@property (nonatomic , strong) CIRectangleFeature *feature;

_img = [_img imageByCroppingToRect:_feature.bounds];
1.png

2.圖形矯正

根據(jù)特征修正圖片 , 這一步很重要 , 是否做這一步直接影響識(shí)別精度

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. 灰度處理

主要用來做文字識(shí)別所以直接去掉色彩信息

    CIColor *filterInputcolor = [CIColor colorWithRed:0.75 green:0.75 blue:0.75];
    //只有在主動(dòng)設(shè)置的時(shí)候才丟棄顏色信息
    //CIColorMonochrome  單色濾鏡
    _img = [_img imageByApplyingFilter:@"CIColorMonochrome" withInputParameters:@{kCIInputColorKey : filterInputcolor}];
3.png

4.提升亮度

會(huì)損失一部分背景紋理 飽和度不能太高

    NSDictionary *para = @{
                           kCIInputSaturationKey : @(0.35),  //飽和度
                           kCIInputBrightnessKey : @(0.2),  //亮度
                           kCIInputContrastKey : @(1.1)     //對比度
                           };
    
    //CIColorControls 調(diào)整飽和度、亮度和對比度值
    _img = [_img imageByApplyingFilter:@"CIColorControls" withInputParameters:para];
4.png

5. 曝光調(diào)節(jié)

_img = [_img imageByApplyingFilter:@"CIExposureAdjust" withInputParameters:@{kCIInputEVKey : @(0.65)}];
5.png

6.高斯模糊

查資料的時(shí)候都推薦這個(gè),不過看不懂有什么用

_img = [_img imageByApplyingGaussianBlurWithSigma:0.4];
6.png

7.增強(qiáng)文字輪廓(描邊)

     NSDictionary* para = @{
             kCIInputRadiusKey : @(2.5),                //獲取或設(shè)置要檢測的最小要素的半徑。
             kCIInputIntensityKey : @(0.5),             //獲取或設(shè)置增強(qiáng)對比度的強(qiáng)度
             };
    
    _img = [_img imageByApplyingFilter:@"CIUnsharpMask" withInputParameters:para];
7.png

8.調(diào)低亮度,增加對比度

使圖片字體更黑

    NSDictionary *para = @{
                           kCIInputSaturationKey : @(0.35),  //飽和度
                           kCIInputBrightnessKey : @(-0.7),  //亮度
                           kCIInputContrastKey : @(1.9)     //對比度
                           };
    
    //CIColorControls 調(diào)整飽和度、亮度和對比度值
    _img = [_img imageByApplyingFilter:@"CIColorControls" withInputParameters:para];
9.png

9.增加曝光

使上一步調(diào)黑的背景變白

_img = [_img imageByApplyingFilter:@"CIExposureAdjust" withInputParameters:@{kCIInputEVKey : @(0.65)}];
10.png

至此圖片的處理已經(jīng)完成,剩下的就交給識(shí)別模塊了

文字位置檢測 , 裁剪 (文字位置檢測與裁剪實(shí)現(xiàn)后,與不裁剪對比,明顯不裁剪效果更好,所以把名片作為一個(gè)整體來識(shí)別了)

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容