npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-native-baidu-ocr

v1.0.1

Published

A React Native wrapper around the Baidu OCR SDKs for Android and iOS, provides access to Baidu OCR APIs.

Downloads

6

Readme

react-native-baidu-ocr

集成百度文字识别 API SDK 的 React Native 模块,支持 Android 和 iOS 平台。百度的文字识别 API 须付费使用,但是开发者文档很不友好,所以不推荐用它的 OCR 服务。本项目主要目的是练习打包 RN 的原生模块,也就无所谓地狱模式了。

README_en

安装

$ npm install react-native-baidu-ocr --save

自动安装依赖

$ react-native link react-native-baidu-ocr

对于 iOS 平台,link之后还要完成手动的步骤4、5,步骤 6 可选。

手动安装依赖

iOS

  1. 在 XCode 的 project navigator, 右键 LibrariesAdd Files to [your project's name]
  2. 找到 node_modulesreact-native-baidu-ocr ,添加 RNBaiduOcr.xcodeproj
  3. 在 XCode 的 project navigator, 选择你的项目。添加 libRNBaiduOcr.a 到你的项目的 Build PhasesLink Binary With Libraries
  4. 在 XCode 的 project navigator, 打开 Libiraies, 打开 RNBaiduOcr.xcodeproj, 复制 AipOcrSdk.frameworkAipBase.framework 到以你‘项目名’命名的文件夹
    copy_to_ExampleApp
  5. 在 XCode 的 Project Editor Help, 选择 TARGETS, 选择你的项目 ➜ General ➜ Embedded Binaries. 添加 AipOcrSdk.frameworkAipBase.framework
    Embedded Binaries
  6. 如果你选择的使用授权文件的认证,将授权文件添加到 Xcode 以你‘项目名’命名的文件夹

Android

  1. 打开 android/app/src/main/java/[...]/MainActivity.java
  • 添加 import com.reactlibrary.RNBaiduOcrPackage; 到文件开头位置
  • 添加 new RNBaiduOcrPackage()getPackages() 方法
  1. 将下列代码添加到 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')
  2. 添加以下代码到 android/app/build.gradledependencies:
      compile project(':react-native-baidu-ocr')

Usage

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

更详细的API信息,可以直接参考官方文档

authWithToken(String token)

此种身份验证方案直接使用开发者提供的AccessToken

authWithAKSK(String apiKey, String secretKey)

此种身份验证方案使用AK/SK获得AccessToken

authWithLicenseFileData()

使用授权文件获得AccessToken

recognizeGeneral(String imagePath)

通用文字识别(含位置信息版), 在 android 并未实现,返回结果与 recognizeGeneralBasic 相同

recognizeGeneralBasic(String imagePath)

通用文字识别

recognizeGeneralEnhanced(String imagePath)

通用文字识别(含生僻字版)

recognizeWebimage(String imagePath)

网络图片文字识别

recognizeBankCard(String imagePath)

银行卡识别

recognizeIDCard(String imagePath)

识别身份证文字