|
|
@ -16,7 +16,7 @@ mp_pose = mp.solutions.pose |
|
|
class HPEModule(IHPEModule): |
|
|
class HPEModule(IHPEModule): |
|
|
|
|
|
|
|
|
# This method starts HPE using a camera specified by its name |
|
|
# This method starts HPE using a camera specified by its name |
|
|
def startHPEwithCamera(self, camera_name): |
|
|
def startHPEwithCamera(self, camera_name, export_landmarks): |
|
|
out = None |
|
|
out = None |
|
|
# check if the camera_name is a file path or not |
|
|
# check if the camera_name is a file path or not |
|
|
if os.path.isfile(camera_name): |
|
|
if os.path.isfile(camera_name): |
|
|
@ -39,15 +39,17 @@ class HPEModule(IHPEModule): |
|
|
|
|
|
|
|
|
# set the window name using the camera name |
|
|
# set the window name using the camera name |
|
|
window_name = f"Pose Estimation on Camera {camera_name}" |
|
|
window_name = f"Pose Estimation on Camera {camera_name}" |
|
|
|
|
|
print(export_landmarks.get()) |
|
|
|
|
|
if export_landmarks.get() is True: |
|
|
|
|
|
# create the root element |
|
|
|
|
|
root = ET.Element("Landmarks") |
|
|
|
|
|
|
|
|
# create the root element |
|
|
# loop through each landmark |
|
|
root = ET.Element("Landmarks") |
|
|
for i in range(33): |
|
|
|
|
|
ET.SubElement(root, f'landmark{i}') |
|
|
|
|
|
|
|
|
# loop through each landmark |
|
|
framecounter = 0 |
|
|
for i in range(33): |
|
|
|
|
|
ET.SubElement(root, f'landmark{i}') |
|
|
|
|
|
|
|
|
|
|
|
framecounter = 0 |
|
|
|
|
|
|
|
|
|
|
|
# start pose detection |
|
|
# start pose detection |
|
|
with mp_pose.Pose(min_detection_confidence=0.5, min_tracking_confidence=0.5) as pose: |
|
|
with mp_pose.Pose(min_detection_confidence=0.5, min_tracking_confidence=0.5) as pose: |
|
|
@ -75,12 +77,13 @@ class HPEModule(IHPEModule): |
|
|
# Extract landmarks |
|
|
# Extract landmarks |
|
|
try: |
|
|
try: |
|
|
landmarks = results.pose_landmarks.landmark |
|
|
landmarks = results.pose_landmarks.landmark |
|
|
for j, landmark in enumerate(landmarks): |
|
|
if export_landmarks.get() is True: |
|
|
frame_element = ET.SubElement(root.find(f'landmark{j}'), f'frame{framecounter}') |
|
|
for j, landmark in enumerate(landmarks): |
|
|
frame_element.set("X", str(landmark.x)) |
|
|
frame_element = ET.SubElement(root.find(f'landmark{j}'), f'frame{framecounter}') |
|
|
frame_element.set("Y", str(landmark.y)) |
|
|
frame_element.set("X", str(landmark.x)) |
|
|
frame_element.set("Z", str(landmark.z)) |
|
|
frame_element.set("Y", str(landmark.y)) |
|
|
framecounter += 1 |
|
|
frame_element.set("Z", str(landmark.z)) |
|
|
|
|
|
framecounter += 1 |
|
|
# print(landmarks) |
|
|
# print(landmarks) |
|
|
except: |
|
|
except: |
|
|
pass |
|
|
pass |
|
|
@ -100,8 +103,9 @@ class HPEModule(IHPEModule): |
|
|
if cv2.getWindowProperty(window_name, cv2.WND_PROP_VISIBLE) < 1: |
|
|
if cv2.getWindowProperty(window_name, cv2.WND_PROP_VISIBLE) < 1: |
|
|
break |
|
|
break |
|
|
|
|
|
|
|
|
xml_string = ET.tostring(root, encoding="UTF-8") |
|
|
if export_landmarks.get() is True: |
|
|
parsed_xml = minidom.parseString(xml_string) |
|
|
xml_string = ET.tostring(root, encoding="UTF-8") |
|
|
pretty_xml_string = parsed_xml.toprettyxml(indent=" ") |
|
|
parsed_xml = minidom.parseString(xml_string) |
|
|
with open(f"{camera_name}_output.xml", "w") as xml_file: |
|
|
pretty_xml_string = parsed_xml.toprettyxml(indent=" ") |
|
|
xml_file.write(pretty_xml_string) |
|
|
with open(f"{camera_name}_output.xml", "w") as xml_file: |
|
|
|
|
|
xml_file.write(pretty_xml_string) |
|
|
|