資源簡介
基于opencv,用C++開發的基于模板匹配的,紅外光照明下的實時瞳孔識別算法,帶有搜索域跟蹤功能,i7下cpu上處理能達到30fps以上

代碼片段和文件信息
#include?“tempMatchPupilDetect.h“
using?namespace?std;
using?namespace?cv;
VideoWriter?outPutMaskoutPutContouroutPutProccessed;
int?main()?{
????int?videoSource=0;//0:read?video?file?;?1:?open?webcam
????long?totalframeNumber;
????cv::VideoCapture?capture;
????long?frameToStart?=?10;
????long?frameIndex=frameToStart;
????cv::Point2d?center?=?cv::Point2d(0?0);
????cv::Mat?framepreframe;
????cv::Rect?roi;
????int?key;
????int?flag;
????double?scale?=0.5;
????Mat?imgDiffAcumu;
????int?patchThre?=?0;
????int?pupilMissCount?=0;
????Mat?templateImg;
????int?pupilSizeMin?=?9;
????int?pupilSizeMax?=?10000;
????int?debugTag?=?1;
????if(!videoSource){
????????capture.open(“1.avi“);
????????totalframeNumber?=?capture.get(CV_CAP_PROP_frame_COUNT);
????????capture.set(?CV_CAP_PROP_POS_frameSframeToStart);
????????cout<<“start?frame:“<ameToStart<<“??to?read“< ????else{
????????capture.open(0);
????????totalframeNumber?=?100000000;}
????if(!capture.isOpened())
????????cout<<“fail?to?open?video?source!“< ????double?rate?=?capture.get(CV_CAP_PROP_FPS);
????cout<<“fps:“<
//reading?one?frame?for?the?preframe?for?calculate?optical?flow
????if(!capture.read(frame)){
????????cout<<“reading?frame?failure“< ????????return?-1;}
????frameIndex++;
????roi?=?cv::Rect(0?0?0?0);
????templateImg?=?Mat::ones(201201CV_8UC1)*255;
????circle(templateImg
?????????Point(101101)
?????????50
?????????0
?????????-1
?????????LINE_8);
????namedWindow(“template?from?algrithm“);
????imshow(“template?from?algrithm“templateImg);
????if(debugTag){
????????outPutMask.open(“./mask.avi“??CV_FOURCC(‘D‘?‘I‘?‘V‘?‘X‘)?30Size(200200)?false);
????????outPutContour.open(“./contour.avi“??CV_FOURCC(‘D‘?‘I‘?‘V‘?‘X‘)?30Size(200200)?false);
????????outPutProccessed.open(“./proccessed.avi“CV_FOURCC(‘D‘?‘I‘?‘V‘?‘X‘)?30Size(frame.colsframe.rows)?true);
????????if?(!outPutMask.isOpened()||!outPutContour.isOpened()||!outPutProccessed.isOpened()){
????????????cout??<“Could?not?open?the?output?video?for?write:?“?<?endl;
????????????return?-1;
????????}
????}
//start?the?detect?task?loop
????while?(key!=27?&&?key!=?1048603?&&?frameIndex?ameNumber)?{???????//Esc?key?value?in?win?is?27?and?in?linux?is?1048603
????????double?t?=?(double)cvGetTickCount();??//calculate?the?cost?time
????????std::swap(preframe?frame);
????????if(!capture.read(frame)){
????????????cout<<“reading?frame?failure“< ????????????return?-1;
????????}
????????std::cout<<“totalframeNumber:“<ameNumber<<“???frameIndex:“<ameIndex<
????????monoPupilDetect(frametemplateImgroicenterflagpatchThrepupilMissCountpupilSizeMinpupilSizeMaxdebugTag);
//????????opticalFlowPupilDetect(preframeframescaleroicenterflag);
//????????imgDiffProcess(preframeframeimgDiffAcumuscaleroi);
????????frameIndex++;
????????key?=?waitKey(1);
????????cout
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件??????89057??2019-03-18?20:10??pupil_extract_20170701\example.png
?????文件?????884897??2019-03-18?20:19??pupil_extract_20170701\example2.png
?????文件???????3564??2019-03-18?20:08??pupil_extract_20170701\main.cpp
?????文件???????1222??2019-03-18?20:06??pupil_extract_20170701\pupil_extract.pro
?????文件??????24118??2019-03-18?20:16??pupil_extract_20170701\pupil_extract.pro.user
?????文件????????299??2019-03-18?20:15??pupil_extract_20170701\readme.txt
?????文件??????16492??2017-07-01?01:57??pupil_extract_20170701\tempMatchPupilDetect.cpp
?????文件????????912??2019-03-18?20:00??pupil_extract_20170701\tempMatchPupilDetect.h
?????目錄??????????0??2019-03-18?20:20??pupil_extract_20170701
-----------?---------??----------?-----??----
??????????????1020561????????????????????9
- 上一篇:modbus完整協議源碼c/c++
- 下一篇:C語言環形隊列
評論
共有 條評論