添加注释
This commit is contained in:
		
							
								
								
									
										43
									
								
								main.py
									
									
									
									
									
								
							
							
						
						
									
										43
									
								
								main.py
									
									
									
									
									
								
							| @@ -1,6 +1,4 @@ | |||||||
| # -*- coding: UTF-8 -*- | # -*- coding: UTF-8 -*- | ||||||
| from flask import Flask, request, jsonify |  | ||||||
| from PIL import Image |  | ||||||
| import io | import io | ||||||
| import base64 | import base64 | ||||||
| import time | import time | ||||||
| @@ -9,6 +7,7 @@ import os | |||||||
| import cv2 | import cv2 | ||||||
| import torch | import torch | ||||||
| import torch.backends.cudnn as cudnn | import torch.backends.cudnn as cudnn | ||||||
|  | import requests | ||||||
| from numpy import random | from numpy import random | ||||||
| import copy | import copy | ||||||
| import numpy as np | 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_rec import get_plate_result, allFilePath, init_model, cv_imread | ||||||
| # from plate_recognition.plate_cls import cv_imread | # from plate_recognition.plate_cls import cv_imread | ||||||
| from plate_recognition.double_plate_split_merge import get_split_merge | 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)] | clors = [(255, 0, 0), (0, 255, 0), (0, 0, 255), (255, 255, 0), (0, 255, 255)] | ||||||
| danger = ['危', '险'] | danger = ['危', '险'] | ||||||
| @@ -251,6 +251,7 @@ def get_second(capture): | |||||||
|         duration = FrameNumber / rate  # 帧速率/视频总帧数 是时间,除以60之后单位是分钟 |         duration = FrameNumber / rate  # 帧速率/视频总帧数 是时间,除以60之后单位是分钟 | ||||||
|         return int(rate), int(FrameNumber), int(duration) |         return int(rate), int(FrameNumber), int(duration) | ||||||
|  |  | ||||||
|  |  | ||||||
| def process_images(detect_model_path, rec_model_path, is_color, img, img_size, output, video_path): | 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") |     device = torch.device("cuda" if torch.cuda.is_available() else "cpu") | ||||||
|  |  | ||||||
| @@ -267,7 +268,7 @@ def process_images(detect_model_path, rec_model_path, is_color, img, img_size, o | |||||||
|     if img.shape[-1] == 4: |     if img.shape[-1] == 4: | ||||||
|         img = cv2.cvtColor(img, cv2.COLOR_BGRA2BGR) |         img = cv2.cvtColor(img, cv2.COLOR_BGRA2BGR) | ||||||
|     dict_list, result_jpg = detect_Recognition_plate(detect_model, img, device, plate_rec_model, img_size, |     dict_list, result_jpg = detect_Recognition_plate(detect_model, img, device, plate_rec_model, img_size, | ||||||
|                                          is_color=is_color) |                                                      is_color=is_color) | ||||||
|     # ori_img = draw_result(img, dict_list) |     # ori_img = draw_result(img, dict_list) | ||||||
|     # ori_list=ori_img[0].tolist() |     # ori_list=ori_img[0].tolist() | ||||||
|     # result_jpg.insert(0,ori_list) |     # result_jpg.insert(0,ori_list) | ||||||
| @@ -275,7 +276,26 @@ def process_images(detect_model_path, rec_model_path, is_color, img, img_size, o | |||||||
|     return result_jpg |     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__) | app = Flask(__name__) | ||||||
|  |  | ||||||
|  |  | ||||||
| def base64_to_image(base64_str): | def base64_to_image(base64_str): | ||||||
|     # 去掉base64编码中的头部信息 |     # 去掉base64编码中的头部信息 | ||||||
|     base64_str = base64_str.split(",")[-1] |     base64_str = base64_str.split(",")[-1] | ||||||
| @@ -287,8 +307,10 @@ def base64_to_image(base64_str): | |||||||
|     image = cv2.imdecode(nparr, cv2.IMREAD_COLOR) |     image = cv2.imdecode(nparr, cv2.IMREAD_COLOR) | ||||||
|     return image |     return image | ||||||
|  |  | ||||||
|  |  | ||||||
| @app.route('/upload', methods=['POST']) | @app.route('/upload', methods=['POST']) | ||||||
| def upload_image(): | def upload_image(): | ||||||
|  |     # return "sadkjfhdskjhgfkj" | ||||||
|     try: |     try: | ||||||
|         # 从请求中获取base64编码的图片数据 |         # 从请求中获取base64编码的图片数据 | ||||||
|         data = request.json |         data = request.json | ||||||
| @@ -343,7 +365,14 @@ def upload_image(): | |||||||
|                         "error_code": "AIS.0404"}) |                         "error_code": "AIS.0404"}) | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
| if __name__ == '__main__': | 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!!!!!!!") | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user