-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0e11c3b
commit 03acea6
Showing
7 changed files
with
124 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
FROM python:3.8-slim | ||
RUN apt-get update -y | ||
RUN apt-get install -y libpcsclite-dev psmisc | ||
RUN mkdir -p /root/kby-ai-idcard | ||
WORKDIR /root/kby-ai-idcard | ||
COPY ./libidsdk.so . | ||
COPY ./idsdk.py . | ||
COPY ./app.py . | ||
COPY ./requirements.txt . | ||
COPY ./data ./data | ||
RUN pip3 install -r requirements.txt | ||
CMD [ "python3", "app.py"] | ||
EXPOSE 8080 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import sys | ||
sys.path.append('.') | ||
|
||
import os | ||
import base64 | ||
import json | ||
|
||
from flask import Flask, request, jsonify | ||
from idsdk import getMachineCode | ||
from idsdk import setActivation | ||
from idsdk import initSDK | ||
from idsdk import idcardRecognition | ||
|
||
licensePath = "license.txt" | ||
license = "" | ||
|
||
machineCode = getMachineCode() | ||
print("machineCode: ", machineCode.decode('utf-8')) | ||
|
||
try: | ||
with open(licensePath, 'r') as file: | ||
license = file.read() | ||
except IOError as exc: | ||
print("failed to open license.txt: ", exc.errno) | ||
print("license: ", license) | ||
|
||
ret = setActivation(license.encode('utf-8')) | ||
print("activation: ", ret) | ||
|
||
ret = initSDK() | ||
print("init: ", ret) | ||
|
||
app = Flask(__name__) | ||
|
||
@app.route('/idcard_recognition', methods=['POST']) | ||
def idcard_recognition(): | ||
try: | ||
file = request.files['file'] | ||
|
||
base64_image = base64.b64encode(file.read()).decode('utf-8') | ||
ret = idcardRecognition(base64_image.encode('utf-8')) | ||
|
||
if ret != None: | ||
j = json.loads(ret) | ||
j.update({"Status": "Ok"}) | ||
response = jsonify(j) | ||
else: | ||
response = jsonify({"Status": "Error"}) | ||
except: | ||
response = jsonify({"Status": "Error"}) | ||
|
||
response.status_code = 200 | ||
response.headers["Content-Type"] = "application/json; charset=utf-8" | ||
return response | ||
|
||
@app.route('/idcard_recognition_base64', methods=['POST']) | ||
def idcard_recognition_base64(): | ||
try: | ||
content = request.get_json() | ||
base64_image = content['base64'] | ||
|
||
ret = idcardRecognition(base64_image.encode('utf-8')) | ||
|
||
if ret != None: | ||
j = json.loads(ret) | ||
j.update({"Status": "Ok"}) | ||
response = jsonify(j) | ||
else: | ||
response = jsonify({"Status": "Error"}) | ||
except: | ||
response = jsonify({"Status": "Error"}) | ||
|
||
response.status_code = 200 | ||
response.headers["Content-Type"] = "application/json; charset=utf-8" | ||
return response | ||
|
||
if __name__ == '__main__': | ||
port = int(os.environ.get("PORT", 8080)) | ||
app.run(host='0.0.0.0', port=port) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import os | ||
|
||
from ctypes import * | ||
|
||
libPath = os.path.abspath(os.path.dirname(__file__)) + '/libidsdk.so' | ||
idsdk = cdll.LoadLibrary(libPath) | ||
|
||
getMachineCode = idsdk.getMachineCode | ||
getMachineCode.argtypes = [] | ||
getMachineCode.restype = c_char_p | ||
|
||
setActivation = idsdk.setActivation | ||
setActivation.argtypes = [c_char_p] | ||
setActivation.restype = c_int32 | ||
|
||
initSDK = idsdk.initSDK | ||
initSDK.argtypes = [] | ||
initSDK.restype = c_int32 | ||
|
||
idcardRecognition = idsdk.idcardRecognition | ||
idcardRecognition.argtypes = [c_char_p] | ||
idcardRecognition.restype = c_char_p | ||
|
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
You must receive the license. | ||
Please contact us: | ||
Email: [email protected] | ||
Telegram: @kbyai | ||
WhatsApp: +19092802609 | ||
Skype: live:.cid.66e2522354b1049b |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
flask | ||
flask-cors |