0
0
Computer Visionml~10 mins

Table extraction from images 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 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'
Aimshow
Bimread
Cimwrite
Dresize
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.
2fill in blank
medium

Complete 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'
Acv2.COLOR_BGR2GRAY
Bcv2.COLOR_BGR2RGB
Ccv2.COLOR_GRAY2BGR
Dcv2.COLOR_RGB2BGR
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.
3fill in blank
hard

Fix 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'
A50
B200
C300
D10
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.
4fill in blank
hard

Fill 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'
A15
B5
C10
D20
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.
5fill in blank
hard

Fill 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'
Acv2.CHAIN_APPROX_SIMPLE
B1000
C1
Dcv2.CHAIN_APPROX_NONE
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.