繁体   English   中英

调整光流框架的大小

[英]Resize Frame for Optical Flow

如果以任何方式操纵帧大小,我就会遇到光流问题,这会给我带来错误。 有两种选择,要么在开始时更改视频的分辨率,要么以某种方式以光流工作的方式更改帧大小。 在进一步的开发中,我想添加一个级联对象来检测鼻子、嘴巴和眼睛,因此我需要解决方案,该解决方案适用于各个区域,而无需为这些区域单独设置光流,尤其是边界框没有固定大小并且它将在帧与帧之间略微移动。 到目前为止,这是我的代码,错误在于它超出了矩阵维度。

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);

更新:我去编辑了创建线条的光流函数,这解决了一些尺寸问题,但是有必要为每个对象手动输入这个(所以如果有任何其他方式让我知道)。 我认为最好的解决方案是为cascadeObjectDetector 设置一个固定大小,有谁知道如何做到这一点? 或者有什么其他想法?

faceDetector = vision.CascadeObjectDetector(); %I need fixed size for this
faceDetector.MinSize = [150 150];

vidRead = vision.VideoFileReader('MEXTest.mp4','ImageColorSpace','Intensity','VideoOutputDataType','uint8');
convert = vision.ImageDataTypeConverter; 
optFlo = vision.OpticalFlow('ReferenceFrameDelay', 1);
optFlo.OutputValue = 'Horizontal and vertical components in complex form';
shapeInserter = vision.ShapeInserter('Shape','Lines','BorderColor','Custom',  'CustomBorderColor', 255);

while ~isDone(vidRead)
    frame = step(vidRead);
    fraRes = imresize(frame,0.3);
    fraSin = im2single(fraRes);

    bbox = step(faceDetector,fraSin);

    I = imcrop(fraSin, bbox); 

    im = step(convert, I); 
    release(optFlo);
    of = step(optFlo, im);
    lines = optfloo(of, 50); %use videooptflowlines instead of (optfloo)
    out =  step(shapeInserter, im, lines); 
    imshow(out);
end

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM