资源简介
简单的一份代码程序,调用笔记本的摄像头进行人脸捕捉,同时进行灰度处理。利用OpenCV自带的函数库实现,可运行。

代码片段和文件信息
// ComputerVisualHW.cpp : 定义控制台应用程序的入口点。
//
#include “stdafx.h“
#include “opencv2/objdetect/objdetect.hpp“
#include “opencv2/highgui/highgui.hpp“
#include “opencv2/imgproc/imgproc.hpp“
#include
#include
//using namespace std;
using namespace cv;
/*******************************************************
detectAndGray函数申明
函数功能:将摄像头所摄取到的图像进行人脸捕捉以及灰度转换
********************************************************/
void detectAndGray(Mat frame);
/*******************************************************
函数变量定义
********************************************************/
//人脸识别功能所需的扩展标记语言
string face_cascade_name = “haarcascade_frontalface_alt.xml“;
//声明对象
CascadeClassifier face_cascade;
//显示窗口1:原图像及人脸捕捉
string window_name_RGB = “Capture - Face detection - RGB“;
//显示窗口2:灰度化图像及人脸捕捉
string window_name_GRAY = “Capture - Face detection - GRAY“;
/*******************************************************
主函数
********************************************************/
int main (int argc const char** argv)
{
CvCapture* capture;//用来存储摄像头的状态
Mat frame;//用来存储摄像头采集回来的一帧图像
/************加载级联分类器文件***********/
if(!face_cascade.load(face_cascade_name))
{
//级联分类器文件加载失败,程序停止运行
printf(“--(!)Error loading face_cascade\n“);
return -1;
}
//打开内置摄像头视频流
capture = cvCaptureFromCAM(0);
//摄像头处于打开状态
if (capture)
{
while(true)
{
//从摄像头中获取一帧图像并存储在frame中
frame = cvQueryframe(capture);
//对当前一帧图像进行处理
if(!frame.empty())//有图像
{
//人脸检测以及灰度转化
detectAndGray(frame);
}
//按ESC键退出图像窗口
if(cvWaitKey(50) == 27){break;}
}
}
return 0;
}
/*****************函数 detectAndDisplay ****************/
void detectAndGray(Mat frame)
{
std::vector faces;
Mat frame_gray;
//多尺寸检测人脸
face_cascade.detectMultiScale(framefaces1.120|CV_HAAR_SCALE_IMAGESize(3030));
for(int i = 0; i < faces.size(); i++)
{
Point center(faces[i].x + faces[i].width*0.5faces[i].y+faces[i].height*0.5);
ellipse(framecenterSize(faces[i].width*0.5faces[i].height*0.5)00360Scalar(2550255)480);
}
imshow(window_name_RGBframe);//窗口1显示原图像
//将原图像转换成灰度图像
cvtColor(frameframe_grayCV_BGR2GRAY);
//在灰度图像上进行人脸检测
face_cascade.detectMultiScale(frame_grayfaces1.120|CV_HAAR_SCALE_IMAGESize(3030));
for(int i = 0; i < faces.size(); i++)
{
Point center(faces[i].x + faces[i].width*0.5faces[i].y+faces[i].height*0.5);
ellipse(frame_graycenterSize(faces[i].width*0.5faces[i].height*0.5)00360Scalar(2550255)480);
}
imshow(window_name_GRAYframe_gray);//窗口2显示灰度图像
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 2959 2014-11-20 18:17 ComputerVisualHW\ComputerVisualHW\ComputerVisualHW.cpp
文件 5007 2014-11-19 20:46 ComputerVisualHW\ComputerVisualHW\ComputerVisualHW.vcxproj
文件 1320 2014-11-19 20:40 ComputerVisualHW\ComputerVisualHW\ComputerVisualHW.vcxproj.filters
文件 143 2014-11-19 20:40 ComputerVisualHW\ComputerVisualHW\ComputerVisualHW.vcxproj.user
文件 1882 2014-11-20 18:04 ComputerVisualHW\ComputerVisualHW\Debug\cl.command.1.tlog
文件 20506 2014-11-20 18:04 ComputerVisualHW\ComputerVisualHW\Debug\CL.read.1.tlog
文件 1466 2014-11-20 18:04 ComputerVisualHW\ComputerVisualHW\Debug\CL.write.1.tlog
文件 406 2014-11-19 20:40 ComputerVisualHW\ComputerVisualHW\Debug\ComputerVisualHW.exe.em
文件 472 2014-11-19 20:41 ComputerVisualHW\ComputerVisualHW\Debug\ComputerVisualHW.exe.em
文件 381 2014-11-20 18:04 ComputerVisualHW\ComputerVisualHW\Debug\ComputerVisualHW.exe.intermediate.manifest
文件 94 2014-11-20 18:04 ComputerVisualHW\ComputerVisualHW\Debug\ComputerVisualHW.lastbuildstate
文件 4849 2014-11-20 18:04 ComputerVisualHW\ComputerVisualHW\Debug\ComputerVisualHW.log
文件 176229 2014-11-20 18:04 ComputerVisualHW\ComputerVisualHW\Debug\ComputerVisualHW.obj
文件 1179648 2014-11-19 20:40 ComputerVisualHW\ComputerVisualHW\Debug\ComputerVisualHW.pch
文件 707 2014-11-19 22:08 ComputerVisualHW\ComputerVisualHW\Debug\ComputerVisualHW.vcxprojResolveAssemblyReference.cache
文件 0 2014-11-19 20:40 ComputerVisualHW\ComputerVisualHW\Debug\ComputerVisualHW.write.1.tlog
文件 222 2014-11-19 20:40 ComputerVisualHW\ComputerVisualHW\Debug\ComputerVisualHW_manifest.rc
文件 2 2014-11-20 18:04 ComputerVisualHW\ComputerVisualHW\Debug\li
文件 2 2014-11-20 18:04 ComputerVisualHW\ComputerVisualHW\Debug\li
文件 2 2014-11-20 18:04 ComputerVisualHW\ComputerVisualHW\Debug\li
文件 2 2014-11-20 18:04 ComputerVisualHW\ComputerVisualHW\Debug\li
文件 2 2014-11-20 18:04 ComputerVisualHW\ComputerVisualHW\Debug\li
文件 2 2014-11-20 18:04 ComputerVisualHW\ComputerVisualHW\Debug\li
文件 2 2014-11-20 18:04 ComputerVisualHW\ComputerVisualHW\Debug\li
文件 2 2014-11-20 18:04 ComputerVisualHW\ComputerVisualHW\Debug\li
文件 2 2014-11-20 18:04 ComputerVisualHW\ComputerVisualHW\Debug\li
文件 2 2014-11-20 18:04 ComputerVisualHW\ComputerVisualHW\Debug\li
文件 2 2014-11-20 18:04 ComputerVisualHW\ComputerVisualHW\Debug\li
文件 2 2014-11-20 18:04 ComputerVisualHW\ComputerVisualHW\Debug\li
文件 2 2014-11-20 18:04 ComputerVisualHW\ComputerVisualHW\Debug\li
............此处省略65个文件信息
- 上一篇:机器人焊接技术实用的教程
- 下一篇:jhaosui_10655933.zip
相关资源
- 基于OpenCV的数字识别468815
- 使用opencv去掉二值化图像中黑色面积
- opencv环境配置
- win10 64位下编译的opencv4.5.5库,opencv
- NVIDIAOpticalFlowSDK-79c6cee80a2df9a196f20afd6
- opencv_contrib-3.4.0.zip
- opencv2.4.9源码分析——SIFT
- 用两个摄像头实现,双目标定,双目
- opencv_traincascade训练分类器,手势识别
- opencv3.0交叉编译用parallel.cpp
- 基于opencv的图像识别识别图像中的色
- 基于openCV的识别特定颜色区域
- 基于OpenCV的分水岭算法实现
- QT+opencv+OCR 身份证号码,银行卡号识别
- opencv视频特定颜色区域识别
- 把RGB转换为HSV和HSI然后根据黄色和蓝
- opencv视觉测距
- 基于Qt和opencv的身份证号码识别系统
- opencv_ffmpeg249.dll
- SfM稀疏三维点云重建--完整工程文件
- 基于opencv的数人头程序源代码
- 利用OpenCV中的Stitcher类实现全景图像拼
- opencv实现的sift算法源码,包含了图像
- openCV 上的小波变换
- 基于OPENCV的车牌识别系统设计
- 617张国内车牌60-17bmp图片用于OpenCV正样
- hog特征提取,c版本代码
- 基于Qt5.8+OpenCV3.2的Basler多相机触发开
- 基于Opencv实现的图像纠偏
- ImageWatch2019.vsix
评论
共有 条评论