【问题标题】:Resize Frame for Optical Flow调整光流的帧大小
【发布时间】:2016-07-08 17:56:23
【问题描述】:

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

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 System 对象将在未来的版本中删除。 se.mathworks.com/help/vision/ref/opticalflow-class.html 替代品对我更有吸引力。也就是说,您应该从抽取的fraRes 计算流量,然后裁剪流量 (of)。但也许你想指出确切的错误线。我只是猜测。
  • 替代方案的工作方式与实现的方式相同,它只是实现的方法,一旦我能够裁剪面部并将光流应用到其上,我将尝试这些方法。我可以这样做,但是光流在较小的图像上计算得更快,我认为它会更精确,而不是在我只对面部区域感兴趣的完整视频上进行。

标签: matlab image-processing computer-vision matlab-cvst opticalflow


【解决方案1】:

更新:我去编辑了创建线条的光流函数,这解决了一些尺寸问题,但是有必要为每个对象手动输入这个(所以如果有任何其他方式让我知道)。我认为最好的解决方案是将固定大小设置为 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

【讨论】:

  • 您的视频帧有什么特点?为什么需要调整它们的大小?
  • 它们太大了,因为视频文件为 1080x1920,而且人脸检测器在更小尺寸的帧上效果更好,因为它更精确。我认为可以使用vision.VideoFileWriter 更改视频大小的某些属性,但是我不知道它将其压缩到首选大小的效果如何。
  • 我使用scaleFactor 使它更稳定,但似乎框架在不断调整大小和移动。也许如果左上角的像素在第一帧被识别并应用于其他帧以稳定它以获得完美的结果但不确定。
  • 那你为什么不重新缩放你的图像呢?
  • 我不是说重新缩放,你为什么不更新你的分辨率更短?
猜你喜欢
  • 2016-06-29
  • 1970-01-01
  • 2020-03-12
  • 2012-11-07
  • 2011-03-31
  • 2011-09-04
  • 2011-10-13
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多