|
@@ -220,56 +220,4 @@ class DoorInference(object):
|
|
|
left, top ,right, bottom = self.rect(person["box"])
|
|
|
conf = person["conf"]
|
|
|
result.append(Box(left=left, top=top, right=right, bottom=bottom, confidence=conf, label="person"))
|
|
|
- return result
|
|
|
-
|
|
|
-
|
|
|
-if __name__ == "__main__":
|
|
|
- logger.info("====== Start Server =======")
|
|
|
- human_model_path = "models/work_clo_person_head_hat.pt"
|
|
|
- door_model_path = "models/door_classify.pt"
|
|
|
- #image_path = "images/camera1_9ce1aca78db14c5807a271cb154fed5b.jpg"
|
|
|
- #image = cv2.imread(image_path)
|
|
|
- # logger.info(video)
|
|
|
- # (222, 59), (432, 3), (528, 96), (318, 198) 这个区域是为了测试,画大了的
|
|
|
- test_area = [[(222, 59), (432, 3), (528, 96), (318, 198)]]
|
|
|
- instance = DoorInference(human_model_path, door_model_path, person_areas=None)
|
|
|
- # 返回需要门和人
|
|
|
- ip = '172.19.152.231'
|
|
|
- channel = '45'
|
|
|
- stream = StreamCapture(ip, channel)
|
|
|
- posttime = time.time() - 30
|
|
|
- for frame, ret in stream():
|
|
|
- if not ret:continue
|
|
|
- image = frame.copy()
|
|
|
- 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)
|
|
|
- content = encoded_image.tobytes()
|
|
|
- successori, encoded_imageori = cv2.imencode('.jpg',frame)
|
|
|
- contentori = encoded_imageori.tobytes()
|
|
|
- payload = {'channel': '45',
|
|
|
- 'classIndex': '8',
|
|
|
- 'ip': '172.19.152.231',
|
|
|
- 'videoTime': videoTime,
|
|
|
- 'videoUrl': stream.stream_url}
|
|
|
- files = [
|
|
|
- ('file', (filename, content, 'image/jpeg')),
|
|
|
- ('oldFile', (filenameori, contentori, 'image/jpeg')),
|
|
|
- ]
|
|
|
-
|
|
|
- result = requests.post('http://172.19.152.231/open/api/operate/upload', data=payload, files=files)
|
|
|
- logger.info(result)
|
|
|
- except Exception as error:
|
|
|
- logger.error('Error : ', str(error))
|
|
|
- logger.info("======= EXIT =======")
|
|
|
- #cv2.imwrite("result/result.jpg", image)
|
|
|
+ return result
|