Skip to content
DeepForgeby svx
All problems
HardComputer Visioncv-118

Lucas-Kanade Single Pixel

Problem

Solve the Lucas-Kanade optical flow equation for one window.

Accumulate the 2x2 structure matrix A from the spatial gradients ix and iy (sum of ix^2, ix*iy, iy^2) and the vector b = [-sum(ix * it), -sum(iy * it)], then return (u, v) = A^-1 b rounded to 4 decimal places. Return [0.0, 0.0] when the determinant is 0.

Hint

Singular windows carry no flow information, so return zeros.

Test cases

case 1
in: [[[1,1,1],[1,1,1],[1,1,1]],[[0,0,0],[1,1,1],[2,2,2]],[[-1,-1,-1],[-1,-1,-1],[-1,-1,-1]]]
expected: [1,0]
case 2
in: [[[1,1,1],[1,1,1],[1,1,1]],[[0,0,0],[1,1,1],[2,2,2]],[[-2,-2,-2],[-2,-2,-2],[-2,-2,-2]]]
expected: [2,0]
case 3
in: [[[1,1,1],[1,1,1],[1,1,1]],[[0,0,0],[0,0,0],[0,0,0]],[[-1,-1,-1],[-1,-1,-1],[-1,-1,-1]]]
expected: [0,0]
case 4
in: [[[1,0,0],[0,1,0],[0,0,1]],[[0,0,0],[0,0,0],[0,0,1]],[[-1,-1,-1],[-1,-1,-1],[-1,-1,-1]]]
expected: [1,0]
Starter codePython
def lucas_kanade_pixel(ix, iy, it):
    # Your code here
    pass

4 test cases · run your code against them in the editor