123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- import cv2
- import os
- from processor import Detector
- def c_main(path, model, ext) -> tuple:
- ''' 主函数,返回图片的路径和图片的信息
- Args: path: 图片的路径
- model: 模型
- ext: 图片的后缀名
- Return: tuple: (图片的路径, 图片的信息)
- '''
- image_data = pre_process(path)
- image_info = predict.predict(image_data, model, ext)
- return image_data[1] + '.' + ext, image_info
- def pre_process(data_path):
- ''' 路径预处理
-
- 从data_path中提取文件名,去除文件后缀
-
- Args: data_path: 图片的路径
- Return: tuple: (图片的路径, 图片的信息)
- '''
- file_name = os.path.split(data_path)[1].split('.')[0]
- return data_path, file_name
- def predict(dataset, model :Detector, ext):
- ''' 预测,保存到服务器本地临时的目录
-
- Args: dataset: tuple: (图片的路径, 图片的信息)
- model: 模型
- ext: 图片的后缀名
- Return: tuple: (图片的路径, 图片的信息)
- '''
- global img_y
- x = dataset[0].replace('\\', '/')
- file_name = dataset[1]
- print(x)
- print(file_name)
- x = cv2.imread(x)
- img_y, image_info = model.detect(x)
- if cv2.imwrite('./tmp/draw/{}.{}'.format(file_name, ext), img_y):
- raise Exception('保存图片时出错.Error saving thepicture.')
- return image_info
|