Contour Detection
**Problem Statement:** Given an image, find the contours in the image. A contour is a continuous sequence of pixels that form a shape.
Example:
Suppose we have an image represented as a 2D array:
image = np.array([[0, 0, 255, 255],
[0, 255, 255, 0],
[255, 0, 0, 255]])
The contours in this image are two shapes: one with pixels (0, 0), (0, 1), (0, 2), (0, 3), (1, 0), (1, 1), (1, 2), (1, 3), (2, 0), (2, 1), (2, 2), (2, 3), (3, 0), (3, 1), (3, 2), (3, 3) and another with pixels (0, 1), (1, 1), (2, 1), (3, 1).
**Constraints:** The input image is a 2D array of color values (BGR).
**Solution:** Write a function to find the contours in the given image.
Test Cases
Test Case 1
Input:
[[0, 0, 255, 255], [0, 255, 255, 0], [255, 0, 0, 255]]Expected:
[[[[0 0]
[[0 1]
[[0 2]
[[0 3]
[[1 0]
[[1 1]
[[1 2]
[[1 3]
[[2 0]
[[2 1]
[[2 2]
[[2 3]
[[3 0]
[[3 1]
[[3 2]
[[3 3]]
[[[0 1]
[[1 1]
[[2 1]
[[3 1]]]]Test Case 2
Input:
[[255, 255, 255, 255], [255, 255, 255, 255], [255, 255, 255, 255]]Expected:
[[]]+ 3 hidden test cases