Complete the code to load images from a folder using OpenCV.
import cv2 image = cv2.imread([1]) print(image.shape)
You need to provide the image filename as a string to cv2.imread(). So, it must be in quotes.
Complete the code to create a list of image file paths from a directory using pathlib.
from pathlib import Path image_dir = Path('images') image_files = list(image_dir.glob([1])) print(len(image_files))
The glob method needs a pattern string with a wildcard and file extension, like '*.jpg', to find all JPG files.
Fix the error in this code that reads bounding box annotations from a CSV file.
import pandas as pd annotations = pd.read_csv([1]) print(annotations.head())
The filename must be a string in quotes when passed to pd.read_csv().
Fill both blanks to create a dictionary of image filenames and their bounding boxes from a DataFrame.
bbox_dict = {row[[1]]: (row['xmin'], row['ymin'], row['xmax'], row[[2]]) for _, row in annotations.iterrows()}The dictionary key is the filename from the 'filename' column. The bounding box tuple uses 'xmin', 'ymin', 'xmax', and 'ymax' columns. Here, the last blank should be 'ymax'.
Fill all three blanks to filter annotations for a specific class and create a list of bounding boxes.
class_name = 'cat' filtered = annotations[annotations[[1]] == [2]] bboxes = [(row['xmin'], row['ymin'], row[[3]], row['ymax']) for _, row in filtered.iterrows()]
We filter rows where the 'class' column equals 'cat'. Then we extract bounding boxes using 'xmin', 'ymin', 'xmax', and 'ymax'. The third blank is 'xmax'.