Complete the code to load an image for real-time processing on an edge device.
import cv2 image = cv2.imread([1])
The cv2.imread function requires the image file path as a string, so it must be enclosed in quotes.
Complete the code to convert the image to grayscale for faster edge processing.
gray_image = cv2.cvtColor(image, [1])To convert a BGR image to grayscale, use cv2.COLOR_BGR2GRAY.
Fix the error in the code to perform edge detection using Canny on the grayscale image.
edges = cv2.Canny([1], 100, 200)
Canny edge detection requires a single-channel (grayscale) image, so we must use gray_image.
Fill both blanks to create a dictionary comprehension that maps each pixel coordinate to its edge value if the edge value is greater than zero.
edge_points = {(x, y): [1][y, x] for y in range(edges.shape[0]) for x in range(edges.shape[1]) if [2][y, x] > 0}We want to map coordinates to their edge values, so both blanks should use the edges array.
Fill all three blanks to create a function that runs edge detection on an input image and returns the edge points dictionary.
def detect_edges([1]): gray = cv2.cvtColor([2], cv2.COLOR_BGR2GRAY) edges = cv2.Canny(gray, 50, 150) return {(x, y): edges[y, x] for y in range(edges.shape[0]) for x in range(edges.shape[1]) if edges[y, x] > [3]
The function takes input_image as input, converts it to grayscale, detects edges, and returns points where edge value is greater than 0.