post ok
Browse files- .gitignore +2 -0
- .vscode/launch.json +12 -12
- main.py +12 -6
- package.json +5 -0
- post.js +60 -0
.gitignore
CHANGED
|
@@ -1,5 +1,7 @@
|
|
| 1 |
__pycache__
|
|
|
|
| 2 |
logs
|
|
|
|
| 3 |
# local_*
|
| 4 |
# inpainted
|
| 5 |
# mask
|
|
|
|
| 1 |
__pycache__
|
| 2 |
+
node_modules
|
| 3 |
logs
|
| 4 |
+
package-lock.json
|
| 5 |
# local_*
|
| 6 |
# inpainted
|
| 7 |
# mask
|
.vscode/launch.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
| 1 |
-
{
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
}
|
|
|
|
| 1 |
+
// {
|
| 2 |
+
// "version": "0.2.0",
|
| 3 |
+
// "configurations": [
|
| 4 |
+
// {
|
| 5 |
+
// "name": "Python Debugger: Current File",
|
| 6 |
+
// "type": "debugpy",
|
| 7 |
+
// "request": "launch",
|
| 8 |
+
// "program": "${file}",
|
| 9 |
+
// "console": "integratedTerminal"
|
| 10 |
+
// }
|
| 11 |
+
// ]
|
| 12 |
+
// }
|
main.py
CHANGED
|
@@ -25,7 +25,7 @@ import PIL
|
|
| 25 |
import cv2
|
| 26 |
import numpy as np
|
| 27 |
|
| 28 |
-
is_debug =
|
| 29 |
|
| 30 |
dic_cache = {}
|
| 31 |
|
|
@@ -158,21 +158,25 @@ def ocr(img):
|
|
| 158 |
img_draw = img.copy()
|
| 159 |
|
| 160 |
|
|
|
|
|
|
|
| 161 |
# ui\mainwindow.py
|
| 162 |
for blk in blk_list:
|
| 163 |
text = blk.get_text()
|
|
|
|
|
|
|
| 164 |
for line in blk.lines:
|
| 165 |
img_draw = cv2.rectangle(img_draw, line[0], line[3], (0, 0, 255), 2) # 在一行坚排文字的左边画一条红线
|
| 166 |
|
| 167 |
|
| 168 |
-
return
|
| 169 |
|
| 170 |
@app.route('/comicocr', methods=['post'])
|
| 171 |
def comicocr():
|
| 172 |
global dic_cache
|
| 173 |
|
| 174 |
# request.json 只能够接受方法为POST、Body为raw,header 内容为 application/json类型的数据
|
| 175 |
-
print(request.json, type(request.json))
|
| 176 |
|
| 177 |
|
| 178 |
img_b64_str = request.json['img']
|
|
@@ -186,10 +190,12 @@ def comicocr():
|
|
| 186 |
img = cv2.cvtColor(img, cv2.COLOR_RGBA2RGB)
|
| 187 |
|
| 188 |
|
| 189 |
-
cv2.imshow('test', img)
|
| 190 |
-
cv2.waitKey()
|
|
|
|
|
|
|
| 191 |
|
| 192 |
-
return jsonify(
|
| 193 |
|
| 194 |
|
| 195 |
def main():
|
|
|
|
| 25 |
import cv2
|
| 26 |
import numpy as np
|
| 27 |
|
| 28 |
+
is_debug = False
|
| 29 |
|
| 30 |
dic_cache = {}
|
| 31 |
|
|
|
|
| 158 |
img_draw = img.copy()
|
| 159 |
|
| 160 |
|
| 161 |
+
results = []
|
| 162 |
+
|
| 163 |
# ui\mainwindow.py
|
| 164 |
for blk in blk_list:
|
| 165 |
text = blk.get_text()
|
| 166 |
+
lines = blk.lines
|
| 167 |
+
results.append( { "text": text, "lines":lines } )
|
| 168 |
for line in blk.lines:
|
| 169 |
img_draw = cv2.rectangle(img_draw, line[0], line[3], (0, 0, 255), 2) # 在一行坚排文字的左边画一条红线
|
| 170 |
|
| 171 |
|
| 172 |
+
return results, img_draw
|
| 173 |
|
| 174 |
@app.route('/comicocr', methods=['post'])
|
| 175 |
def comicocr():
|
| 176 |
global dic_cache
|
| 177 |
|
| 178 |
# request.json 只能够接受方法为POST、Body为raw,header 内容为 application/json类型的数据
|
| 179 |
+
# print(request.json, type(request.json))
|
| 180 |
|
| 181 |
|
| 182 |
img_b64_str = request.json['img']
|
|
|
|
| 190 |
img = cv2.cvtColor(img, cv2.COLOR_RGBA2RGB)
|
| 191 |
|
| 192 |
|
| 193 |
+
# cv2.imshow('test', img)
|
| 194 |
+
# cv2.waitKey()
|
| 195 |
+
|
| 196 |
+
results, img_draw = ocr(img)
|
| 197 |
|
| 198 |
+
return jsonify(results)
|
| 199 |
|
| 200 |
|
| 201 |
def main():
|
package.json
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"dependencies": {
|
| 3 |
+
"request": "^2.88.2"
|
| 4 |
+
}
|
| 5 |
+
}
|
post.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
(async () => {
|
| 3 |
+
|
| 4 |
+
const request = require('request')
|
| 5 |
+
const fs = require('fs')
|
| 6 |
+
|
| 7 |
+
imgData = fs.readFileSync('E:/huggingface/BallonsTranslator/assets/kcc-0010.jpg').toString('base64')
|
| 8 |
+
|
| 9 |
+
const api = 'http://127.0.0.1:2393/comicocr'
|
| 10 |
+
|
| 11 |
+
const data = await new Promise((resolve, reject) => {
|
| 12 |
+
request.post({
|
| 13 |
+
url: api,
|
| 14 |
+
timeout: 1000 * 60 * 2,
|
| 15 |
+
headers: {
|
| 16 |
+
"Content-Type": "application/json;charset=UTF-8"
|
| 17 |
+
},
|
| 18 |
+
body: JSON.stringify({
|
| 19 |
+
img: imgData,
|
| 20 |
+
prob: true,
|
| 21 |
+
charInfo: true,
|
| 22 |
+
table: true,
|
| 23 |
+
sortPage: true,
|
| 24 |
+
NeedRotate:true
|
| 25 |
+
})
|
| 26 |
+
}, (error, response, body) => {
|
| 27 |
+
if (error) {
|
| 28 |
+
console.log('#####ERROR: aliyun ocr fail.');
|
| 29 |
+
console.log(error);
|
| 30 |
+
reject(error);
|
| 31 |
+
}
|
| 32 |
+
else {
|
| 33 |
+
if (response.statusCode != 200) {
|
| 34 |
+
return resolve({"error_code":response.statusCode, "error_msg":body})
|
| 35 |
+
}
|
| 36 |
+
let aliResult = null;
|
| 37 |
+
try {
|
| 38 |
+
aliResult = JSON.parse(body);
|
| 39 |
+
} catch (ex) {
|
| 40 |
+
console.log(ex.message);
|
| 41 |
+
console.log(response.statusCode);
|
| 42 |
+
console.log(error);
|
| 43 |
+
console.log(body);
|
| 44 |
+
}
|
| 45 |
+
resolve(aliResult);
|
| 46 |
+
}
|
| 47 |
+
})
|
| 48 |
+
});
|
| 49 |
+
|
| 50 |
+
if (data.error_code !== undefined && data.error_code !== null) {
|
| 51 |
+
a = 1
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
})()
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
|