Mk1443 commited on
Commit
39efc7b
·
verified ·
1 Parent(s): f22f246

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -11
app.py CHANGED
@@ -9,7 +9,6 @@ import pandas as pd
9
  from calculations import measure_body_sizes
10
  import tf_bodypix
11
  from tf_bodypix.api import download_model, load_model, BodyPixModelPaths
12
- from tf_bodypix.draw import draw_poses
13
 
14
  # Load BodyPix model
15
  bodypix_model = load_model(download_model(BodyPixModelPaths.MOBILENET_FLOAT_50_STRIDE_16))
@@ -59,7 +58,7 @@ def capture_image_with_timer(label, person_height_cm, pixels_per_cm):
59
  ret, frame = cap.read()
60
  if not ret:
61
  print("Failed to capture frame.")
62
- break
63
  draw_bounding_box(frame, box_width, box_height)
64
  cv2.putText(frame, f"{label.capitalize()} pose: {i} seconds remaining", (10, 30),
65
  cv2.FONT_HERSHEY_SIMPLEX, 0.8, (0, 255, 255), 2)
@@ -78,6 +77,10 @@ def capture_image_with_timer(label, person_height_cm, pixels_per_cm):
78
  return final_frame
79
 
80
  def process_images(front_img, side_img, real_height_cm):
 
 
 
 
81
  front_image_array = preprocessing.image.img_to_array(front_img)
82
  side_image_array = preprocessing.image.img_to_array(side_img)
83
 
@@ -93,8 +96,9 @@ def process_images(front_img, side_img, real_height_cm):
93
  front_poses = front_result.get_poses()
94
  side_poses = side_result.get_poses()
95
 
96
- body_sizes = measure_body_sizes(side_colored_mask, front_colored_mask, side_poses, front_poses, real_height_cm)
97
- measurements_df = pd.DataFrame([body_sizes[0]])
 
98
  return measurements_df
99
 
100
  def gradio_interface(person_height_cm):
@@ -103,13 +107,10 @@ def gradio_interface(person_height_cm):
103
  front_frame = capture_image_with_timer("front", person_height_cm, pixels_per_cm)
104
  side_frame = capture_image_with_timer("side", person_height_cm, pixels_per_cm)
105
 
106
- front_img_path = os.path.join(output_dir, "front_image.jpg")
107
- side_img_path = os.path.join(output_dir, "side_image.jpg")
108
-
109
- front_img = cv2.imread(front_img_path)
110
- side_img = cv2.imread(side_img_path)
111
 
112
- measurements_df = process_images(front_img, side_img, person_height_cm)
113
  return measurements_df
114
 
115
  def main():
@@ -123,4 +124,4 @@ def main():
123
  demo.launch()
124
 
125
  if __name__ == "__main__":
126
- main()
 
9
  from calculations import measure_body_sizes
10
  import tf_bodypix
11
  from tf_bodypix.api import download_model, load_model, BodyPixModelPaths
 
12
 
13
  # Load BodyPix model
14
  bodypix_model = load_model(download_model(BodyPixModelPaths.MOBILENET_FLOAT_50_STRIDE_16))
 
58
  ret, frame = cap.read()
59
  if not ret:
60
  print("Failed to capture frame.")
61
+ return None
62
  draw_bounding_box(frame, box_width, box_height)
63
  cv2.putText(frame, f"{label.capitalize()} pose: {i} seconds remaining", (10, 30),
64
  cv2.FONT_HERSHEY_SIMPLEX, 0.8, (0, 255, 255), 2)
 
77
  return final_frame
78
 
79
  def process_images(front_img, side_img, real_height_cm):
80
+ # Ensure images are not None
81
+ if front_img is None or side_img is None:
82
+ raise ValueError("Front or side image is None")
83
+
84
  front_image_array = preprocessing.image.img_to_array(front_img)
85
  side_image_array = preprocessing.image.img_to_array(side_img)
86
 
 
96
  front_poses = front_result.get_poses()
97
  side_poses = side_result.get_poses()
98
 
99
+ # Added a placeholder for the rainbow parameter
100
+ body_sizes = measure_body_sizes(side_colored_mask, front_colored_mask, side_poses, front_poses, real_height_cm, rainbow=None)
101
+ measurements_df = pd.DataFrame(body_sizes)
102
  return measurements_df
103
 
104
  def gradio_interface(person_height_cm):
 
107
  front_frame = capture_image_with_timer("front", person_height_cm, pixels_per_cm)
108
  side_frame = capture_image_with_timer("side", person_height_cm, pixels_per_cm)
109
 
110
+ if front_frame is None or side_frame is None:
111
+ return pd.DataFrame() # Return empty DataFrame if image capture fails
 
 
 
112
 
113
+ measurements_df = process_images(front_frame, side_frame, person_height_cm)
114
  return measurements_df
115
 
116
  def main():
 
124
  demo.launch()
125
 
126
  if __name__ == "__main__":
127
+ main()