-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcalibration.py
111 lines (89 loc) · 3.28 KB
/
calibration.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#! /usr/bin/env python2
# -*- coding: utf-8 -*-
import cv2
import numpy as np
import time
import Tkinter as tk
class Calibrator(object):
def __init__(self):
self.blue_min = 0
self.green_min = 0
self.red_min = 0
self.blue_max = 0
self.green_max = 0
self.red_max = 0
def set_blue_min(self, val):
self.blue_min = int(val)
def set_green_min(self, val):
self.green_min = int(val)
def set_red_min(self, val):
self.red_min = int(val)
def set_blue_max(self, val):
self.blue_max = int(val)
def set_green_max(self, val):
self.green_max = int(val)
def set_red_max(self, val):
self.red_max = int(val)
def calibrate(self, im, colors):
root = tk.Tk()
bmin, gmin, rmin = colors.colors['min']
min_target_color = np.array([bmin,gmin,rmin])
bmax, gmax, rmax = colors.colors['max']
blue_min_scale = tk.Scale(
master=root,
to=255,
command=self.set_blue_min,
label='Bmin')
blue_min_scale.set(bmin)
green_min_scale = tk.Scale(
master=root,
to=255,
command=self.set_green_min,
label='Gmin')
green_min_scale.set(gmin)
red_min_scale = tk.Scale(
master=root,
to=255,
command=self.set_red_min,
label='Rmin')
red_min_scale.set(rmin)
red_min_scale.pack(side=tk.LEFT)
green_min_scale.pack(side=tk.LEFT)
blue_min_scale.pack(side=tk.LEFT)
blue_max_scale = tk.Scale(
master=root,
to=255,
command=self.set_blue_max,
label='Bmax')
blue_max_scale.set(bmax)
green_max_scale = tk.Scale(
master=root,
to=255,
command=self.set_green_max,
label='Gmax')
green_max_scale.set(gmax)
red_max_scale = tk.Scale(
master=root,
to=255,
command=self.set_red_max,
label='Rmax')
red_max_scale.set(rmax)
red_max_scale.pack(side=tk.LEFT)
green_max_scale.pack(side=tk.LEFT)
blue_max_scale.pack(side=tk.LEFT)
root.mainloop()
colors = Colors(
self.blue_min,
self.green_min,
self.red_min,
self.blue_max,
self.green_max,
self.red_max)
return colors
class Colors(object):
def __init__(self,b,g,r,bm,gm,rm):
self.colors = {}
min_color = (b,g,r)
max_color = (bm,gm,rm)
self.colors['min'] = min_color
self.colors['max'] = max_color