I have computed an optical flow and I wish to convert this to images.
Following the tutorials of opencv2:
mag, ang = cv2.cartToPolar(flow[...,0], flow[...,1])
hsv = np.zeros_like(cv2.imread(img_path))
hsv[...,1] = 255
hsv[...,0] = ang*180/np.pi/2
hsv[...,2] = cv2.normalize(mag,None,0,255,cv2.NORM_MINMAX)
bgr = cv2.cvtColor(hsv,cv2.COLOR_HSV2BGR)
cv2.imshow('optical flow',bgr)
I am able to do this, however the RGB image is not as smooth and continuous as the one that comes with more recent papers: such as T. Brox's High Accuracy Optical Flow Estimation Based on a Theory for Warping or FlowNet which looks like smooth, continuous regions as seen here: https://www.youtube.com/watch?v=JSzUdVBmQP4
Any recommendations how I can achieve this conversion instead of what I am doing (opencv tutorial)?
I have found a piece of Matlab script that might be achieving the latter one, but I do not understand how the conversion is made. Can someone explain?
flow = mex_OF(double(im1),double(im2));
scale = 16;
mag = sqrt(flow(:,:,1).^2+flow(:,:,2).^2)*scale+128;
mag = min(mag, 255);
flow = flow*scale+128;
flow = min(flow,255);
flow = max(flow,0);
[x,y,z] = size(flow);
flow_image = zeros(x,y,3);
flow_image(:,:,1:2) = flow;
flow_image(:,:,3) = mag;
imwrite(flow_image./255,sprintf('%s/%s/flow_image_%s',save_base,video,frames{k}))
Thank you.