Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to load an image for text recognition.
Computer Vision
from PIL import Image image = Image.open([1])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting quotes around the filename.
Passing an Image object instead of a filename string.
✗ Incorrect
The Image.open() function requires a string path to the image file, so the filename must be in quotes.
2fill in blank
mediumComplete the code to convert the image to grayscale before text recognition.
Computer Vision
gray_image = image.convert([1]) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'RGB' instead of 'L' for grayscale conversion.
Using modes that keep color channels.
✗ Incorrect
The mode 'L' converts the image to grayscale, which is common preprocessing for text recognition.
3fill in blank
hardFix the error in the code to extract text from the image using pytesseract.
Computer Vision
import pytesseract text = pytesseract.image_to_string([1])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a file path string instead of an image object.
Passing a file object instead of an image.
✗ Incorrect
pytesseract.image_to_string expects an image object, here the grayscale image is best for accurate text extraction.
4fill in blank
hardFill both blanks to create a dictionary of word lengths for words longer than 3 characters.
Computer Vision
words = text.split()
lengths = {word: [1] for word in words if len(word) [2] 3} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using word instead of len(word) for length.
Using '<' instead of '>' for filtering.
✗ Incorrect
We use len(word) to get the length, and filter words with length greater than 3 using '>'.
5fill in blank
hardFill all three blanks to create a dictionary of uppercase words and their lengths for words longer than 4 characters.
Computer Vision
words = text.split()
result = { [1]: [2] for w in words if len(w) [3] 4} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using w instead of w.upper() for keys.
Using '<' instead of '>' for filtering.
✗ Incorrect
We convert words to uppercase for keys, use their length as values, and filter words longer than 4 characters.