Bladeren bron

使用协程上传图片

leon 3 weken geleden
bovenliggende
commit
817caaf6d8
2 gewijzigde bestanden met toevoegingen van 9 en 60 verwijderingen
  1. 8 7
      Makefile
  2. 1 53
      infer.py

+ 8 - 7
Makefile

@@ -1,17 +1,17 @@
 start:
-	nohup python3 infer.py > /dev/null 2>&1 &
+	nohup python3 main.py > /dev/null 2>&1 &
 	@sleep 1s
-	@ps -ef | grep infer.py | grep -v grep || true
+	@ps -ef | grep main.py | grep -v grep || true
 
 debug:
-	@python3 infer.py
+	@python3 main.py
 
 status:
-	@ps -ef | grep infer.py | grep -v grep || true
+	@ps -ef | grep main.py | grep -v grep || true
 
 stop:
-	@ps -ef | grep infer.py | grep -v grep | awk '{print $$2}' | xargs kill || true
-	@ps -ef | grep infer.py | grep -v grep || true
+	@ps -ef | grep main.py | grep -v grep | awk '{print $$2}' | xargs kill || true
+	@ps -ef | grep main.py | grep -v grep || true
 
 log:
 	@tail -f log/runtime.log
@@ -24,8 +24,9 @@ help:
 	@echo ""
 	@echo "make start      Start server"
 	@echo "make status     Check server status"
-	@echo "make debug      Execute python3 infer.py"
+	@echo "make debug      Execute python3 main.py"
 	@echo "make stop       Kill server"
+	@echo "make test       Test local image"
 	@echo "make log        Print log"
 	@echo "make help       Show this help message"
 	@echo ""

+ 1 - 53
infer.py

@@ -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