|
@@ -9,23 +9,20 @@ from infer import DoorInference
|
|
|
from logger import logger
|
|
|
|
|
|
async def upload_image(url, payload, filename1, content1, filename2, content2):
|
|
|
- try:
|
|
|
- form_data = aiohttp.FormData()
|
|
|
- # 添加普通表单数据
|
|
|
- for key, value in payload.items():
|
|
|
- form_data.add_field(key, value)
|
|
|
+ form_data = aiohttp.FormData()
|
|
|
+ # 添加普通表单数据
|
|
|
+ for key, value in payload.items():
|
|
|
+ form_data.add_field(key, value)
|
|
|
|
|
|
- # 添加文件数据
|
|
|
- form_data.add_field('file', content1, filename=filename1, content_type='image/jpeg')
|
|
|
- # form_data.add_field('oldFile', content2, filename=filename2, content_type='image/jpeg')
|
|
|
-
|
|
|
- # 发起 POST 请求
|
|
|
- async with aiohttp.ClientSession() as session:
|
|
|
- async with session.post(url, data=form_data) as response:
|
|
|
- result = await response.text()
|
|
|
- logger.info(result)
|
|
|
- except Exception as error:
|
|
|
- logger.error(f'Error: {str(error)}')
|
|
|
+ # 添加文件数据
|
|
|
+ form_data.add_field('file', content1, filename=filename1, content_type='image/jpeg')
|
|
|
+ # form_data.add_field('oldFile', content2, filename=filename2, content_type='image/jpeg')
|
|
|
+
|
|
|
+ # 发起 POST 请求
|
|
|
+ async with aiohttp.ClientSession() as session:
|
|
|
+ async with session.post(url, data=form_data) as response:
|
|
|
+ result = await response.text()
|
|
|
+ logger.info(result)
|
|
|
|
|
|
async def process_stream():
|
|
|
logger.info("====== Start Server =======")
|
|
@@ -46,40 +43,37 @@ async def process_stream():
|
|
|
|
|
|
result = instance(image)
|
|
|
if len(result) > 0 and time.time() - posttime > 30:
|
|
|
- try:
|
|
|
- posttime = time.time()
|
|
|
- videoTime = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
|
|
|
- fileTime = time.strftime('%Y-%m-%d-%H:%M:%S', time.localtime())
|
|
|
- filename = fileTime + ".jpg"
|
|
|
- filenameori = fileTime + "det.jpg"
|
|
|
- logger.info(videoTime)
|
|
|
- logger.info(result)
|
|
|
-
|
|
|
- for res in result:
|
|
|
- cv2.rectangle(image, tuple(map(int, (res.left, res.top))),
|
|
|
- tuple(map(int, (res.right, res.bottom))), (255, 0, 0), 4)
|
|
|
-
|
|
|
- success, encoded_image = cv2.imencode('.jpg', image)
|
|
|
- if not success:
|
|
|
- logger.error('imencode image error')
|
|
|
- content = encoded_image.tobytes()
|
|
|
- successori, encoded_imageori = cv2.imencode('.jpg', frame)
|
|
|
- if not successori:
|
|
|
- logger.error('imencode original image error')
|
|
|
- contentori = encoded_imageori.tobytes()
|
|
|
-
|
|
|
- payload = {
|
|
|
- 'channel': '45',
|
|
|
- 'classIndex': '8',
|
|
|
- 'ip': '172.19.152.231',
|
|
|
- 'videoTime': videoTime,
|
|
|
- 'videoUrl': stream.stream_url
|
|
|
- }
|
|
|
-
|
|
|
- # 使用协程上传图像
|
|
|
- await upload_image('http://172.19.152.231/open/api/operate/upload', payload, filename, content, filenameori, contentori)
|
|
|
- except Exception as error:
|
|
|
- logger.error(f'Error: {str(error)}')
|
|
|
+ posttime = time.time()
|
|
|
+ videoTime = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
|
|
|
+ fileTime = time.strftime('%Y-%m-%d-%H:%M:%S', time.localtime())
|
|
|
+ filename = fileTime + ".jpg"
|
|
|
+ filenameori = fileTime + "det.jpg"
|
|
|
+ logger.info(videoTime)
|
|
|
+ logger.info(result)
|
|
|
+
|
|
|
+ for res in result:
|
|
|
+ cv2.rectangle(image, tuple(map(int, (res.left, res.top))),
|
|
|
+ tuple(map(int, (res.right, res.bottom))), (255, 0, 0), 4)
|
|
|
+
|
|
|
+ success, encoded_image = cv2.imencode('.jpg', image)
|
|
|
+ if not success:
|
|
|
+ logger.error('imencode image error')
|
|
|
+ content = encoded_image.tobytes()
|
|
|
+ successori, encoded_imageori = cv2.imencode('.jpg', frame)
|
|
|
+ if not successori:
|
|
|
+ logger.error('imencode original image error')
|
|
|
+ contentori = encoded_imageori.tobytes()
|
|
|
+
|
|
|
+ payload = {
|
|
|
+ 'channel': '45',
|
|
|
+ 'classIndex': '8',
|
|
|
+ 'ip': '172.19.152.231',
|
|
|
+ 'videoTime': videoTime,
|
|
|
+ 'videoUrl': stream.stream_url
|
|
|
+ }
|
|
|
+
|
|
|
+ # 使用协程上传图像
|
|
|
+ await upload_image('http://172.19.152.231/open/api/operate/upload', payload, filename, content, filenameori, contentori)
|
|
|
|
|
|
logger.info("======= EXIT =======")
|
|
|
|