OpenCv椭圆皮肤模型
Mat input_image;
Mat output_mask;
Mat output_image; void main()
{
VideoCapture cam();
if (!cam.isOpened())
return; namedWindow("input image");
namedWindow("output mask");
namedWindow("output image");
//椭圆皮肤模型
Mat skinCrCbHist = Mat::zeros(Size(, ), CV_8UC1);
ellipse(skinCrCbHist, Point(, 155.6), Size(23.4, 15.2), 43.0, 0.0, 360.0, Scalar(, , ), -); while (true) {
cam >> input_image;
if (input_image.empty())
return; Mat ycrcb_image;
output_mask = Mat::zeros(input_image.size(), CV_8UC1);
cvtColor(input_image, ycrcb_image, CV_BGR2YCrCb); //首先转换成到YCrCb空间
for (int i = ; i < input_image.cols; i++) //利用椭圆皮肤模型进行皮肤检测
for (int j = ; j < input_image.rows; j++){
Vec3b ycrcb = ycrcb_image.at<Vec3b>(j, i);
if (skinCrCbHist.at<uchar>(ycrcb[], ycrcb[]) > )
output_mask.at<uchar>(j, i) = ;
}
input_image.copyTo(output_image, output_mask);
cv::erode(output_mask, output_mask, cv::Mat());
cv::erode(output_mask, output_mask, cv::Mat());
cv::erode(output_mask, output_mask, cv::Mat());
cv::erode(output_mask, output_mask, cv::Mat());
cv::dilate(output_mask, output_mask, cv::Mat());
imshow("input image", input_image);
imshow("output mask", output_mask);
imshow("output image", output_image);
output_image.setTo();
if ( == waitKey())
return;
}
return;
}
第二种:
Mat input_image;
Mat output_mask;
Mat output_image;
Mat mask;
void main()
{
VideoCapture cam();
if (!cam.isOpened())
return; ///椭圆皮肤模型
Mat skinCrCbHist = Mat::zeros(Size(, ), CV_8UC1);
ellipse(skinCrCbHist, Point(, 155.6), Size(23.4, 15.2), 43.0, 0.0, 360.0, Scalar(, , ), -); Mat element = getStructuringElement(MORPH_RECT, Size(, ), Point(-, -)); while (true)
{
cam >> input_image;
if (input_image.empty())
return; Mat ycrcb_image;
output_mask = Mat::zeros(input_image.size(), CV_8UC1);
cvtColor(input_image, ycrcb_image, CV_BGR2YCrCb); //首先转换成到YCrCb空间 for (int i = ; i < input_image.rows; i++) //利用椭圆皮肤模型进行皮肤检测
{
uchar* p = (uchar*)output_mask.ptr<uchar>(i);
Vec3b* ycrcb = (Vec3b*)ycrcb_image.ptr<Vec3b>(i);
for (int j = ; j < input_image.cols; j++)
{
if (skinCrCbHist.at<uchar>(ycrcb[j][], ycrcb[j][]) > )
p[j] = ;
}
} morphologyEx(output_mask, output_mask, MORPH_CLOSE, element); vector< vector<Point> > contours; // 轮廓
vector< vector<Point> > filterContours; // 筛选后的轮廓
vector< Vec4i > hierarchy; // 轮廓的结构信息
contours.clear();
hierarchy.clear();
filterContours.clear(); findContours(output_mask, contours, hierarchy, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE);
// 去除伪轮廓
for (size_t i = ; i < contours.size(); i++)
{
if (fabs(contourArea(Mat(contours[i]))) > &&fabs(arcLength(Mat(contours[i]),true))<) //判断手进入区域的阈值
filterContours.push_back(contours[i]);
} output_mask.setTo();
drawContours(output_mask, filterContours, -, Scalar(, , ), CV_FILLED); //8, hierarchy); input_image.copyTo(output_image, output_mask);
imshow("input image", input_image);
imshow("output image", output_image); output_image.setTo();
if ( == waitKey())
return;
}
return;
}
OpenCv椭圆皮肤模型的更多相关文章
- OpenCV混合高斯模型函数注释说明
OpenCV混合高斯模型函数注释说明 一.cvaux.h #define CV_BGFG_MOG_MAX_NGAUSSIANS 500 //高斯背景检测算法的默认参数设置 #define CV_BGF ...
- Opencv混合高斯模型前景分离
#include "stdio.h" #include "string.h" #include "iostream" #include &q ...
- OpenCv:椭圆上点的计算方程
椭圆 椭圆(Ellipse)是平面内到定点F1.F2的距离之和等于常数(大于|F1F2|)的动点P的轨迹,F1.F2称为椭圆的两个焦点.其数学表达式为: ...
- Opencv SkinOtsu皮肤检测
void SkinRGB(IplImage* rgb, IplImage* _dst) { assert(rgb->nChannels == && _dst->nChann ...
- OpenCV探索之路(二十七):皮肤检测技术
好久没写博客了,因为最近都忙着赶项目和打比赛==| 好吧,今天我打算写一篇关于使用opencv做皮肤检测的技术总结.那首先列一些现在主流的皮肤检测的方法都有哪些: RGB color space Yc ...
- OpenCV实时美颜摄像并生成H264视频流
为什么美颜摄像这么简单的功能,OpenCV这个开源项目网上很少有代码呢?对于在windows平台下,生成h264视频流也比价麻烦,没有现成的api可以使用,需要借助MinGw编译libx264,或者f ...
- 使用VS+OpenCV调用深度学习模型
最近项目有个任务,要在windows环境下用VS+OpenCV实现caffe模型的调用,于是在网上找了几个相关的博客跑了几个demo练练手.这些博客写得都很详细,但是有些细节由于版本更新的问题,配置的 ...
- HOG:从理论到OpenCV实践
(转载请注明出处:http://blog.csdn.net/zhazhiqiang/ 未经允许请勿用于商业用途) 一.理论 1.HOG特征描述子的定义: locally normalised ...
- Unity3d 屏幕空间人体皮肤知觉渲染&次表面散射Screen-Space Perceptual Rendering & Subsurface Scattering of Human Skin
之前的人皮渲染相关 前篇1:unity3d Human skin real time rendering 真实模拟人皮实时渲染 前篇2:unity3d Human skin real time ren ...
随机推荐
- restClient访问SSL
IRestClient client = new RestClient("https://xxx.com/aa/bb"); "; ); ServicePointManag ...
- SVN服务器配置说明
1.前 言 花了72小时,终于把 Subversion 初步掌握了.从一个连“什么是版本控制”都不知道的门外汉,到配置出精确至每目录访问的入门者,中间还卡了一天时间.其中费了许多气力,摸索实验了多次, ...
- QT的安装和配置及helloqt程序的编写时遇到的问题
1.如果在Windows下命令行编译和运行.cpp 文件,需要找到合适的命令所在文件夹的目录,把它添加到Windows的环境变量里去,SystemPropertiesAdvance. 如qmake 在 ...
- XtraFinder在OSX10.11的使用
重启系统,按住command键加上R键 进入恢复模式还是什么模式里,然后启动terminal 然后键入 csrutil enable --without debug 重启电脑,可正常使用 居然上传不了 ...
- django笔记-模型数据模板呈现过程记录(多对多关系)
首先,推荐一个网址:http://www.tuicool.com/articles/BfqYz2F,因为这里的比我的要有条理,更有利于各位的理解. 以下仅为为个人一次不完整的笔记: 环境:ubuntu ...
- SSH+Ext+mysql快速开发
一.需要知识点 1.SSH整合 2.EXT使用 以及深入细节点 二.小功能实现 1.Servlet实现校验码验证 2.首页布局实现 3.struts错误信息显示(struts标签使用) 4.首页整体布 ...
- 几乎所有的html + css 内容的编写, 都可以通过emmet来写
在今后的html编写中, 强迫 / 必须 使用 emmet来编写html代码了 !!!! 只使用zen coding, 只使用emmet 来编写, 再也不用以前的那种移动过去移动过来的 写法: 原始的 ...
- CF451C Predict Outcome of the Game 水题
Codeforces Round #258 (Div. 2) Predict Outcome of the Game C. Predict Outcome of the Game time limit ...
- spring缓存Ehcache(入门2)源码解读
Ehcache缓存: 解读: Ehcache缓存是在继承spring缓存核心类CacheManager的基础上实现的. 常用类: EhCacheCacheManager:继承自CacheManager ...
- LYDSY模拟赛day9 2048
/* 大模拟题,做的时候思路还是比较清晰的 */ #include<iostream> #include<cstdio> #include<string> #inc ...