0
0
Computer Visionml~10 mins

Motion detection basics 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 read a video frame using OpenCV.

Computer Vision
ret, frame = cap.[1]()
Drag options to blanks, or click blank then click option'
Aread
Bgrab
Ccapture
Dfetch
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'capture()' which is not a valid OpenCV method for reading frames.
Using 'grab()' which only grabs the frame but does not decode it.
Using 'fetch()' which does not exist in OpenCV.
2fill in blank
medium

Complete the code to convert a frame to grayscale for motion detection.

Computer Vision
gray = cv2.[1](frame, cv2.COLOR_BGR2GRAY)
Drag options to blanks, or click blank then click option'
AtransformColor
BconvertColor
CchangeColor
DcvtColor
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'convertColor' which is not the exact OpenCV function name.
Using 'changeColor' or 'transformColor' which do not exist.
3fill in blank
hard

Fix the error in the code to compute the absolute difference between two frames.

Computer Vision
diff = cv2.[1](frame1, frame2)
Drag options to blanks, or click blank then click option'
Aabsdiff
BabsDiff
CabsoluteDifference
Dabs_diff
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect capitalization like 'absDiff'.
Using non-existent functions like 'absoluteDifference' or 'abs_diff'.
4fill in blank
hard

Fill both blanks to threshold the difference image and find contours.

Computer Vision
ret, thresh = cv2.[1](diff, 25, 255, cv2.[2])
contours, _ = cv2.findContours(thresh, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
Drag options to blanks, or click blank then click option'
Athreshold
BTHRESH_BINARY
CadaptiveThreshold
DTHRESH_OTSU
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'adaptiveThreshold' which requires different parameters.
Using 'THRESH_OTSU' which is a flag for Otsu's method, not binary threshold.
5fill in blank
hard

Fill all three blanks to draw rectangles around detected motion areas.

Computer Vision
for contour in contours:
    if cv2.contourArea(contour) > [1]:
        (x, y, w, h) = cv2.[2](contour)
        cv2.[3](frame, (x, y), (x + w, y + h), (0, 255, 0), 2)
Drag options to blanks, or click blank then click option'
A500
BboundingRect
Crectangle
DcontourArea
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'contourArea' as a function call in the wrong place.
Using wrong function names like 'contourRect' or 'drawRect'.