2
votes

I have problem with optical flow if the frame size have been manipulated in any way this gives me error. There are two options either change the resolution of the video at the beginning or somehow how change the frame size in a way that optical flow will work. I will want to add a cascade object to detect nose, mouth and eyes in further development therefore I need solution that will work for individual regions without necessary setting optical flow individually for those regions especially that a bounding box does not have a fixed size and it will displace itself slightly from frame to frame. Here is my code so far, the error is that it is exceeding matrix dimensions.

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);
1
The vision.opticalFlow System object will be removed in a future release. se.mathworks.com/help/vision/ref/opticalflow-class.html The alternatives appeal more to me. That said, you should compute the flow from decimated fraRes and then crop the flow (of). But maybe you want to point out the exact line of error. I'm just guessing.mainactual
The alternatives will work in the same way as the one implemented it is just about method to implement and I will experiment with those once I will be able to crop the face and apply optical flow onto it. I could do that however optical flow will compute faster on a smaller image and I think it would be more precise rather than doing it on a full video where I'm only interested in the face regions.UZIERSKI

1 Answers

2
votes

UPDATE: I went and edited the function for optical flow which creates lines and this sorts out the some size issues however it is necessary to to input this manually for each object (so if there is any other way let me know). I think the best solution would be set a fixed size to cascadeObjectDetector, does anyone know how to do this? Or have any other idea?

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