亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費(fèi)注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 6497 | 回復(fù): 0
打印 上一主題 下一主題

怎么計算臉部姿勢 with cv2.solvePnP in python3 [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報告]
發(fā)表于 2018-03-21 10:38 |只看該作者 |倒序?yàn)g覽
我用shape_predictor_68_face_landmarks.dat計算出臉部得68個點(diǎn),想得到臉部姿勢,通過這個函數(shù)計算在兩個人得圖片上計算,發(fā)現(xiàn)[float(roll), float(pitch), float(yaw)]值接近得兩張圖,臉得姿勢并不一樣,誰用過這個函數(shù),幫忙給點(diǎn)意見。
def face_orientation(frame, landmarks):
    size = frame.shape #(height, width, color_channel)

    # image_points = np.array([
                            # (landmarks[4], landmarks[5]),     # Nose tip
                            # (landmarks[10], landmarks[11]),   # Chin
                            # (landmarks[0], landmarks[1]),     # Left eye left corner
                            # (landmarks[2], landmarks[3]),     # Right eye right corne
                            # (landmarks[6], landmarks[7]),     # Left Mouth corner
                            # (landmarks[8], landmarks[9])      # Right mouth corner
                        # ], dtype="double")
   
    # center_righteyes = (landmarks[36] + landmarks[39]) // 2
    # center_lefteyes  = (landmarks[42] + landmarks[45]) // 2
    # image_points = numpy.array([
                            # landmarks[31],     # Nose tip
                            # landmarks[8],   # Chin
                            # center_lefteyes,     # Left eye left corner
                            # center_righteyes,     # Right eye right corne
                            # landmarks[48],     # Left Mouth corner
                            # landmarks[54]      # Right mouth corner
                        # ], dtype="double")
                        
    image_points = numpy.array([
        (landmarks[33, 0], landmarks[33, 1]),     # Nose tip
        (landmarks[8, 0], landmarks[8, 1]),       # Chin
        (landmarks[36, 0], landmarks[36, 1]),     # Left eye left corner
        (landmarks[45, 0], landmarks[45, 1]),     # Right eye right corner
        (landmarks[48, 0], landmarks[48, 1]),     # Left Mouth corner
        (landmarks[54, 0], landmarks[54, 1])      # Right mouth corner
        ], dtype="double")

                        
    model_points = numpy.array([
                            (0.0, 0.0, 0.0),             # Nose tip
                            (0.0, -330.0, -65.0),        # Chin
                            (-165.0, 170.0, -135.0),     # Left eye left corner
                            (165.0, 170.0, -135.0),      # Right eye right corne
                            (-150.0, -150.0, -125.0),    # Left Mouth corner
                            (150.0, -150.0, -125.0)      # Right mouth corner                        
                        ])

    # Camera internals

    center = (size[1]/2, size[0]/2)
    focal_length = center[0] / numpy.tan(60/2 * numpy.pi / 180)
    camera_matrix = numpy.array(
                         [[focal_length, 0, center[0]],
                         [0, focal_length, center[1]],
                         [0, 0, 1]], dtype = "double"
                         )

    dist_coeffs = numpy.zeros((4,1)) # Assuming no lens distortion
    #(success, rotation_vector, translation_vector) = cv2.solvePnP(model_points, image_points, camera_matrix, dist_coeffs, flags=cv2.CV_ITERATIVE)
    (success, rotation_vector, translation_vector) = cv2.solvePnP(model_points, image_points, camera_matrix, dist_coeffs, flags=cv2.SOLVEPNP_ITERATIVE)

   
    axis = numpy.float32([[500,0,0],
                          [0,500,0],
                          [0,0,500]])
                          
    imgpts, jac = cv2.projectPoints(axis, rotation_vector, translation_vector, camera_matrix, dist_coeffs)
    modelpts, jac2 = cv2.projectPoints(model_points, rotation_vector, translation_vector, camera_matrix, dist_coeffs)
    rvec_matrix = cv2.Rodrigues(rotation_vector)[0]

    proj_matrix = numpy.hstack((rvec_matrix, translation_vector))
    eulerAngles = cv2.decomposeProjectionMatrix(proj_matrix)[6]

   
    pitch, yaw, roll = [math.radians(_) for _ in eulerAngles]


    pitch = math.degrees(math.asin(math.sin(pitch)))
    roll = -math.degrees(math.asin(math.sin(roll)))
    yaw = math.degrees(math.asin(math.sin(yaw)))

    #return imgpts, modelpts, (str(int(roll)), str(int(pitch)), str(int(yaw))), (landmarks[4], landmarks[5])
    return numpy.array([float(roll), float(pitch), float(yaw)], dtype = "double")
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報專區(qū)
中國互聯(lián)網(wǎng)協(xié)會會員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP