0
0
Computer Visionml~10 mins

Optical flow concept in Computer Vision - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to calculate the optical flow using Lucas-Kanade method.

Computer Vision
flow = cv2.calcOpticalFlow[1](prev_gray, next_gray, None, lk_params['winSize'], lk_params['maxLevel'], lk_params['criteria'])
Drag options to blanks, or click blank then click option'
APyrLK
BFarneback
CSparse
DDense
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Farneback' instead of 'PyrLK' for sparse optical flow.
Confusing dense and sparse optical flow methods.
2fill in blank
medium

Complete the code to convert a video frame to grayscale for optical flow calculation.

Computer Vision
gray_frame = cv2.cvtColor(frame, [1])
Drag options to blanks, or click blank then click option'
Acv2.COLOR_RGB2GRAY
Bcv2.COLOR_BGR2RGB
Ccv2.COLOR_BGR2GRAY
Dcv2.COLOR_GRAY2BGR
Attempts:
3 left
💡 Hint
Common Mistakes
Using RGB conversion instead of grayscale.
Not converting the frame to grayscale before optical flow.
3fill in blank
hard

Fix the error in the code to calculate the magnitude and angle of optical flow vectors.

Computer Vision
magnitude, angle = cv2.cartToPolar(flow[..., 0], flow[..., [1]], angleInDegrees=True)
Drag options to blanks, or click blank then click option'
A1
B3
C2
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using index 2 or 3 which are out of bounds.
Using the same index 0 for both components.
4fill in blank
hard

Fill both blanks to create a mask image that visualizes optical flow direction and magnitude.

Computer Vision
mask = np.zeros_like(frame)
mask[..., [1]] = angle / 2
mask[..., [2]] = 255
Drag options to blanks, or click blank then click option'
A0
B1
C2
D3
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing channel indices for HSV color space.
Setting saturation to zero instead of 255.
5fill in blank
hard

Fill all three blanks to convert the mask to BGR color and display it with OpenCV.

Computer Vision
rgb_flow = cv2.cvtColor(mask, [1])
cv2.imshow('Optical Flow', rgb_flow)
cv2.waitKey([2])
cv2.destroyAllWindows()

# Wait time of [3] milliseconds allows frame update
Drag options to blanks, or click blank then click option'
Acv2.COLOR_BGR2HSV
Bcv2.COLOR_HSV2BGR
Ccv2.COLOR_RGB2BGR
Dcv2.COLOR_GRAY2BGR
E0
F1
G30
H100
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong color conversion codes.
Using waitKey(1) or waitKey(100) which may be too fast or slow.