0
0
Computer Visionml~20 mins

Motion detection basics in Computer Vision - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Motion Detection Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
What is the main purpose of background subtraction in motion detection?

Background subtraction is a common technique in motion detection. What does it primarily help to achieve?

AIt isolates moving objects by removing the static background from video frames.
BIt enhances the color saturation of moving objects in the video.
CIt increases the frame rate of the video to detect faster motion.
DIt compresses the video to reduce storage space.
Attempts:
2 left
💡 Hint

Think about how motion detection separates moving parts from the rest.

Predict Output
intermediate
2:00remaining
What is the output of this motion detection code snippet?

Consider this Python code using OpenCV for simple motion detection:

import cv2
cap = cv2.VideoCapture('video.mp4')
ret, frame1 = cap.read()
ret, frame2 = cap.read()
diff = cv2.absdiff(frame1, frame2)
gray = cv2.cvtColor(diff, cv2.COLOR_BGR2GRAY)
_, thresh = cv2.threshold(gray, 25, 255, cv2.THRESH_BINARY)
count = cv2.countNonZero(thresh)
print(count)

What does the printed count represent?

AThe total number of pixels in the video frame.
BThe average brightness of the current frame.
CThe number of pixels that changed significantly between two consecutive frames.
DThe number of frames processed so far.
Attempts:
2 left
💡 Hint

Look at what cv2.countNonZero counts after thresholding the difference.

Model Choice
advanced
2:00remaining
Which model is best suited for detecting motion in a video with changing lighting conditions?

You want to detect motion in a video where lighting changes frequently, like clouds passing over the sun. Which approach is best?

ABackground subtraction using a Gaussian Mixture Model (GMM).
BSimple frame differencing between consecutive frames.
CUsing a fixed threshold on grayscale pixel differences.
DApplying edge detection on each frame without background modeling.
Attempts:
2 left
💡 Hint

Consider models that adapt to gradual background changes.

Metrics
advanced
2:00remaining
Which metric best evaluates the accuracy of a motion detection algorithm?

You have ground truth masks showing where motion occurs and your algorithm's predicted masks. Which metric best measures how well your algorithm detects motion?

ANumber of detected moving objects.
BIntersection over Union (IoU) between predicted and ground truth motion areas.
CFrame rate of the video processing.
DMean Squared Error (MSE) between pixel intensities.
Attempts:
2 left
💡 Hint

Think about how to compare predicted and actual motion regions.

🔧 Debug
expert
3:00remaining
Why does this motion detection code fail to detect motion correctly?

Review this Python code snippet for motion detection:

import cv2
cap = cv2.VideoCapture('video.mp4')
ret, frame1 = cap.read()
while True:
    ret, frame2 = cap.read()
    diff = cv2.absdiff(frame1, frame2)
    gray = cv2.cvtColor(diff, cv2.COLOR_BGR2GRAY)
    _, thresh = cv2.threshold(gray, 30, 255, cv2.THRESH_BINARY)
    count = cv2.countNonZero(thresh)
    if count > 5000:
        print('Motion detected')
    frame1 = frame2
    if cv2.waitKey(30) & 0xFF == 27:
        break
cap.release()

Why might this code miss some motion events?

AThe code does not convert frames to grayscale before differencing.
BThe threshold value is too low, causing false positives.
CIt updates <code>frame1</code> incorrectly inside the loop.
DIt does not handle the case when <code>ret</code> is False, causing errors on last frames.
Attempts:
2 left
💡 Hint

Check what happens when the video ends or frame reading fails.