速度矢量(光流等)到RGB颜色转换

时间:2019-01-16 16:22:11

标签: python matlab rgb motion opticalflow

我已经计算了光流,希望将其转换为图像。

遵循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)

我能够做到这一点,但是RGB图像不如最近的论文所提供的那样平滑和连续:例如T. Brox基于翘曲理论或FlowNet的高精度光流估计就像这里连续的平滑区域一样:https://www.youtube.com/watch?v=JSzUdVBmQP4

有人建议我如何实现这种转换而不是我在做什么(opencv教程)?

我发现了一段Matlab脚本可能会实现后者,但是我不了解如何进行转换。有人可以解释吗?

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

谢谢。

0 个答案:

没有答案