Skip to main content

wechat_mp_ocr/
lib.rs

1//! 微信小程序图像处理与文字识别
2//!
3//! 文档:[图像处理与文字识别](https://developers.weixin.qq.com/miniprogram/dev/server/API/img-ocr/)
4
5mod cv;
6mod img;
7mod input;
8mod models;
9mod ocr;
10
11pub use img::*;
12pub use input::ImageSource;
13pub use models::*;
14pub use ocr::*;
15
16use wechat_mp_core::MpClient;
17
18/// OCR / 图像处理 API 门面
19#[derive(Clone)]
20pub struct OcrApi {
21    client: MpClient,
22}
23
24impl OcrApi {
25    pub fn new(client: MpClient) -> Self {
26        Self { client }
27    }
28
29    pub fn client(&self) -> &MpClient {
30        &self.client
31    }
32
33    /// 通用印刷体
34    pub async fn printed_text(
35        &self,
36        img: ImageSource,
37    ) -> wechat_mp_core::Result<CommOcrResponse> {
38        printed_text(&self.client, img).await
39    }
40
41    /// 身份证
42    pub async fn id_card(&self, img: ImageSource) -> wechat_mp_core::Result<IdCardOcrResponse> {
43        id_card(&self.client, img).await
44    }
45
46    /// 银行卡
47    pub async fn bank_card(
48        &self,
49        img: ImageSource,
50    ) -> wechat_mp_core::Result<BankCardOcrResponse> {
51        bank_card(&self.client, img).await
52    }
53
54    /// 行驶证
55    pub async fn driving(&self, img: ImageSource) -> wechat_mp_core::Result<DrivingOcrResponse> {
56        driving(&self.client, img).await
57    }
58
59    /// 驾驶证
60    pub async fn driving_license(
61        &self,
62        img: ImageSource,
63    ) -> wechat_mp_core::Result<DrivingLicenseOcrResponse> {
64        driving_license(&self.client, img).await
65    }
66
67    /// 营业执照
68    pub async fn biz_license(
69        &self,
70        img: ImageSource,
71    ) -> wechat_mp_core::Result<BizLicenseOcrResponse> {
72        biz_license(&self.client, img).await
73    }
74
75    /// 智能裁剪
76    pub async fn ai_crop(
77        &self,
78        img: ImageSource,
79        ratios: Option<&str>,
80    ) -> wechat_mp_core::Result<AiCropResponse> {
81        ai_crop(&self.client, img, ratios).await
82    }
83
84    /// 二维码 / 条码识别
85    pub async fn scan_qrcode(&self, img: ImageSource) -> wechat_mp_core::Result<QrCodeResponse> {
86        scan_qrcode(&self.client, img).await
87    }
88}