GithubHelp home page GithubHelp logo

easypr_ios's Introduction

EasyPR_iOS

介绍如何将EasyPR集成到iOS平台/EasyPR在macOS上调试。

EasyPR github项目地址:https://github.com/liuruoze/EasyPR

如何在mac上调试

mac上使用EasyPR进行车牌号识别

如何在iOS项目中使用(Xcode9)

1). 集成openCV具体看这里

2). 添加srcthirdpartyincludemodel (model为蓝色)

2017092752315cc2.png

并保证

copy bundle resource里引入了蓝色文件夹model Complie Sources添加了src和util的文件夹内cpp文件

3). Header Search Path添加$(SRCROOT)/EasyPR_iOS/include

4). 尝试#include "easypr.h"发现报错

02.png

原因应该是名字和iOSMacTypes.h的冲突了 处理方法:报错的全部加cv::前缀。

5). 尝试运行,发现报错,原因是路径的问题

03.png

解决方法参考了https://github.com/zhoushiwei/EasyPR-iOS:

根据include/esaypr/config.h里的变量名,创建全局变量,并修改源码。

新建cpp文件:

SGGlobalEasyPRPath.hpp:

#ifndef SGGlobalEasyPRPath_hpp
#define SGGlobalEasyPRPath_hpp

#include <stdio.h>
#include <string>

class SGGlobalEasyPRPath {
public:
    static std::string kDefaultSvmPath;
    static std::string kLBPSvmPath;
    static std::string kHistSvmPath;    
    static std::string kDefaultAnnPath;
    static std::string kChineseAnnPath;
    static std::string kGrayAnnPath;
    static std::string kChineseMappingPath;
    SGGlobalEasyPRPath()=default;    
private:
};
#endif /* SGGlobalEasyPRPath_hpp */

SGGlobalEasyPRPath.hpp:

#include "SGGlobalEasyPRPath.hpp"

std::string SGGlobalEasyPRPath::kDefaultSvmPath;
std::string SGGlobalEasyPRPath::kLBPSvmPath;
std::string SGGlobalEasyPRPath::kHistSvmPath;

std::string SGGlobalEasyPRPath::kDefaultAnnPath;
std::string SGGlobalEasyPRPath::kChineseAnnPath;
std::string SGGlobalEasyPRPath::kGrayAnnPath;
std::string SGGlobalEasyPRPath::kChineseMappingPath;

使用之前赋给变量值,比如写到AppDelegate.mm里面:

#import "AppDelegate.h"
#include "SGGlobalEasyPRPath.hpp"
@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
    NSString* bundlePath=[[NSBundle mainBundle] bundlePath];
    SGGlobalEasyPRPath::kDefaultSvmPath = [[NSString stringWithFormat:@"%@/model/svm_hist.xml",bundlePath] UTF8String];;
    SGGlobalEasyPRPath::kLBPSvmPath = [[NSString stringWithFormat:@"%@/model/svm_lbp.xml",bundlePath] UTF8String];;
    SGGlobalEasyPRPath::kHistSvmPath = [[NSString stringWithFormat:@"%@/model/svm_hist.xml",bundlePath] UTF8String];;
    SGGlobalEasyPRPath::kDefaultAnnPath = [[NSString stringWithFormat:@"%@/model/ann.xml",bundlePath] UTF8String];;
    SGGlobalEasyPRPath::kChineseAnnPath = [[NSString stringWithFormat:@"%@/model/ann_chinese.xml",bundlePath] UTF8String];;
    SGGlobalEasyPRPath::kGrayAnnPath = [[NSString stringWithFormat:@"%@/model/annCh.xml",bundlePath] UTF8String];;
    SGGlobalEasyPRPath::kChineseMappingPath = [[NSString stringWithFormat:@"%@/model/province_mapping",bundlePath] UTF8String];;
    std::cout<<"SGGlobalEasyPRPath::mainBundle():"<< SGGlobalEasyPRPath::kChineseAnnPath  <<std::endl;
    return YES;
}
@end

然后修改源代码,将用到路径的地方 #include "SGGlobalEasyPRPath.hpp"并添加前缀SGGlobalEasyPRPath::

如:kChineseMappingPath改为SGGlobalEasyPRPath::kChineseMappingPath

注意:引用SGGlobalEasyPRPath.hpp的.m文件,后缀改为.mm

5). 跑下测试效果

#import "ViewController.h"

#import <opencv2/opencv.hpp>

#include "easypr.h"
using namespace cv;
using namespace easypr;

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self myFunction];
}

- (void)myFunction{
    
    cv::Mat cvImage;
    cv::Mat RGB;
    CPlateRecognize pr;
    
    NSString *path = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"jpg"];
    Mat img = imread([path UTF8String]);
 
    if (img.empty()) {
        return;
    }
    cvtColor(img, RGB, COLOR_BGRA2RGB);
    vector<CPlate> plateVec;
    int result = pr.plateRecognize(RGB, plateVec);
    NSLog(@"result %@",@(result));
    if (result != 0) cout << "result:" << result << endl;
    if(plateVec.size()==0){
        
    }else {
        string name=plateVec[0].getPlateStr();
        NSString *resultMessage = [NSString stringWithCString:plateVec[0].getPlateStr().c_str()
                                                     encoding:NSUTF8StringEncoding];
        NSLog(@"%@",resultMessage);
    }
}
@end

04.png

easypr_ios's People

Contributors

tyrad avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.