我是靠谱客的博主 甜蜜万宝路,这篇文章主要介绍opencv 人脸背景是否亮度过强检测,现在分享给大家,希望可以做个参考。

笔记hsv图判断图像亮度

在人脸检测中,如果人脸背景亮度过强(自然光照或灯光导致),相机无法自适应调节面部亮度,就会导致人脸很暗,影响面部特征的提取.
检测光照强度,判断环境是否符合实验要求.
DetectLandmarkPoints(),人脸68点检测.该接口后续添加.

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <opencv2/opencv.hpp> using namespace std; using namespace cv; int main() { cv::Mat testframe = imread("backlight.png"); bool BackLightFlag = false; if (testframe.empty()) { cout << "image imread fail;" << endl; return 1; } std::vector<cv::Point2f> landmarks; landmarks = DetectLandmarkPoints();//人脸68个特征点检测 cv::Rect mat_back_light_rect(std::max(float(0), landmarks[0].x - abs(landmarks[0].x - landmarks[16].x)), std::max(float(0), landmarks[19].y - abs(landmarks[19].y - landmarks[33].y) / 2), std::max(float(0), abs(landmarks[0].x - landmarks[16].x)) * 3, std::max(float(0), abs(landmarks[19].y - landmarks[51].y)));; if (mat_back_light_rect.x + mat_back_light_rect.width > testframe.cols || mat_back_light_rect.y + mat_back_light_rect.height > testframe.rows) { cout << "face roi out of image bounds;" << endl; return 1; } cv::Mat mat_back_light_roi = testframe(mat_back_light_rect); cv::Mat mat_back_light_roi_hsv; cvtColor(mat_back_light_roi, mat_back_light_roi_hsv, cv::COLOR_RGB2HSV);//转换成hsv int count_v = 0; for (int i = 0; i < mat_back_light_roi.cols; i++) { for (int j = 0; j < mat_back_light_roi.rows; j++) { if ((i< mat_back_light_roi.cols / 3 || i>mat_back_light_roi.cols / 3 * 2) && static_cast<int>(mat_back_light_roi_hsv.at<cv::Vec3b>(j, i)[2]) > 200)//取hsv通道值时记得转换类型 { count_v++; } } } if (count_v > mat_back_light_roi.cols * 2 / 3 * mat_back_light_roi.rows / 3)//过亮面积大于总面积的1/3判断为异常 { BackLightFlag = true; cout << "BackLight Exception;" << endl; } }

最后

以上就是甜蜜万宝路最近收集整理的关于opencv 人脸背景是否亮度过强检测的全部内容,更多相关opencv内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(60)

评论列表共有 0 条评论

立即
投稿
返回
顶部