Upload 20 files
Browse filesFiles changed (21)
- .gitattributes+4
- DockerfileAdded+23
- app.pyAdded+131
- arial.ttfAdded+3
- demo.pyAdded+140
- examples/1.jpgAdded
- examples/2.jpgAdded
- examples/3.jpgAdded
- install.shAdded+11
- lib/libopycard.soAdded
- lib/libopycardenv.soAdded+3
- lib/libtensorflow.so.1.14.0Added+3
- lib/libtensorflow_framework.so.1.14.0Added+3
- license.txtAdded+1
- model/detect.binAdded+3
- model/fp.binAdded+3
- model/map.binAdded+3
- model/recog.binAdded+3
- opycard.pyAdded+27
- requirements.txtAdded+4
- run.shAdded+5
32 unmodified lines33343532 unmodified lines*.zip filter=lfs diff=lfs merge=lfs -text*.zst filter=lfs diff=lfs merge=lfs -text*tfevents* filter=lfs diff=lfs merge=lfs -text32 unmodified lines3334353637383932 unmodified lines*.zip filter=lfs diff=lfs merge=lfs -text*.zst filter=lfs diff=lfs merge=lfs -text*tfevents* filter=lfs diff=lfs merge=lfs -textarial.ttf filter=lfs diff=lfs merge=lfs -textlib/libopycardenv.so filter=lfs diff=lfs merge=lfs -textlib/libtensorflow_framework.so.1.14.0 filter=lfs diff=lfs merge=lfs -textlib/libtensorflow.so.1.14.0 filter=lfs diff=lfs merge=lfs -text
1234567891011121314151617181920212223FROM python:3.8-slimWORKDIR /home/opycardCOPY ./opycard.py .COPY ./app.py .COPY ./demo.py .COPY ./license.txt .COPY ./requirements.txt .COPY ./run.sh .COPY ./arial.ttf .COPY ./examples ./examplesCOPY ./model ./modelCOPY ./lib/libopycard.so ./lib/libopycard.soCOPY ./lib/libopycardenv.so ./lib/libopycardenv.soCOPY ./lib/libtensorflow_framework.so.1.14.0 /usr/lib/libtensorflow_framework.so.1.14.0COPY ./lib/libtensorflow.so.1.14.0 /usr/lib/libtensorflow.so.1.14.0RUN ln -s /usr/lib/libtensorflow.so.1.14.0 /usr/lib/libtensorflow.so.1 \ && ln -s /usr/lib/libtensorflow.so.1.14.0 /usr/lib/libtensorflow.so \ && ln -s /usr/lib/libtensorflow_framework.so.1.14.0 /usr/lib/libtensorflow_framework.so.1 \ && ln -s /usr/lib/libtensorflow_framework.so.1.14.0 /usr/lib/libtensorflow_framework.soRUN pip3 install -r requirements.txtRUN chmod a+x run.shCMD ["./run.sh"]EXPOSE 9000 7860123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131import syssys.path.append('.')
import osimport numpy as npimport base64import jsonimport io
from PIL import Image, ExifTagsfrom flask import Flask, request, jsonifyfrom opyalpr import getHWIDfrom opyalpr import setLicenseKeyfrom opyalpr import initSDKfrom opyalpr import processImage
licenseKeyPath = "license.txt"license = ""
try: with open(licenseKeyPath, 'r') as file: license = file.read().strip()except IOError as exc: print("failed to open license.txt: ", exc.errno)print("License Key: ", license)
hwid = getHWID()print("HWID: ", hwid.decode('utf-8'))
ret = setLicenseKey(license.encode('utf-8'))print("Set License: ", ret)
ret = initSDK("model".encode('utf-8'))print("Init: ", ret)
app = Flask(__name__)
def apply_exif_rotation(image): try: exif = image._getexif() if exif is not None: for orientation in ExifTags.TAGS.keys(): if ExifTags.TAGS[orientation] == 'Orientation': break
# Get the orientation value orientation = exif.get(orientation, None)
# Apply the appropriate rotation based on the orientation if orientation == 3: image = image.rotate(180, expand=True) elif orientation == 6: image = image.rotate(270, expand=True) elif orientation == 8: image = image.rotate(90, expand=True)
except AttributeError: print("No EXIF data found")
return image
@app.route('/process_image', methods=['POST'])def process_image(): file = request.files['image']
try: image = apply_exif_rotation(Image.open(file)).convert('RGB') except: result = "Failed to open file" response = jsonify({"resultCode": "Error", "result": result})
response.status_code = 200 response.headers["Content-Type"] = "application/json; charset=utf-8" return response
image_np = np.asarray(image) result = processImage(image_np, image_np.shape[1], image_np.shape[0])
if result is None: result = "Failed to process image" response = jsonify({"resultCode": "Error", "result": result})
response.status_code = 200 response.headers["Content-Type"] = "application/json; charset=utf-8" return response else: result_dict = json.loads(result.decode('utf-8')) response = jsonify({"resultCode": "Ok", "result": result_dict})
response.status_code = 200 response.headers["Content-Type"] = "application/json; charset=utf-8" return response
@app.route('/process_image_base64', methods=['POST'])def process_image_base64(): try: content = request.get_json() base64_image = content['base64']
image_data = base64.b64decode(base64_image) image = apply_exif_rotation(Image.open(io.BytesIO(image_data))).convert("RGB") except: result = "Failed to parse base64" response = jsonify({"resultCode": "Error", "result": result})
response.status_code = 200 response.headers["Content-Type"] = "application/json; charset=utf-8" return response
image_np = np.asarray(image) result = processImage(image_np, image_np.shape[1], image_np.shape[0])
if result is None: result = "Failed to process image" response = jsonify({"resultCode": "Error", "result": result})
response.status_code = 200 response.headers["Content-Type"] = "application/json; charset=utf-8" return response else: result_dict = json.loads(result.decode('utf-8')) response = jsonify({"resultCode": "Ok", "result": result_dict})
response.status_code = 200 response.headers["Content-Type"] = "application/json; charset=utf-8" return response
if __name__ == '__main__': port = int(os.environ.get("PORT", 9000)) app.run(host='0.0.0.0', port=port)123version https://git-lfs.github.com/spec/v1oid sha256:baa251526d6862712a58e613ef451d8a2b60482142ec6aab1d47fb8e23e21a7csize 1045960123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140import osimport gradio as grimport requestsimport jsonimport iofrom gradio.components import Imagefrom PIL import Image as PILImage, ImageDraw, ImageFont # This import may be needed if you're processing images
from PIL import Image
def resize_image_with_aspect_ratio(image, target_height): # Get original dimensions original_width, original_height = image.size # Calculate the new width to maintain aspect ratio aspect_ratio = original_width / original_height new_width = int(target_height * aspect_ratio) # Resize the image resized_image = image.resize((new_width, target_height), Image.LANCZOS) return resized_image
def draw_text_with_background(draw, text, position, font, text_color="red", bg_color="white", padding=2): # Get the bounding box of the text bbox = draw.textbbox(position, text, font=font) # Calculate the background rectangle coordinates bg_x0, bg_y0, bg_x1, bg_y1 = bbox[0] - padding, bbox[1] - padding, bbox[2] + padding, bbox[3] + padding # Draw the background rectangle draw.rectangle([bg_x0, bg_y0, bg_x1, bg_y1], fill=bg_color) # Draw the text on top of the background draw.text(position, text, fill=text_color, font=font)
def process_image(image): # Convert PIL image to bytes to send in POST request img_bytes = io.BytesIO() image.save(img_bytes, format="JPEG") img_bytes.seek(0) url = "http://127.0.0.1:9000/process_image" files = {'image': img_bytes} result = requests.post(url=url, files=files)
# Font setup (default font) try: font = ImageFont.truetype("arial.ttf", int(image.size[1] / 30)) except IOError: font = ImageFont.load_default()
draw = ImageDraw.Draw(image) if result.ok: json_result = result.json() if json_result.get("resultCode") == "Error": return [image, {"resultCode": "Error", "result": "Failed to process image"}]
# plates = json_result.get("result", {}).get("plates", []) # for plate in plates: # number = plate.get("number") # left = plate.get("left") # top = plate.get("top") # right = plate.get("right") # bottom = plate.get("bottom") # countryCode = plate.get('countryCode') # car = plate.get('car') # if car is not None: # car_left = car.get('left') # car_top = car.get('top') # car_right = car.get('right') # car_bottom = car.get('bottom') # color = car.get('color') # madeBy = car.get('madeBy') # model = car.get('model') # draw.rectangle([car_left, car_top, car_right, car_bottom], outline="white", width=3) # draw_text_with_background(draw, color + "," + madeBy + "," + model, (car_left, car_top - 10), font, text_color="blue", bg_color="white") # # Draw rectangle and plate number # if left is not None: # draw.rectangle([left, top, right, bottom], outline="green", width=3) # draw_text_with_background(draw, number + "," + countryCode, (left, top - 10), font, text_color="green", bg_color="white")
return [image, json_result] else: return [image, {"resultCode": "Error", "result": result.text}] with gr.Blocks() as demo: gr.Markdown( """ <div style="display: flex;align-items: center;"> <img alt="Opulentyn Logo" src="https://github.com/user-attachments/assets/5fc78032-bff2-4f7e-a174-7d64b22f506d" width="350"/> <div> <h1>Credit Card OCR</h1> <p>We offer <b>on-premises</b> OCR and liveness check solutions available with a <b>perpetual license</b>.</p> </div> </div> ## 🤝 Talk to us <div style="display: flex; align-items: center;"> <a href="https://opulentyn.com" target="_blank"> <img src="https://img.shields.io/badge/Website-https%3A%2F%2Fopulentyn.com-blue?style=flat&logo=google-chrome&logoColor=white" alt="Website"> </a> <a href="mailto:support@opulentyn.com"> <img src="https://img.shields.io/badge/Email-support%40opulentyn.com-blue?style=flat&logo=gmail&logoColor=white" alt="Email"> </a> <a href="https://wa.me/13435013587" target="_blank"> <img src="https://img.shields.io/badge/WhatsApp-%2B13435013587-blue?logo=whatsapp&logoColor=green" alt="WhatsApp"> </a> <a href="https://join.slack.com/t/opulentyn/shared_invite/zt-2s230jtbq-dWBs8XUZcrYim~nUqiimSA" target="_blank"> <img src="https://img.shields.io/badge/Slack-support--sdk-blueviolet?style=flat&logo=slack&logoColor=white" alt="Slack"> </a> </div> """ )
with gr.Row(): with gr.Column(): image_input = gr.Image(type='pil') gr.Examples(['examples/1.jpg', 'examples/2.jpg', 'examples/3.jpg'], inputs=image_input) process_button = gr.Button("Process") with gr.Column(): with gr.TabItem("Image"): image_output = gr.Image(type="pil") with gr.TabItem("Json"): json_output = gr.JSON() process_button.click(process_image, inputs=[image_input], outputs=[image_output, json_output])
gr.HTML('<a href="https://visitorbadge.io/status?path=https%3A%2F%2Fhuggingface.co%2Fspaces%2Fopulentyn%2FLicensePlateRecognition"><img src="https://api.visitorbadge.io/api/combined?path=https%3A%2F%2Fhuggingface.co%2Fspaces%2Fopulentyn%2FLicensePlateRecognition&countColor=%23263759" /></a>')
demo.launch(server_name="0.0.0.0", server_port=7860)1234567891011#!/bin/bash
sudo cp lib/libopycardenv.so /usr/lib
sudo cp lib/libtensorflow.so.1.14.0 /usr/lib
sudo ln -s /usr/lib/libtensorflow.so.1.14.0 /usr/lib/libtensorflow.so.1
sudo ln -s /usr/lib/libtensorflow.so.1.14.0 /usr/lib/libtensorflow.so
sudo cp lib/libtensorflow_framework.so.1.14.0 /usr/lib
sudo ln -s /usr/lib/libtensorflow_framework.so.1.14.0 /usr/lib/libtensorflow_framework.so.1
sudo ln -s /usr/lib/libtensorflow_framework.so.1.14.0 /usr/lib/libtensorflow_framework.so
123version https://git-lfs.github.com/spec/v1oid sha256:7d05d12d34540dded22034918c37a1df0b0c5396a0e460f31292849e17c4a226size 3943952123version https://git-lfs.github.com/spec/v1oid sha256:055751c7691dcec4506658d96f02b17632759299534b4ddd2a47627d192b38d7size 216546752123version https://git-lfs.github.com/spec/v1oid sha256:b5648d27a4c58a5669d1d3d40326da9aaf414d443dfac7de273ecf3a28a97679size 347485201gHCbGlNYovccScwbo52dFL6rz9wsgcn0aG1M1TOIGp0yC4Bu3t0CjOzKC9/G5YYh8T1OtWdDVU0YUXNR6bLRJLxP2vd+suclRwzpDdVZ2J0Ab33boUdSJ+23idE9dSjWNMDO4cvaQj7zW7WAYixoMC01SBBTKOinhm7z/rrqyP8=123version https://git-lfs.github.com/spec/v1oid sha256:c5010fda486f4395d064447ef1c4a806be41c776896e76cb5d80f1f653e85bbcsize 13253378123version https://git-lfs.github.com/spec/v1oid sha256:fd5669349ef0ee0278a3444ae31057bf218f6c006699e517813100d3b5959340size 230123version https://git-lfs.github.com/spec/v1oid sha256:ea598067f0383fa8e0fb430528d38e4a1a855df8782e04813fbd4d23a31f4a26size 199123version https://git-lfs.github.com/spec/v1oid sha256:f9fb4e913f1c6b574bdeffb0cb498c6be838740548f4d4ef7874ad20a855700dsize 7907130123456789101112131415161718192021222324252627import os
from ctypes import *from numpy.ctypeslib import ndpointer
libPath = os.path.abspath(os.path.dirname(__file__)) + '/lib/libopycardenv.so'opycardenv = cdll.LoadLibrary(libPath)
libPath = os.path.abspath(os.path.dirname(__file__)) + '/lib/libopycard.so'opycard = cdll.LoadLibrary(libPath)
getHWID = opycard.getHWIDgetHWID.argtypes = []getHWID.restype = c_char_p
setLicenseKey = opycard.setLicenseKeysetLicenseKey.argtypes = [c_char_p]setLicenseKey.restype = c_int32
initSDK = opycard.initSDKinitSDK.argtypes = [c_char_p]initSDK.restype = c_int32
processImage = opycard.processImageprocessImage.argtypes = [ndpointer(c_ubyte, flags='C_CONTIGUOUS'), c_int32, c_int32]processImage.restype = c_char_p
1234flaskflask-corsgradiodatadog_api_client12345#!/bin/bash
cd /home/opycardexec python3 demo.py &exec python3 app.py.gitattributes+4
DockerfileAdded+23
app.pyAdded+131
arial.ttfAdded+3
demo.pyAdded+140
examples/1.jpgAdded

examples/2.jpgAdded

examples/3.jpgAdded

install.shAdded+11
lib/libopycard.soAdded
lib/libopycardenv.soAdded+3
lib/libtensorflow.so.1.14.0Added+3
lib/libtensorflow_framework.so.1.14.0Added+3
license.txtAdded+1
model/detect.binAdded+3
model/fp.binAdded+3
model/map.binAdded+3
model/recog.binAdded+3
opycard.pyAdded+27
requirements.txtAdded+4
run.shAdded+5