瀏覽代碼

update backend

dongyuanjushi 4 年之前
父節點
當前提交
ce4d14df57
共有 3 個文件被更改,包括 24 次插入25 次删除
  1. 13 19
      backend/demo_func.py
  2. 9 5
      backend/flask_api.py
  3. 2 1
      backend/video_to_photo.py

+ 13 - 19
backend/demo_func.py

@@ -109,45 +109,39 @@ def run_openpose_for_image_side(index):
     # plt.show()
 
 
-def run_openpose_for_normal(index):
+def run_openpose_for_normal(index,name):
     print(index)
-
+    
     # 输入index和原来一样,就是序号,你可以更改一下输入或者输出,方便你们处理
 
     # 判断是否是PNG格式,如果是,增添对alpha通道的处理
     PNG_OR_NOT = True
     # 调用的模型路径,无需更改
-    # 原图像的位置,需要更改 !!
-    test_image = './capture_image/capture_image{}.png'.format(index)
+    body_estimation = Body('model/body_pose_model.pth')
+    #原图像的位置,需要更改 !!
+    p='./capture_image/'+name
+    test_image = p+'/capture_image{}.png'.format(index)
     if os.path.exists(test_image) is False:
         PNG_OR_NOT = False
         # 原图像的位置,需要更改 !!
-        test_image = './capture_image/capture_image{}.jpg'.format(index)
+        test_image = p+'/capture_image{}.jpg'.format(index)
     oriImg = cv2.imread(test_image)  # B,G,R order
     im = cv2.imread(test_image, cv2.IMREAD_UNCHANGED)
 
-    # --- for openpose ---
-    body_estimation = Body('model/body_pose_model.pth')
     candidate, subset = body_estimation(oriImg)
-
-    # --- for detectron ---
-    # predictor = load_predictor()
-    # candidate, subset = infer_image(oriImg, predictor)
-
     # 坐标点数值保存路径,需要更改!!
-    np.save('./capture_image/capture_image{}-1.png'.format(index), candidate)
-    print('./capture_image/capture_image{}.png'.format(index))
+    np.save(p+'/capture_image{}-1.png'.format(index), candidate)
+    print(p+'/capture_image{}.png'.format(index))
 
     # 处理
     canvas = copy.deepcopy(oriImg)
     canvas = util.draw_bodypose(canvas, candidate, subset)
-    # if PNG_OR_NOT == True:
-    # alpha_value_new = np.reshape(im[:,:,3],(im.shape[0],im.shape[1],1))
-    # canvas = np.c_[canvas, alpha_value_new]
+    #if PNG_OR_NOT == True:
+        #alpha_value_new = np.reshape(im[:,:,3],(im.shape[0],im.shape[1],1))
+        #canvas = np.c_[canvas, alpha_value_new]
 
     # 结果图片的保存路径,需要更改 !!
-    cv2.imwrite('./capture_image/capture_image_result{}.png'.format(index), canvas,
-                [int(cv2.IMWRITE_PNG_COMPRESSION), 9])
+    cv2.imwrite(p+'/capture_image_result{}.png'.format(index), canvas, [int(cv2.IMWRITE_PNG_COMPRESSION), 9])
 
 
 if __name__ == '__main__':

+ 9 - 5
backend/flask_api.py

@@ -242,7 +242,9 @@ def get_video_data():
     dict_video_ = request.form.to_dict()
     global global_video_index
     global_video_index = int(dict_video_["id"])
+    # print(global_video_index)
     mode = str(lookup_data(global_video_index))  # get database mode
+    # print(mode)
     re = run_video(mode, global_video_index, 1)
     return re
 
@@ -264,7 +266,9 @@ def query_video():
     print(dict_video_)
     global global_video_index
     global_video_index = int(dict_video_["id"])
-    print(global_video_index)
+    if get_status(global_video_index) == 0:
+        mode = str(lookup_data(global_video_index))  # get database mode
+        run_video(mode, global_video_index, 1)
     return lookup_video(global_video_index, 0)
 
 
@@ -343,8 +347,8 @@ if __name__ == '__main__':
     # print(list_to_json(li_return))
 
     # app.run()
-    app.run(host="0.0.0.0", port=8090, debug=True)
-    # app.run(host="0.0.0.0", port=8090)
+    # app.run(host="0.0.0.0", port=8090, debug=True)
+    app.run(host="0.0.0.0", port=8090)
     CORS(app, resouces=r'/*')
-    # run_video("gaotaitui",27,0)
-    lookup_video(41, 0)
+    # run_video("gaotaitui",19,1)
+    # lookup_video(41, 0)

+ 2 - 1
backend/video_to_photo.py

@@ -42,11 +42,12 @@ def split_video(path):
     cap.release()
     return c
 
-def process_photo(name,c=334):
+def process_photo(name,c):
     print(name)
     for i in range(1,c):
         run_openpose_for_normal(i,name)
 
+
 def gather_video(path):
     video_path = path