
Security News
Crates.io Implements Trusted Publishing Support
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
react-native-baidu-ocr
Advanced tools
A React Native wrapper around the Baidu OCR SDKs for Android and iOS, provides access to Baidu OCR APIs.
集成百度文字识别 API SDK 的 React Native 模块,支持 Android 和 iOS 平台。百度的文字识别 API 须付费使用,但是开发者文档很不友好,所以不推荐用它的 OCR 服务。本项目主要目的是练习打包 RN 的原生模块,也就无所谓地狱模式了。
$ npm install react-native-baidu-ocr --save
$ react-native link react-native-baidu-ocr
对于 iOS 平台,link
之后还要完成手动的步骤4、5,步骤 6 可选。
Libraries
➜ Add Files to [your project's name]
node_modules
➜ react-native-baidu-ocr
,添加 RNBaiduOcr.xcodeproj
libRNBaiduOcr.a
到你的项目的 Build Phases
➜ Link Binary With Libraries
Libiraies
, 打开 RNBaiduOcr.xcodeproj
, 复制 AipOcrSdk.framework
和 AipBase.framework
到以你‘项目名’命名的文件夹AipOcrSdk.framework
和 AipBase.framework
android/app/src/main/java/[...]/MainActivity.java
import com.reactlibrary.RNBaiduOcrPackage;
到文件开头位置new RNBaiduOcrPackage()
到 getPackages()
方法android/settings.gradle
:
include ':react-native-baidu-ocr'
project(':react-native-baidu-ocr').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-baidu-ocr/android')
android/app/build.gradle
的 dependencies
:
compile project(':react-native-baidu-ocr')
import BaiduOcr from 'react-native-baidu-ocr';
/*
* 使用之前先获取授权认证,可以使用以下三张方法之一:
* BaiduOCR.authWithToken(String token);
* BaiduOCR.authWithAKSK(String apiKey, String secretKey)
* BaiduOCR.authWithLicenseFileData()
*/
componentDidMount(){
BaiduOCR.authWithToken(yourAccessToken);
}
/*
* imagePath
* for Android, eg:
* "/storage/[...]/image-09cc1d6c-b6bd-40fa-a383-025b960d25a8.jpg"
* for iOS, eg:
* "file:///Users/[...]/C553DAA3-FA8D-4D77-86FF-7C4C75DFF7D7.jpg"
*/
BaiduOCR.recognizeGeneralBasic(imagePath)
.then((data)=>{
console.log(JSON.stringify(data))
})
.catch((err)=>{
console.log(err)
})
更详细的API信息,可以直接参考官方文档
此种身份验证方案直接使用开发者提供的AccessToken
此种身份验证方案使用AK/SK获得AccessToken
使用授权文件获得AccessToken
通用文字识别(含位置信息版), 在 android 并未实现,返回结果与 recognizeGeneralBasic 相同
通用文字识别
通用文字识别(含生僻字版)
网络图片文字识别
银行卡识别
识别身份证文字
FAQs
A React Native wrapper around the Baidu OCR SDKs for Android and iOS, provides access to Baidu OCR APIs.
The npm package react-native-baidu-ocr receives a total of 3 weekly downloads. As such, react-native-baidu-ocr popularity was classified as not popular.
We found that react-native-baidu-ocr demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
Research
/Security News
Undocumented protestware found in 28 npm packages disrupts UI for Russian-language users visiting Russian and Belarusian domains.
Research
/Security News
North Korean threat actors deploy 67 malicious npm packages using the newly discovered XORIndex malware loader.