yzm模块
超级鹰验证码识别¶
Chaojiying_Client
¶
超级鹰验证码客服端
参考文档: http://www.chaojiying.com/api.php
Attributes:
| Name | Type | Description |
|---|---|---|
username |
str
|
超级鹰用户名 |
password |
str
|
超级鹰密码 |
soft_id |
str
|
超级鹰软件ID |
Source code in src/cfun/yzm/chaojiying.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 | |
__init__
¶
初始化超级鹰客户端
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
username
|
str
|
超级鹰用户名 |
required |
password
|
str
|
超级鹰密码 |
required |
soft_id
|
str
|
超级鹰软件ID |
required |
Source code in src/cfun/yzm/chaojiying.py
calculate_md5
staticmethod
¶
计算文件的 MD5 值
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
str
|
文件路径 |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
文件的 MD5 值 |
Source code in src/cfun/yzm/chaojiying.py
read_image
staticmethod
¶
读取图片文件并返回字节
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image_path
|
str
|
图片路径 |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bytes |
bytes
|
图片字节 |
Source code in src/cfun/yzm/chaojiying.py
PostPic
¶
通过网络上传图片进行识别
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
im
|
bytes
|
图片字节 |
required |
codetype
|
int
|
题目类型 参考 http://www.chaojiying.com/price.html |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
超级鹰返回的结果 |
Source code in src/cfun/yzm/chaojiying.py
PostPic_base64
¶
通过网络上传图片进行识别
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base64_str
|
str
|
图片的base64编码字符串 |
required |
codetype
|
int
|
题目类型 参考 http://www.chaojiying.com/price.html |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
超级鹰返回的结果 |
Source code in src/cfun/yzm/chaojiying.py
ReportError
¶
上传错误的图片ID进行反馈
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
im_id
|
str
|
图片ID |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
超级鹰返回的结果 |
Source code in src/cfun/yzm/chaojiying.py
parse_response
¶
解析超级鹰返回的字符串格式
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
res
|
str | dict
|
超级鹰返回的字符串 或者字典格式 |
required |
Returns:
| Name | Type | Description |
|---|---|---|
list |
list
|
解析后的列表 [ {"name": "之", "coordinates": [207, 115]}, {"name": "成", "coordinates": [158, 86]}, {"name": "人", "coordinates": [126, 44]} ] |
Example
Source code in src/cfun/yzm/chaojiying.py
get
¶
根据图片和题目类型获取超级鹰识别结果,
根据图片和题目类型获取超级鹰识别结果, 暂时只针对 codetype=9800 进行处理,其他类型的暂未测试
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image_path
|
str
|
图片路径 |
required |
codetype
|
int
|
题目类型 参考 http://www.chaojiying.com/price.html |
9800
|
Returns:
| Name | Type | Description |
|---|---|---|
list |
list
|
扩展后的结果 |
Example
Source code in src/cfun/yzm/chaojiying.py
ddocrtool封装¶
ddddocr 目标检测工具类
这个类主要是对 ddddocr 进行封装, 方便使用
主要的功能:
-
目标检测,获取目标检测框
-
获取图片的宽高
-
将 ddddocr 返回的目标检测框转换为 xlabing 的格式 (xyxy格式)
-
删除太近边缘的框
-
检查坐标是否在给定的矩形范围内
-
扩展超级鹰识别的结果,增加目标检测框的坐标 (主要的功能)
-
检查框的格式是否正确
ImageDet
¶
Source code in src/cfun/yzm/dddocrtool.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 | |
get_image_size
¶
通过 PIL 库获取图片的宽高
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image_path
|
str | Path
|
图片路径 |
required |
Returns:
| Name | Type | Description |
|---|---|---|
tuple |
(width, height, channels)
|
图片的宽高和通道数 |
Source code in src/cfun/yzm/dddocrtool.py
toxlabeling
¶
把 ddddocr 返回的目标检测框转换为 xlabing 的格式 (xyxy格式)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image_path
|
str
|
图片路径 (与 bboxes 二选一) |
None
|
bboxes
|
list
|
[[x1, y1, x2, y2], ...] (与 image_path 二选一), 这个坐标 左上,右下, 也就是 xyxy 的格式 |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
list |
list
|
[[[x1, y1], [x2, y1], [x2, y2], [x1, y2]], ...] |
PS
- 这个函数主要是把 ddddocr 返回的目标检测框转换为 xlabing 的格式, 也就是四个点的格式, 具体的格式是:
Source code in src/cfun/yzm/dddocrtool.py
extendCJYRecognition
¶
扩展超级鹰识别的结果. (也可以是其他平台的结果, 因为很多平台返回的结果都只含中心点坐标)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ocrdata
|
list of dict
|
超级鹰识别的结果,每个元素是一个字典,格式如下:
|
required |
image_path
|
str
|
图片路径。 |
required |
Returns:
| Type | Description |
|---|---|
list
|
list of dict: 扩展后的结果,每个字典包含以下字段:
|
Example
Source code in src/cfun/yzm/dddocrtool.py
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 | |
check_bboxes_four
staticmethod
¶
检查框的格式是否正确(四个点的格式)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bboxes
|
list
|
[[[x1, y1], [x2, y1], [x2, y2], [x1, y2]], ....] |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True or False |
Source code in src/cfun/yzm/dddocrtool.py
check_bboxes_two
staticmethod
¶
检查框的格式是否正确(两个点的格式)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bboxes
|
list
|
[[x1, y1, x2, y2], ....] |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True or False |