Spaces:
Running
Running
Sagar Bharadwaj
commited on
Commit
·
775d79d
1
Parent(s):
c850ed8
Added draw contours utility function
Browse files- colorbynumber/utils.py +12 -0
colorbynumber/utils.py
CHANGED
@@ -1,4 +1,6 @@
|
|
|
|
1 |
from matplotlib import pyplot as plt
|
|
|
2 |
|
3 |
def show_image(image, cmap = None):
|
4 |
if cmap:
|
@@ -8,3 +10,13 @@ def show_image(image, cmap = None):
|
|
8 |
plt.axis('off')
|
9 |
plt.show()
|
10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import cv2 as cv
|
2 |
from matplotlib import pyplot as plt
|
3 |
+
import numpy as np
|
4 |
|
5 |
def show_image(image, cmap = None):
|
6 |
if cmap:
|
|
|
10 |
plt.axis('off')
|
11 |
plt.show()
|
12 |
|
13 |
+
def draw_contours(contour, image_width, image_height):
|
14 |
+
contours_image = np.ones((image_width, image_height), dtype = np.uint8)
|
15 |
+
if type(contour) == tuple:
|
16 |
+
# If the contour is a tuple, it is a tuple of multiple contours
|
17 |
+
cv.drawContours(contours_image, contour, -1, (0,255,0), 4)
|
18 |
+
else:
|
19 |
+
# Else, it is a single contour
|
20 |
+
cv.drawContours(contours_image, [contour], 0, (0,255,0), 4)
|
21 |
+
show_image(contours_image, cmap = 'gray')
|
22 |
+
|