如果以任何方式操作了框架大小,我都會遇到光流問題,從而導致出錯。有兩個選項可以在開始時更改視頻的分辨率,或者以某種方式改變幀大小,從而以光流的方式工作。我希望在進一步的開發中添加級聯對象來檢測鼻子,嘴巴和眼睛,因此我需要解決方案,它可以用於單個區域,而無需爲這些區域單獨設置光流,特別是邊界框不具有固定大小,將在框架之間輕微置換。這是我的代碼到目前爲止,錯誤是它超過矩陣尺寸。調整光流大小的框架
faceDetector = vision.CascadeObjectDetector();
vidObj = vision.VideoFileReader('MEXTest.mp4','ImageColorSpace','Intensity','VideoOutputDataType','uint8');
converter = vision.ImageDataTypeConverter;
opticalFlow = vision.OpticalFlow('ReferenceFrameDelay', 1);
opticalFlow.OutputValue = 'Horizontal and vertical components in complex form';
shapeInserter = vision.ShapeInserter('Shape','Lines','BorderColor','Custom','CustomBorderColor', 255);
vidPlayer = vision.VideoPlayer('Name','Motion Vector');
while ~isDone(vidObj);
frame = step(vidObj);
fraRes = imresize(frame,0.5);
fbbox = step(faceDetector,fraRes);
I = imcrop(fraRes,fbbox);
im = step(converter,I);
of = step(opticalFlow,im);
lines = videooptflowlines(of, 20);
if ~isempty(lines)
out = step(shapeInserter,im,lines);
step(vidPlayer,out);
end
end
release(vidPlayer);
release(VidObj);
'vision.opticalFlow'系統對象將在未來版本中刪除。 http://se.mathworks.com/help/vision/ref/opticalflow-class.html替代品對我更有吸引力。也就是說,你應該從抽取的「fraRes」計算流量,然後裁剪流量('')。但是,也許你想指出錯誤的確切路線。我只是猜測。 – mainactual
這些替代品的工作方式與實施方法相同,只是實施方法,我會嘗試那些能夠裁剪臉部並將光流應用到臉部的方法。我可以做到這一點,但是光流量會在較小的圖像上計算得更快,我認爲這會更精確,而不是在完整的視頻中進行,而我只對臉部區域感興趣。 – UZIERSKI