Why OpenCV's Opticalflow return flows between the exactly same pictures?

Viewed 40

I use opencv Opticalflow function (cv2.calcOpticalFlowFarneback) to compare two images were moved or not. I think it shouldn't be found flow between exatly same picture files, But flow were occured. what happened?

SAMPLE IMAGE

SAMPLE RESULT

source code

from utils.compute_optical_flow import *
import cv2
import os



def compute_dense_optical_flow(prev_image, current_image):
    old_shape = current_image.shape
    prev_image_gray = cv2.cvtColor(prev_image, cv2.COLOR_BGR2GRAY)
    current_image_gray = cv2.cvtColor(current_image, cv2.COLOR_BGR2GRAY)
    assert current_image.shape == old_shape
    hsv = np.zeros_like(prev_image)
    hsv[..., 1] = 255
    flow = None
    flow = cv2.calcOpticalFlowFarneback(prev=prev_image_gray,
                                      next=current_image_gray, flow=flow,
                                      pyr_scale=0.8, levels=15, winsize=5,
                                      iterations=10, poly_n=5, poly_sigma=0,
                                      flags=10)

    mag, ang = cv2.cartToPolar(flow[..., 0], flow[..., 1])
    hsv[..., 0] = ang * 180 / np.pi / 2
    hsv[..., 2] = cv2.normalize(mag, None, 0, 255, cv2.NORM_MINMAX)
    return cv2.cvtColor(hsv, cv2.COLOR_HSV2BGR)


now_path = os.path.dirname(os.path.abspath(__file__))

img_one = cv2.imread(now_path + "/tests/t.jpg")
img_two = cv2.imread(now_path + "/tests/t.jpg")

flow_img = compute_dense_optical_flow(img_one, img_one)
cv2.imwrite(now_path + "/tests/result_t.jpg",flow_img)

0 Answers
Related