From 9fe61de82c1a555d4b0e4aa841f0361f64ae440c Mon Sep 17 00:00:00 2001
From: JianHe0628 <jl02958@surrey.ac.uk>
Date: Wed, 29 Jan 2025 17:42:07 +0000
Subject: [PATCH] Updating code for CSLdaily

---
 Extract_HaMeR_Single.py | 13 +++++++++----
 Inject_Json.py          | 16 ++++++++--------
 2 files changed, 17 insertions(+), 12 deletions(-)

diff --git a/Extract_HaMeR_Single.py b/Extract_HaMeR_Single.py
index a10f7c8..95f7ca8 100644
--- a/Extract_HaMeR_Single.py
+++ b/Extract_HaMeR_Single.py
@@ -118,7 +118,7 @@ def main(args, model, renderer, device):
         img_paths = [img for end in args.file_type for img in image_folder.glob(end)]
 
         #VideoFile Specific
-        img_paths = sorted(img_paths,key = lambda x: int(os.path.basename(x).removesuffix('.png').removeprefix('Frame')))
+        img_paths = sorted(img_paths,key = lambda x: int(os.path.basename(x).removesuffix('.png').removesuffix('.jpg').removeprefix('Frame')))
 
         # #For Phoenix
         # img_paths = sorted(img_paths,key = lambda x: int(os.path.basename(x).removeprefix('images').removesuffix('.png')))  
@@ -144,6 +144,9 @@ def main(args, model, renderer, device):
             else:
                 print("No humans detected in the image")
                 return
+            print(f"Using detected bbox, {pred_bboxes[0]}")
+
+            
         else:
             # Hardcoded bbox. This assumes person is in the center and that there is always one person in the image
             if args.custom_bbox == '':
@@ -156,7 +159,7 @@ def main(args, model, renderer, device):
                 
             # Force confidence to be 0.99 that human is present
             pred_scores = np.array([0.99])
-        
+        # show_bbox(img_cv2, pred_bboxes)
         # keypoint detector
         cpm = ViTPoseModel(device)
         print('Loading ViTPose Model')
@@ -301,8 +304,10 @@ if __name__ == '__main__':
     args = parser.parse_args()
 
     args.bbox = 'False'
-    args.custom_bbox = '70,0,550,360'
-    args.out_folder = os.path.join(args.out_folder, os.path.dirname(args.vid).removeprefix('/vol/vssp/LF_datasets/multiview/bslcp/BSLCP/'))
+    args.custom_bbox = '0,60,512,512'
+    # args.img_folder = '/vol/vssp/datasets/singlevideo/csldaily/sentences/frames_512x512/S000000_P0000_T00'
+    # args.out_folder = '/vol/research/signVision/Projects/BSLboundaries/Testing'
+    args.out_folder = os.path.join(args.out_folder, os.path.basename(args.img_folder))
     print(f"Output folder: {args.out_folder}")
     
     model, model_cfg = load_hamer(args.checkpoint, load_mesh=False) # False sets model to not produce vertice on inference
diff --git a/Inject_Json.py b/Inject_Json.py
index 27a55aa..fad14e1 100644
--- a/Inject_Json.py
+++ b/Inject_Json.py
@@ -138,7 +138,7 @@ def main(args, model, device):
     img_paths = [img for end in args.file_type for img in image_folder.glob(end)]
 
     # For General Video
-    img_paths = sorted(img_paths,key = lambda x: int(os.path.basename(x).removesuffix('.png').removeprefix('Frame')))
+    img_paths = sorted(img_paths,key = lambda x: int(os.path.basename(x).removesuffix('.png').removesuffix('.jpg').removeprefix('Frame')))
     # #For Phoenix
     # img_paths = sorted(img_paths,key = lambda x: int(os.path.basename(x).removeprefix('images').removesuffix('.png')))  
     assert len(img_paths) == len(hand_pose_list), f"Number of images {len(img_paths)} and lmdb files {len(hand_pose_list)} do not match"
@@ -172,6 +172,7 @@ def main(args, model, device):
         else:
             print("No humans detected in the first frame. Exiting...")
             return
+        
     else:
         # Hardcoded bbox. This assumes person is in the center and that there is always one person in the image
         if args.custom_bbox == '':
@@ -351,15 +352,14 @@ if __name__ == '__main__':
     args = parser.parse_args()
     
 
-    Filename = 'BUSINESS_GROUP_AND_SET-UP_SPIN-OFF_PARTNER-RELATIONSHIP'
+    args.img_folder = '/vol/vssp/datasets/singlevideo/csldaily/sentences/frames_512x512/S000000_P0000_T00'
     
-    args.vid = f'/vol/vssp/LF_datasets/multiview/bslcp/BSLCP/Videos/Narratives/Belfast/17+18/BF17n.mov'
-    args.lmdb_input = f'/mnt/fast/nobackup/scratch4weeks/jl02958/BSLCorpus/Videos/Narratives/Belfast/17+18/BF17n.lmdb'
-    args.out_folder = f'/vol/research/signVision/Projects/BSLboundaries/Test/BF17n'
-    args.frame_range = '30,400'
+    args.lmdb_input = f'/vol/research/signVision/Projects/BSLboundaries/Test/S000000_P0000_T00/S000000_P0000_T00.lmdb'
+    args.out_folder = f'/vol/research/signVision/Projects/BSLboundaries/Test/Check_S000000_P0000_T00'
+    args.frame_range = '0,50'
     args.bbox = False
-    args.custom_bbox = '70,0,550,360'
-    args.save_mesh = False
+    args.custom_bbox = '0,60,512,512'
+    args.save_mesh = True
 
     # Download and load checkpoints
     # download_models(CACHE_DIR_HAMER)
-- 
GitLab