人脸姿态估计

opencv +dlib 人脸姿态估计:

dlib人脸识别参考:http://dlib.net/


#include <dlib/opencv.h>
#include <opencv2/highgui/highgui.hpp>
#include "opencv2/opencv.hpp"
#include "opencv2/core/core.hpp"
#include "opencv2/objdetect/objdetect.hpp"
#include <dlib/image_processing/frontal_face_detector.h>
#include <dlib/image_processing/render_face_detections.h>
#include <dlib/image_processing.h>
#include <dlib/gui_widgets.h>
#include "head_pose_estimation_test.h"
using namespace dlib;
using namespace std;
//using namespace cv;
//
//cv::Mat estimateHeadPoseMat;
//cv::Mat estimateHeadPoseMat2;
//int *estimateHeadPosePointIndexs;
static int HeadPosePointIndexs[] = { 36, 39, 42, 45, 30, 48, 54 };
int *estimateHeadPosePointIndexs = HeadPosePointIndexs;
static float estimateHeadPose2dArray[] = {
	-0.208764, -0.140359, 0.458815, 0.106082, 0.00859783, -0.0866249, -0.443304, -0.00551231, -0.0697294,
	-0.157724, -0.173532, 0.16253, 0.0935172, -0.0280447, 0.016427, -0.162489, -0.0468956, -0.102772,
	0.126487, -0.164141, 0.184245, 0.101047, 0.0104349, -0.0243688, -0.183127, 0.0267416, 0.117526,
	0.201744, -0.051405, 0.498323, 0.0341851, -0.0126043, 0.0578142, -0.490372, 0.0244975, 0.0670094,
	0.0244522, -0.211899, -1.73645, 0.0873952, 0.00189387, 0.0850161, 1.72599, 0.00521321, 0.0315345,
	-0.122839, 0.405878, 0.28964, -0.23045, 0.0212364, -0.0533548, -0.290354, 0.0718529, -0.176586,
	0.136662, 0.335455, 0.142905, -0.191773, -0.00149495, 0.00509046, -0.156346, -0.0759126, 0.133053,
	-0.0393198, 0.307292, 0.185202, -0.446933, -0.0789959, 0.29604, -0.190589, -0.407886, 0.0269739,
	-0.00319206, 0.141906, 0.143748, -0.194121, -0.0809829, 0.0443648, -0.157001, -0.0928255, 0.0334674,
	-0.0155408, -0.145267, -0.146458, 0.205672, -0.111508, 0.0481617, 0.142516, -0.0820573, 0.0329081,
	-0.0520549, -0.329935, -0.231104, 0.451872, -0.140248, 0.294419, 0.223746, -0
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
以下是OpenMV4的人脸姿态估计代码: 首先,我们需要导入所需的库和模块: ```python import sensor, image, time import KPU as kpu import lcd from fpioa_manager import * from machine import I2C from board import board_info from fpioa_manager import * from pmu import axp192 from modules import ws2812 ``` 然后,我们需要初始化硬件和模块: ```python fm.register(board_info.LED_W, fm.fpioa.GPIO0) led = GPIO(GPIO.GPIO0, GPIO.OUT) led.value(1) lcd.init(freq=15000000) lcd.direction(lcd.YX_RLDU) sensor.reset() sensor.set_pixformat(sensor.RGB565) sensor.set_framesize(sensor.QVGA) sensor.set_vflip(1) sensor.run(1) kpu.memtest() task = kpu.load(0x200000) ``` 接下来,我们需要创建I2C总线和AXP192电源管理器的实例: ```python fm.register(20, fm.fpioa.GPIOH7) fm.register(21, fm.fpioa.GPIOH6) i2c = I2C(I2C.I2C0, freq=400000, scl=21, sda=20) pmu = axp192(i2c=i2c) pmu.enablePMICSleepMode(True) ``` 然后,我们需要定义一些变量和函数: ```python def draw_string_at(img, x, y, text): img.draw_string(x, y, text, color=(255, 255, 255), scale=2) colors = [(255, 0, 0), (255, 128, 0), (255, 255, 0), (128, 255, 0), (0, 255, 0), (0, 255, 128), (0, 255, 255), (0, 128, 255), (0, 0, 255), (128, 0, 255), (255, 0, 255), (255, 0, 128), (128, 128, 128), (0, 0, 0)] def draw_arrow(img, x, y, dx, dy): img.draw_line(x, y, x+dx, y+dy, color=(255, 0, 0), thickness=3) img.draw_circle(x+dx, y+dy, 5, color=(255, 0, 0), thickness=3) def get_pose_string(pose): return "Yaw: {:.2f}, Pitch: {:.2f}, Roll: {:.2f}".format(pose[0], pose[1], pose[2]) ``` 最后,我们可以开始循环读取图像,进行人脸检测和姿态估计,并在LCD屏幕上显示结果: ```python while True: img = sensor.snapshot() boxes = img.detect_face() if boxes: for box in boxes: x, y, w, h = box img.draw_rectangle(x, y, w, h, color=colors[0], thickness=3) face_img = img.crop(x, y, w, h) resized_img = face_img.resize(128, 128) out = kpu.forward(task, resized_img) pose = out[:3] draw_string_at(img, x, y-30, get_pose_string(pose)) draw_arrow(img, int(x+w/2), int(y+h/2), int(pose[0]*50), int(pose[1]*50)) lcd.display(img) ``` 完整代码如下:

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值