資源簡介
使用matlab打開筆記本自帶的攝像頭進(jìn)行實(shí)時人臉識別。修改了matlab示例程序,具有較好的實(shí)時性和魯棒性,能夠在光線充足的環(huán)境下穩(wěn)定識別并跟蹤。注:若未在matlab中使用過攝像頭,需要在matlab中首先手動聯(lián)網(wǎng)下載安裝筆記本自帶攝像頭的支持包,否則可能無法識別自帶的攝像頭
代碼片段和文件信息
%?2017-05-22?by?LSS
%?Live?Face?Detection
%?Need?to?manually?install?support?package?(OS?Generic?Video?Interface)
vidDevice?=?imaq.VideoDevice(‘winvideo‘?1?‘MJPG_320x240‘?...
?????????????????????????????‘ROI‘?[1?1?320?240]?...
?????????????????????????????‘ReturnedColorSpace‘?‘rgb‘?...
?????????????????????????????‘DeviceProperties.Brightness‘?8?...
?????????????????????????????‘DeviceProperties.Sharpness‘?8);
hVideoIn?=?vision.VideoPlayer;
hVideoIn.Name??=?‘Input?Video‘;
hVideoOut?=?vision.VideoPlayer;
hVideoOut.Name??=?‘Output?Video‘;
faceDetector?=?vision.CascadeobjectDetector();
pointTracker?=?vision.PointTracker(‘MaxBidirectionalError‘?2);
numPts?=?0;
while?1
????videoframe?=?step(vidDevice);
????videoframeOutput?=?videoframe;
????videoframeGray?=?rgb2gray(videoframe);
????if?numPts?10
????????%?Detection?mode.
????????bbox?=?faceDetector.step(videoframeGray);
????????if?~isempty(bbox)
????????????%?Find?corner?points?inside?the?detected?region.
????????????points?=?detectMinEigenFeatures(videoframeGray?‘ROI‘?bbox(1?:));
????????????%?Re-initialize?the?point?tracker.
????????????xyPoints?=?points.Location;
????????????numPts?=?size(xyPoints1);
????????????release(pointTracker);
????????????initialize(pointTracker?xyPoints?videoframeGray);
????????????%?Save?a?copy?of?the?points.
????????????oldPoints?=?xyPoints;
????????????%?Convert?the?rectangle?represented?as?[x?y?w?h]?into?an
????????????%?M-by-2?matrix?of?[xy]?coordinates?of?the?four?corners.?This
????????????%?is?needed?to?be?able?to?transform?the?bounding?box?to?display
????????????%?the?orientation?of?the?face.
????????????bboxPoints?=?bbox2points(bbox(1?:));
????????????%?Convert?the?box?corners?into?the?[x1?y1?x2?y2?x3?y3?x4?y4]
????????????%?format?required?by?insertShape.
????????????bboxPolygon?=?reshape(bboxPoints‘
評論
共有 條評論