Skip to content

Commit 51470b7

Browse files
committed
1.1.3
1 parent 415cc74 commit 51470b7

File tree

11 files changed

+1810
-0
lines changed

11 files changed

+1810
-0
lines changed

build/lib/pcv/__init__.py

Whitespace-only changes.

build/lib/pcv/interact.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env python3
2+
3+
import cv2
4+
5+
6+
waitKey = lambda ms : cv2.waitKey(ms) & 0xFF
7+
8+
9+
class DoNothing:
10+
''' A context manager that does nothing. '''
11+
def __init__(self): pass
12+
def __enter__(self): return self
13+
def __exit__(self, *args): pass
14+
15+
16+
class MouseCallback:
17+
''' A context manager for temporary mouse callbacks. '''
18+
def __init__(self, window, handler, param=None,
19+
restore=lambda *args: None, restore_param=None):
20+
''' Initialise with the window, handler, and restoration command.
21+
22+
'window' is the name of the window to set the callback for.
23+
'handler' is the function for handling the callback, which should take
24+
x, y, flags ('&'ed EVENT_FLAG bits), and an optional param passed
25+
in from the callback handler.
26+
'param' is any Python object that should get passed to the handler
27+
on each call - useful for tracking state.
28+
'restore' is the function to restore as the handler on context exit.
29+
'restore_param' is the handler param to restore on context exit.
30+
31+
'''
32+
self.window = window
33+
self.handler = handler
34+
self.param = param
35+
self.restore = restore
36+
self.restore_param = restore_param
37+
38+
def __enter__(self):
39+
cv2.setMouseCallback(self.window, self.handler, self.param)
40+
return self
41+
42+
def __exit__(self, *args):
43+
cv2.setMouseCallback(self.window, self.restore, self.restore_param)

build/lib/pcv/process.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/env python3
2+
3+
import cv2
4+
5+
def downsize(img, ratio):
6+
''' downsize 'img' by 'ratio'. '''
7+
return cv2.resize(img,
8+
tuple(dim // ratio for dim in reversed(img.shape[:2])),
9+
interpolation = cv2.INTER_AREA)
10+
11+
def channel_options(img):
12+
''' Create a composite image of img in all of opencv's colour channels
13+
14+
|img| -> | blue | green | red |
15+
| hue | saturation | value |
16+
| hue2 | luminosity | saturation2 |
17+
| lightness | green-red | blue-yellow |
18+
| lightness2 | u | v |
19+
20+
'''
21+
B,G,R = cv2.split(img)
22+
H,S,V = cv2.split(cv2.cvtColor(img, cv2.COLOR_BGR2HSV))
23+
H2,L2,S2 = cv2.split(cv2.cvtColor(img, cv2.COLOR_BGR2HLS))
24+
L,a,b = cv2.split(cv2.cvtColor(img, cv2.COLOR_BGR2LAB))
25+
L3,u,v = cv2.split(cv2.cvtColor(img, cv2.COLOR_BGR2LUV))
26+
channels = (((B, 'blue'), (G, 'green'), (R, 'red')),
27+
((H, 'hue'), (S, 'saturation'), (V, 'value')),
28+
((H2, 'hue2'), (L2, 'luminosity'), (S2, 'saturation2')),
29+
((L, 'lightness'), (a, 'green-red'), (b, 'blue-yellow')),
30+
((L3,'lightness2'), (u, 'u'), (v, 'v')))
31+
out = []
32+
for row in channels:
33+
img_row = []
34+
for img, name in row:
35+
cv2.putText(img, name, (10, 30), cv2.FONT_HERSHEY_SIMPLEX,
36+
0.6, 255, 1)
37+
img_row.append(img)
38+
out.append(cv2.hconcat(img_row))
39+
return cv2.vconcat(out)

0 commit comments

Comments
 (0)