4.15团队开发报告

1.昨天遇到了什么困难

在调配其他人的项目时对库的版本不熟练,导致很多功能功能没法运行。

2.今天的任务

将多人脸识别算法进行初步编写

3.代码

def show_3d_model(self):
from matplotlib import pyplot
from mpl_toolkits.mplot3d import Axes3D
fig = pyplot.figure()
ax = Axes3D(fig)
model_points = self.model_points_68
x = model_points[:, 0]
y = model_points[:, 1]
z = model_points[:, 2]

ax.scatter(x, y, z)
pyplot.xlabel('x')
pyplot.ylabel('y')
pyplot.show()

def solve_pose(self, image_points):
"""
Solve pose from image points
Return (rotation_vector, translation_vector) as pose.
"""
assert image_points.shape[0] == self.model_points_68.shape[
0], "3D points and 2D points should be of same number."
(_, rotation_vector, translation_vector) = cv2.solvePnP(
self.model_points_68, image_points, self.camera_matrix, self.dist_coeefs)

# (success, rotation_vector, translation_vector) = cv2.solvePnP(
# self.model_points,
# image_points,
# self.camera_matrix,
# self.dist_coeefs,
# rvec=self.r_vec,
# tvec=self.t_vec,
# useExtrinsicGuess=True)
return rotation_vector, translation_vector

def solve_body_pose(self, image_points):
"""
Solve pose from image points
Return (rotation_vector, translation_vector) as pose.
"""
assert image_points.shape[0] == self.body_model_points.shape[
0], "3D points and 2D points should be of same number."
(_, rotation_vector, translation_vector) = cv2.solvePnP(
self.body_model_points, image_points, self.camera_matrix, self.dist_coeefs)

# (success, rotation_vector, translation_vector) = cv2.solvePnP(
# self.model_points,
# image_points,
# self.camera_matrix,
# self.dist_coeefs,
# rvec=self.r_vec,
# tvec=self.t_vec,
# useExtrinsicGuess=True)
return rotation_vector, translation_vector

def solve_neck_pose(self, image_points):
"""
Solve pose from image points
Return (rotation_vector, translation_vector) as pose.
"""
assert image_points.shape[0] == self.neck_model_points.shape[
0], "3D points and 2D points should be of same number."
(_, rotation_vector, translation_vector) = cv2.solvePnP(
self.body_model_points, image_points, self.camera_matrix, self.dist_coeefs)

# (success, rotation_vector, translation_vector) = cv2.solvePnP(
# self.model_points,
# image_points,
# self.camera_matrix,
# self.dist_coeefs,
# rvec=self.r_vec,
# tvec=self.t_vec,
# useExtrinsicGuess=True)
return rotation_vector, translation_vector

def solve_pose_by_68_points(self, image_points):
"""
Solve pose from all the 68 image points
Return (rotation_vector, translation_vector) as pose.
"""

if self.r_vec is None:
(_, rotation_vector, translation_vector) = cv2.solvePnP(
self.model_points_68, image_points, self.camera_matrix, self.dist_coeefs)
# self.r_vec = rotation_vector
# self.t_vec = translation_vector

# (_, rotation_vector, translation_vector) = cv2.solvePnP(
# self.model_points_68,
# image_points,
# self.camera_matrix,
# self.dist_coeefs,
# rvec=rotation_vector,
# tvec=translation_vector,
# useExtrinsicGuess=True)

return rotation_vector, translation_vector
def draw_annotation_box(self, image, rotation_vector, translation_vector, color=(255, 255, 255), line_width=2):
"""Draw a 3D box as annotation of pose"""
point_3d = []
rear_size = 75
rear_depth = 0
point_3d.append((-rear_size, -rear_size, rear_depth))
point_3d.append((-rear_size, rear_size, rear_depth))
point_3d.append((rear_size, rear_size, rear_depth))
point_3d.append((rear_size, -rear_size, rear_depth))
point_3d.append((-rear_size, -rear_size, rear_depth))

front_size = 100
front_depth = 100
point_3d.append((-front_size, -front_size, front_depth))
point_3d.append((-front_size, front_size, front_depth))
point_3d.append((front_size, front_size, front_depth))
point_3d.append((front_size, -front_size, front_depth))
point_3d.append((-front_size, -front_size, front_depth))
point_3d = np.array(point_3d, dtype=np.float).reshape(-1, 3)

# Map to 2d image points
(point_2d, _) = cv2.projectPoints(point_3d,
rotation_vector,
translation_vector,
self.camera_matrix,
self.dist_coeefs)
point_2d = np.int32(point_2d.reshape(-1, 2))

# Draw all the lines
cv2.polylines(image, [point_2d], True, color, line_width, cv2.LINE_AA)
cv2.line(image, tuple(point_2d[1]), tuple(
point_2d[6]), color, line_width, cv2.LINE_AA)
cv2.line(image, tuple(point_2d[2]), tuple(
point_2d[7]), color, line_width, cv2.LINE_AA)
cv2.line(image, tuple(point_2d[3]), tuple(
point_2d[8]), color, line_width, cv2.LINE_AA)

def draw_axis(self, img, R, t):
points = np.float32(
[[30, 0, 0], [0, 30, 0], [0, 0, 30], [0, 0, 0]]).reshape(-1, 3)

axisPoints, _ = cv2.projectPoints(
points, R, t, self.camera_matrix, self.dist_coeefs)

cv2.line(img, tuple(axisPoints[3].ravel()), tuple(
axisPoints[0].ravel()), (255, 0, 0), 3)
cv2.line(img, tuple(axisPoints[3].ravel()), tuple(
axisPoints[1].ravel()), (0, 255, 0), 3)
cv2.line(img, tuple(axisPoints[3].ravel()), tuple(
axisPoints[2].ravel()), (0, 0, 255), 3)

def draw_axes(self, img, R, t):
cv2.drawFrameAxes(img, self.camera_matrix, self.dist_coeefs, R, t, 30)

def get_pose_marks(self, marks):
"""Get marks ready for pose estimation from 68 marks"""
pose_marks = [marks[30], marks[8], marks[36], marks[45], marks[48], marks[54]]
return pose_marks

@staticmethod
def get_euler(rotation_vector, translation_vector):
"""
此函数用于从旋转向量计算欧拉角
:param translation_vector: 输入为偏移向量
:param rotation_vector: 输入为旋转向量
:return: 返回欧拉角在三个轴上的值
"""
rvec_matrix = cv2.Rodrigues(rotation_vector)[0]
proj_matrix = np.hstack((rvec_matrix, translation_vector))
eulerAngles = cv2.decomposeProjectionMatrix(proj_matrix)[6]
yaw = eulerAngles[1]
pitch = eulerAngles[0]
roll = eulerAngles[2]
rot_params = np.array([yaw, pitch, roll])
return rot_params
posted @   Joranger  阅读(26)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 使用C#创建一个MCP客户端
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· ollama系列1:轻松3步本地部署deepseek,普通电脑可用
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 按钮权限的设计及实现
点击右上角即可分享
微信分享提示