forked from maciejczyzewski/neural-chessboard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
debug.py
53 lines (40 loc) · 1.41 KB
/
debug.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from config import *
from random import randint
from copy import copy
import numpy as np
import cv2; load = cv2.imread
save = cv2.imwrite
################################################################################
def lines(img, lines, color=(0,0,255), size=2):
"""draw lines"""
for a, b in lines: cv2.line(img,tuple(a),tuple(b),color,size)
return img
def points(img, points, color=(0,0,255), size=10):
"""draw points"""
for pt in points: cv2.circle(img,(int(pt[0]),int(pt[1])),size,color,-1)
return img
def color():
return (randint(0, 255), randint(0, 255), randint(0, 255))
################################################################################
counter = 0
class ImageDebug(object):
img = object
def __init__(self, img):
if isinstance(img, tuple):
img = np.zeros((img[0], img[1], 3), np.uint8)
if len(img.shape) < 3:
img = cv2.cvtColor(img, cv2.COLOR_GRAY2RGB)
self.img = copy(img)
def lines(self, _lines, color=(0,0,255), size=2):
self.img = lines(self.img, _lines, color=color, size=size)
return self
def points(self, _points, color=(0,0,255), size=10):
self.img = points(self.img, _points, color=color, size=size)
return self
def save(self, filename, prefix=True):
global counter; counter += 1
if prefix: __prefix = "__debug_"+"%04d"%int(counter)+"_"
else: __prefix = ""
if NC_DEBUG: save("test/steps/" + __prefix + \
filename + ".jpg", self.img)
image = ImageDebug