資源簡介
讀取視頻,根據(jù)移動檢測與行人檢測做的一個監(jiān)控人數(shù)的程序,運行環(huán)境為Qt+Opencv,在運行前注意配置好環(huán)境

代碼片段和文件信息
#include?“detectcv.h“
DetectCV::DetectCV(int?x?int?y?int?width?int?height)
{
????????//--?1.?加載級聯(lián)分類器文件
????????if(?!face_cascade.load(?face_cascade_name?)?)
????????{
????????????????printf(“--(!)Error?loading\n“);
????????????????cout?<????????}
????????screen?=?QGuiApplication::primaryScreen();
????????for(int?i=0;?i?3;?i++)
????????{
????????????QString?filePathName?=?“full-“;
????????????filePathName?+=?QString::number(i10);
????????????filePathName?+=?“.jpg“;
????????????screen->grabWindow(0?x?y?width?height).save(filePathName?“jpg“);
????????}
}
/**?@函數(shù)?detectFace?*/
int?DetectCV::detectFace(?)
{
????????vector?faces;
????????Mat?frame_gray;
????????QString?path?=?“full-“?+?QString::number(past10)?+?“.jpg“;
????????Mat?frame?=?imread(path.toStdString());
????????cvtColor(?frame?frame_gray?CV_BGR2GRAY?);
????????equalizeHist(?frame_gray?frame_gray?);
????????//--?多尺寸檢測人臉
????????face_cascade.detectMultiScale(?frame_gray?faces?1.1?2?0|CV_HAAR_SCALE_IMAGE?Size(30?30)?);
????????for(?int?i?=?0;?i?????????{
????????????????Point?center(?faces[i].x?+?faces[i].width*0.5?faces[i].y?+?faces[i].height*0.5?);
????????????????ellipse(?frame?center?Size(?faces[i].width*0.5?faces[i].height*0.5)?0?0?360?Scalar(?255?0?255?)?4?8?0?);
????????}
????????//--?顯示結(jié)果圖像
????????imshow(?window_name?frame?);
????????return?faces.size();
}
/**?@函數(shù)?detectBody?*/
int?DetectCV::detectBody(Mat?framevector?boundRect)
{
//????????QString?path?=?“full-“?+?QString::number(past10)?+?“.jpg“;
//????????Mat?frame?=?imread(path.toStdString());
????????std::vector?bodys;
????????HOGDescriptor?defaultHog;
????????defaultHog.setSVMDetector(HOGDescriptor::getDefaultPeopleDetector());
????????//進行檢測
????????defaultHog.detectMultiScale(frame?bodys);
????????//畫長方形,框出行人
????????for(int?i?=?0;?i?????????{
????????????????Rect?r?=?bodys[i];
????????????????Point?center?=?heightPoint(r);
????????????????for(int?j?=?0;?j?????????????????{
????????????????????if(center.x?>?boundRect[j].x
????????????????????????????&&?center.x?????????????????????????????&&?center.y?>?boundRect[j].y
????????????????????????????&&?center.y?????????????????????{
????????????????????????//?if?come?back
????????????????????????for(int?l?=?0;?l ????????????????????????{
????????????????????????????if(per_direc[l].bound.x?==?boundRect[j].x?&&?per_direc[l].bound.y?==?boundRect[j].y)
????????????????????????????{
????????????????????????????????per_direc[l].preNum++;
????????????????????????????????per_direc[l].isAppear?=?true;
//????????????????????????????????per_direc[l].appearTimes++;
????????????????????????????}
????????????????????????}
????????????????????????rectangle(frame?r?Scalar(0?0?255)?2);
????????????????????}
????????????????}
???????????????
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2018-06-06?17:07??projectCatch\
?????文件?????????192??2018-04-13?07:09??projectCatch\main.cpp
?????文件???????24176??2018-04-13?08:39??projectCatch\projectcatch.pro.user
?????文件?????????710??2018-05-21?06:14??projectCatch\mainwindow.h
?????文件???????24183??2018-06-01?18:41??projectCatch\projectCatch.pro.user
?????文件????????2750??2018-05-23?04:05??projectCatch\mainwindow.ui
?????文件???????10704??2018-05-31?10:41??projectCatch\detectcv.cpp
?????文件????????1184??2018-05-21?06:37??projectCatch\detectcv.h
?????文件??????????59??2018-05-23?07:54??projectCatch\person.cpp
?????文件????????2223??2018-06-06?17:07??projectCatch\mainwindow.cpp
?????文件????????1962??2018-05-16?06:21??projectCatch\projectCatch.pro
?????文件?????????371??2018-05-23?07:54??projectCatch\person.h
評論
共有 條評論