← 返回 pinterest 的题目列表Count Objects in Image Using Recursive Pixel Grouping
类型:online_judge
pinterest
Given a grid of pixels representing an image where some pixels are part of objects in the image, use the provided functions to count the number of objects in the given image.
class Pixel:
def __init__(self, x: int, y: int):
self.x = x
self.y = y
def createPin(width, height):
return [[Pixel(x, y) for x in range(width)] for y in range(height)]
def isSameObject(p1: Pixel, p2: Pixel) -> bool:
# Returns True if pixels p1 and p2 are part of the same object
pass
Requirements:
Implement object counting using a recursive function.
Output the number of objects.
Support a 20x20 pixel grid.
Example
Input
grid = createPin(20, 20)