我有一个结构体typedef struct EyeKeypoints { dlib::point left_eye; dlib::point right_eye; bool left_eye_missing; bool right_eye_missing; } EyeKeypoints,及该结构体的对象shape。如何用opencv把shape里面左眼及右眼坐标用矩形框画在mat上?
时间: 2023-02-12 09:33:24 浏览: 120
可以这样实现:
1. 定义OpenCV的Rect类型的对象分别表示左眼和右眼的矩形框,坐标为shape.left_eye和shape.right_eye。
2. 使用rectangle函数在Mat图像上绘制左眼和右眼的矩形框。
代码示例:
```
cv::Rect leftEyeRect(shape.left_eye.x, shape.left_eye.y, 20, 20);
cv::Rect rightEyeRect(shape.right_eye.x, shape.right_eye.y, 20, 20);
cv::rectangle(mat, leftEyeRect, cv::Scalar(255, 0, 0), 2);
cv::rectangle(mat, rightEyeRect, cv::Scalar(255, 0, 0), 2);
```
相关问题
我有一个结构体typedef struct EyeKeypoints { dlib::point left_eye; dlib::point right_eye; bool left_eye_missing; bool right_eye_missing; } EyeKeypoints,如何用opencv把里面左眼及右眼坐标用矩形框画在mat上?;
您可以这样做:
1. 定义左眼和右眼的矩形框:
```
cv::Rect left_eye_rect, right_eye_rect;
```
2. 设置左眼和右眼的矩形框的左上角和右下角坐标:
```
left_eye_rect = cv::Rect(left_eye.x, left_eye.y, width, height);
right_eye_rect = cv::Rect(right_eye.x, right_eye.y, width, height);
```
3. 在Mat图像上绘制左眼和右眼的矩形框:
```
cv::rectangle(mat, left_eye_rect, cv::Scalar(0, 255, 0), 2);
cv::rectangle(mat, right_eye_rect, cv::Scalar(0, 255, 0), 2);
```
这样,您就可以在Mat图像上绘制左眼和右眼的矩形框了。
阅读全文