You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: fback_demo.m
    path of file: ./repos/mexopencv/samples
    
    the code of the file until where you have to start completion: %% Farneback Optical Flow
% This program demonstrates dense optical flow algorithm by Gunnar Farneback,
% mainly the function |cv.calcOpticalFlowFarneback|.
% It captures from the camera by default.
%
% Sources:
%
% * <https://github.com/opencv/opencv/blob/3.2.0/samples/cpp/fback.cpp>
%

%% Input video
% setup video capture
cap = cv.VideoCapture();
pause(1);
assert(cap.isOpened(), 'Could not initialize capturing');

%%
% grab first frame
frame = cap.read();
assert(~isempty(frame), 'Could not read frame');
prev = cv.cvtColor(frame, 'RGB2GRAY');

%% Prepare
% grid over which to plot vector field
step = 16;  % subsample in x/y direction
    
function |cv.calcOpticalFlowFarneback|.
% It captures from the camera by default.
%
% Sources:
%
% * <https://github.com/opencv/opencv/blob/3.2.0/samples/cpp/fback.cpp>
%

%% Input video
% setup video capture
cap = cv.VideoCapture();
pause(1);
assert(cap.isOpened(), 'Could not initialize capturing');

%%
% grab first frame
frame = cap.read();
assert(~isempty(frame), 'Could not read frame');
prev = cv.cvtColor(frame, 'RGB2GRAY');

%% Prepare
% grid over which to plot vector field
step = 16;  % subsample in x/y directions for less dense plot
sz = size(frame);
xstep = 1:step:sz(2);
ystep = 1:step:sz(1);
[X,Y] = meshgrid(xstep, ystep);

%%
% plot
out = frame;
hImg = imshow(out);
hold on
hQ = quiver(X(:), Y(:), X(:)*0, Y(:)*0, 0, 'Color','g');
hold off, title('Farneback [Dense]')

%% Main loop
counter = 0;
tid = tic();
while ishghandle(hImg)
    % grab frame
    counter = counter + 1;
    frame = cap.read();
    if isempty(frame), break; end