refactor: add missing interpolators for the string in logging
This commit is contained in:
parent
7ffdaaca26
commit
5c4136cf6b
68
landmarks.py
68
landmarks.py
@ -1,9 +1,7 @@
|
|||||||
import warnings
|
import warnings
|
||||||
import os
|
import os
|
||||||
|
|
||||||
warnings.filterwarnings("ignore",
|
warnings.filterwarnings("ignore", category=UserWarning, module="google.protobuf")
|
||||||
category=UserWarning,
|
|
||||||
module="google.protobuf")
|
|
||||||
|
|
||||||
os.environ["TF_CPP_MIN_LOG_LEVEL"] = "3"
|
os.environ["TF_CPP_MIN_LOG_LEVEL"] = "3"
|
||||||
|
|
||||||
@ -30,9 +28,11 @@ class Landmarker:
|
|||||||
self.side_image = cv2.imread(args.side_image)
|
self.side_image = cv2.imread(args.side_image)
|
||||||
|
|
||||||
self.front_image_resized = cv2.resize(
|
self.front_image_resized = cv2.resize(
|
||||||
self.front_image, (self.resized_height, self.resized_width))
|
self.front_image, (self.resized_height, self.resized_width)
|
||||||
|
)
|
||||||
self.side_image_resized = cv2.resize(
|
self.side_image_resized = cv2.resize(
|
||||||
self.side_image, (self.resized_height, self.resized_width))
|
self.side_image, (self.resized_height, self.resized_width)
|
||||||
|
)
|
||||||
|
|
||||||
self.person_height = args.person_height
|
self.person_height = args.person_height
|
||||||
self.pixel_height = args.pixel_height
|
self.pixel_height = args.pixel_height
|
||||||
@ -60,14 +60,8 @@ class Landmarker:
|
|||||||
|
|
||||||
def parse_args(self):
|
def parse_args(self):
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument("--front",
|
parser.add_argument("--front", dest="front_image", type=str, help="Front image")
|
||||||
dest="front_image",
|
parser.add_argument("--side", dest="side_image", type=str, help="Side image")
|
||||||
type=str,
|
|
||||||
help="Front image")
|
|
||||||
parser.add_argument("--side",
|
|
||||||
dest="side_image",
|
|
||||||
type=str,
|
|
||||||
help="Side image")
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--pose_detection_confidence",
|
"--pose_detection_confidence",
|
||||||
dest="pose_detection_confidence",
|
dest="pose_detection_confidence",
|
||||||
@ -100,9 +94,9 @@ class Landmarker:
|
|||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
|
|
||||||
logging.warning("person's height: ", self.person_height)
|
logging.warning("person's height: %s", self.person_height)
|
||||||
|
|
||||||
logging.warning("person's pixel height: ", self.pixel_height)
|
logging.warning("person's pixel height: %s", self.pixel_height)
|
||||||
|
|
||||||
front_results = self.process_images()
|
front_results = self.process_images()
|
||||||
|
|
||||||
@ -118,9 +112,11 @@ class Landmarker:
|
|||||||
|
|
||||||
def process_images(self):
|
def process_images(self):
|
||||||
front_results = self.pose.process(
|
front_results = self.pose.process(
|
||||||
cv2.cvtColor(self.front_image_resized, cv2.COLOR_BGR2RGB))
|
cv2.cvtColor(self.front_image_resized, cv2.COLOR_BGR2RGB)
|
||||||
|
)
|
||||||
side_results = self.pose.process(
|
side_results = self.pose.process(
|
||||||
cv2.cvtColor(self.side_image_resized, cv2.COLOR_BGR2RGB))
|
cv2.cvtColor(self.side_image_resized, cv2.COLOR_BGR2RGB)
|
||||||
|
)
|
||||||
|
|
||||||
self.side_image_keypoints = self.side_image_resized.copy()
|
self.side_image_keypoints = self.side_image_resized.copy()
|
||||||
self.front_image_keypoints = self.front_image_resized.copy()
|
self.front_image_keypoints = self.front_image_resized.copy()
|
||||||
@ -153,7 +149,7 @@ class Landmarker:
|
|||||||
def pixel_to_metric_ratio(self):
|
def pixel_to_metric_ratio(self):
|
||||||
self.pixel_height = self.pixel_distance * 2
|
self.pixel_height = self.pixel_distance * 2
|
||||||
pixel_to_metric_ratio = self.person_height / self.pixel_height
|
pixel_to_metric_ratio = self.person_height / self.pixel_height
|
||||||
logging.warning("pixel_to_metric_ratio", pixel_to_metric_ratio)
|
logging.warning("pixel_to_metric_ratio %s", pixel_to_metric_ratio)
|
||||||
return pixel_to_metric_ratio
|
return pixel_to_metric_ratio
|
||||||
|
|
||||||
def draw_landmarks(self, image, landmarks, indices):
|
def draw_landmarks(self, image, landmarks, indices):
|
||||||
@ -200,17 +196,13 @@ class Landmarker:
|
|||||||
knee_left = landmarks[pose.PoseLandmark.LEFT_KNEE.value]
|
knee_left = landmarks[pose.PoseLandmark.LEFT_KNEE.value]
|
||||||
ankle_left = landmarks[pose.PoseLandmark.LEFT_ANKLE.value]
|
ankle_left = landmarks[pose.PoseLandmark.LEFT_ANKLE.value]
|
||||||
|
|
||||||
self.distance_left_hand_up = self.calculate_distance(
|
self.distance_left_hand_up = self.calculate_distance(shoulder_left, elbow_left)
|
||||||
shoulder_left, elbow_left)
|
|
||||||
|
|
||||||
self.distance_left_hand_down = self.calculate_distance(
|
self.distance_left_hand_down = self.calculate_distance(elbow_left, wrist_left)
|
||||||
elbow_left, wrist_left)
|
|
||||||
|
|
||||||
self.distance_left_leg_up = self.calculate_distance(
|
self.distance_left_leg_up = self.calculate_distance(hip_left, knee_left)
|
||||||
hip_left, knee_left)
|
|
||||||
|
|
||||||
self.distance_left_leg_down = self.calculate_distance(
|
self.distance_left_leg_down = self.calculate_distance(knee_left, ankle_left)
|
||||||
knee_left, ankle_left)
|
|
||||||
|
|
||||||
def euclidean_distance(self, x1, x2, y1, y2):
|
def euclidean_distance(self, x1, x2, y1, y2):
|
||||||
distance = math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)
|
distance = math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)
|
||||||
@ -226,25 +218,26 @@ class Landmarker:
|
|||||||
cv2.waitKey(0)
|
cv2.waitKey(0)
|
||||||
|
|
||||||
def get_center_top_point(self, side_results):
|
def get_center_top_point(self, side_results):
|
||||||
gray_image = cv2.cvtColor(self.side_image_keypoints,
|
gray_image = cv2.cvtColor(self.side_image_keypoints, cv2.COLOR_BGR2GRAY)
|
||||||
cv2.COLOR_BGR2GRAY)
|
|
||||||
blurred_image = cv2.GaussianBlur(gray_image, (5, 5), 0)
|
blurred_image = cv2.GaussianBlur(gray_image, (5, 5), 0)
|
||||||
roi = blurred_image[0 : int(self.side_image_resized.shape[0] / 2), :]
|
roi = blurred_image[0 : int(self.side_image_resized.shape[0] / 2), :]
|
||||||
self.edges = cv2.Canny(roi, 50, 150)
|
self.edges = cv2.Canny(roi, 50, 150)
|
||||||
contours, _ = cv2.findContours(self.edges, cv2.RETR_EXTERNAL,
|
contours, _ = cv2.findContours(
|
||||||
cv2.CHAIN_APPROX_SIMPLE)
|
self.edges, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE
|
||||||
|
)
|
||||||
xt, yt = None, None
|
xt, yt = None, None
|
||||||
self.topmost_point = None
|
self.topmost_point = None
|
||||||
|
|
||||||
if contours:
|
if contours:
|
||||||
largest_contour = max(contours, key=cv2.contourArea)
|
largest_contour = max(contours, key=cv2.contourArea)
|
||||||
self.topmost_point = tuple(
|
self.topmost_point = tuple(
|
||||||
largest_contour[largest_contour[:, :, 1].argmin()][0])
|
largest_contour[largest_contour[:, :, 1].argmin()][0]
|
||||||
|
)
|
||||||
xt, yt = self.topmost_point
|
xt, yt = self.topmost_point
|
||||||
self.circle(self.side_image_keypoints, xt, yt)
|
self.circle(self.side_image_keypoints, xt, yt)
|
||||||
|
|
||||||
logging.warning("xt: ", xt)
|
logging.warning("xt: %s", xt)
|
||||||
logging.warning(f"yt: ")
|
logging.warning("yt: %s", yt)
|
||||||
xc, yc = None, None
|
xc, yc = None, None
|
||||||
landmarks = side_results.pose_landmarks.landmark
|
landmarks = side_results.pose_landmarks.landmark
|
||||||
|
|
||||||
@ -260,13 +253,14 @@ class Landmarker:
|
|||||||
int(center_point[1] * self.side_image_resized.shape[0]),
|
int(center_point[1] * self.side_image_resized.shape[0]),
|
||||||
)
|
)
|
||||||
xc, yc = center_point
|
xc, yc = center_point
|
||||||
logging.warning("xc: ", xc)
|
logging.warning("xc: %s", xc)
|
||||||
logging.warning(f"yc: {yc}")
|
logging.warning("yc: %s", yc)
|
||||||
self.circle(self.side_image_keypoints, xc, yc)
|
self.circle(self.side_image_keypoints, xc, yc)
|
||||||
|
|
||||||
self.pixel_distance = self.euclidean_distance(xc, xt, yc, yt)
|
self.pixel_distance = self.euclidean_distance(xc, xt, yc, yt)
|
||||||
self.distance = self.euclidean_distance(
|
self.distance = (
|
||||||
xc, xt, yc, yt) * self.pixel_to_metric_ratio()
|
self.euclidean_distance(xc, xt, yc, yt) * self.pixel_to_metric_ratio()
|
||||||
|
)
|
||||||
return self.distance
|
return self.distance
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user