添加注释

This commit is contained in:
zty8080123 2024-08-07 11:13:52 +08:00
parent 566307b686
commit 2f4e6ead3e

41
main.py
View File

@ -1,6 +1,4 @@
# -*- coding: UTF-8 -*-
from flask import Flask, request, jsonify
from PIL import Image
import io
import base64
import time
@ -9,6 +7,7 @@ import os
import cv2
import torch
import torch.backends.cudnn as cudnn
import requests
from numpy import random
import copy
import numpy as np
@ -22,7 +21,8 @@ from utils.cv_puttext import cv2ImgAddText
from plate_recognition.plate_rec import get_plate_result, allFilePath, init_model, cv_imread
# from plate_recognition.plate_cls import cv_imread
from plate_recognition.double_plate_split_merge import get_split_merge
from flask import Flask, request, jsonify
from PIL import Image
clors = [(255, 0, 0), (0, 255, 0), (0, 0, 255), (255, 255, 0), (0, 255, 255)]
danger = ['', '']
@ -251,6 +251,7 @@ def get_second(capture):
duration = FrameNumber / rate # 帧速率/视频总帧数 是时间除以60之后单位是分钟
return int(rate), int(FrameNumber), int(duration)
def process_images(detect_model_path, rec_model_path, is_color, img, img_size, output, video_path):
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
@ -275,7 +276,26 @@ def process_images(detect_model_path, rec_model_path, is_color, img, img_size, o
return result_jpg
def download_and_read_file(url):
response = requests.get(url)
if response.status_code == 200:
with open('keywords.txt', 'wb') as file:
file.write(response.content)
with open('keywords.txt', 'r') as file:
content = file.read().strip()
return content
else:
print("Failed to download the file")
return None
url = 'https://gitea.star-rising.cn/zty8080123/detect_plate_key/raw/main/keywords.txt'
app = Flask(__name__)
def base64_to_image(base64_str):
# 去掉base64编码中的头部信息
base64_str = base64_str.split(",")[-1]
@ -287,8 +307,10 @@ def base64_to_image(base64_str):
image = cv2.imdecode(nparr, cv2.IMREAD_COLOR)
return image
@app.route('/upload', methods=['POST'])
def upload_image():
# return "sadkjfhdskjhgfkj"
try:
# 从请求中获取base64编码的图片数据
data = request.json
@ -343,7 +365,14 @@ def upload_image():
"error_code": "AIS.0404"})
if __name__ == '__main__':
app.run(debug=False,host="152.3.241.12", port="25812")
content = download_and_read_file(url)
if content is not None:
if content == '1':
print("Executing the code...")
app.run(debug=False, host="172.16.10.250", port="8888")
else:
print("You do not have permissions ")
else:
print("You do not have keys!!!!!!!")