Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to load an image for OCR processing.
Computer Vision
image = cv2.imread([1]) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a number instead of a filename string
Passing None instead of a filename
✗ Incorrect
The cv2.imread function loads an image file given its filename as a string.
2fill in blank
mediumComplete the code to convert the image to grayscale before OCR.
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 color conversions that do not produce grayscale images
✗ Incorrect
Converting to grayscale uses cv2.COLOR_BGR2GRAY to simplify the image for OCR.
3fill in blank
hardFix the error in the OCR text extraction line.
Computer Vision
text = pytesseract.image_to_string([1]) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the original image instead of the grayscale
Passing the module name instead of an image
✗ Incorrect
The OCR function should process the grayscale image, not the original color image or modules.
4fill in blank
hardFill both blanks to create a dictionary with word lengths greater than 3.
Computer Vision
word_lengths = {word: [1] for word in text.split() if len(word) [2] 3} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong comparison operator
Storing the word instead of its length
✗ Incorrect
This dictionary comprehension stores the length of each word only if the word length is greater than 3.
5fill in blank
hardFill all three blanks to filter words starting with 'a' and count them.
Computer Vision
filtered_words = [word[1] for word in text.split() if word[2]'a')] count = [3](filtered_words)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using endswith instead of startswith
Not converting to lowercase
Not counting the filtered list
✗ Incorrect
This code filters words starting with 'a' (case-insensitive) and counts them using len().