Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to load an image using OpenCV for table extraction.
Computer Vision
import cv2 image = cv2.[1]('table_image.png')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using cv2.imshow() instead of cv2.imread() to load the image.
Trying to use cv2.imwrite() which saves an image, not loads it.
✗ Incorrect
The function cv2.imread() loads an image from a file into memory, which is the first step in processing an image for table extraction.
2fill in blank
mediumComplete the code to convert the loaded image to grayscale for easier table detection.
Computer Vision
gray_image = cv2.cvtColor(image, [1]) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using cv2.COLOR_BGR2RGB which changes color space but not to grayscale.
Using cv2.COLOR_GRAY2BGR which converts grayscale to color, opposite of what is needed.
✗ Incorrect
Converting the image to grayscale using cv2.COLOR_BGR2GRAY simplifies the image and helps in detecting table structures.
3fill in blank
hardFix the error in the code to detect edges using Canny edge detection for table boundary detection.
Computer Vision
edges = cv2.Canny(gray_image, [1], 150)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Setting the first threshold higher than the second, which causes poor edge detection.
Using very low values that cause too many edges.
✗ Incorrect
The first threshold in Canny edge detection is usually lower than the second. Using 50 and 150 is a common pair for detecting edges effectively.
4fill in blank
hardFill both blanks to apply dilation and find contours for table structure extraction.
Computer Vision
kernel = cv2.getStructuringElement(cv2.MORPH_RECT, ([1], [2])) dilated = cv2.dilate(edges, kernel, iterations=1)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using very large kernel sizes that over-dilate and merge unrelated edges.
Using kernel sizes that are too small to connect table lines.
✗ Incorrect
A rectangular kernel of size (5, 10) is commonly used to dilate edges vertically and horizontally to connect table lines.
5fill in blank
hardFill all three blanks to extract bounding boxes of detected table cells from contours.
Computer Vision
contours, _ = cv2.findContours(dilated, cv2.RETR_EXTERNAL, [1]) bounding_boxes = [cv2.boundingRect(c) for c in contours if cv2.contourArea(c) > [2]] sorted_boxes = sorted(bounding_boxes, key=lambda b: (b[[3]], b[0]))
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using CHAIN_APPROX_NONE which is slower and unnecessary here.
Not filtering small contours causing noise in bounding boxes.
Sorting by x before y which disrupts reading order.
✗ Incorrect
cv2.CHAIN_APPROX_SIMPLE compresses contour points, 1000 filters out small contours, and sorting by b[1] (y-coordinate) then b[0] (x-coordinate) orders boxes top to bottom, left to right.