-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathImageTool.py
76 lines (60 loc) · 1.98 KB
/
ImageTool.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
import cv
import sys
image = 0
redtrackbar = "R"
greentrackbar = "G"
bluetrackbar = "B"
xtrackbar = "X"
ytrackbar = "Y"
imagewindow = "Image Tool: "
trackbarwindow ="Image Tool: Trackbars"
def foo(x):
return 0
def mousecallback(mouseevent, mousex, mousey, flags, param):
global image
global redtrackbar
global greentrackbar
global bluetrackbar
global Xtrackbar
global Ytrackbar
global imagewindow
global trackbarwindow
if mouseevent == cv.CV_EVENT_LBUTTONDOWN :
scalar = image[mousey, mousex]
cv.SetTrackbarPos(bluetrackbar, trackbarwindow, int(scalar[0]))
cv.SetTrackbarPos(greentrackbar, trackbarwindow, int(scalar[1]))
cv.SetTrackbarPos(redtrackbar, trackbarwindow, int(scalar[2]))
cv.SetTrackbarPos(xtrackbar, trackbarwindow, mousex)
cv.SetTrackbarPos(ytrackbar, trackbarwindow, mousey)
return 0
def main() :
global image
global redtrackbar
global greentrackbar
global bluetrackbar
global Xtrackbar
global Ytrackbar
global imagewindow
global trackbarwindow
if len(sys.argv) != 2 :
print "Usage: " + sys.argv[0] +" <image>"
sys.exit(0)
image = cv.LoadImage(sys.argv[1], 1)
if not image :
print "Unable to load image"
sys.exit(0)
imagewindow += sys.argv[1]
cv.NamedWindow(imagewindow)
cv.NamedWindow(trackbarwindow)
cv.ShowImage(imagewindow, image)
cv.CreateTrackbar(redtrackbar, trackbarwindow, 0, 255, foo)
cv.CreateTrackbar(greentrackbar, trackbarwindow, 0, 255, foo)
cv.CreateTrackbar(bluetrackbar, trackbarwindow, 0, 255, foo)
cv.CreateTrackbar(xtrackbar, trackbarwindow, 0, image.width, foo)
cv.CreateTrackbar(ytrackbar, trackbarwindow, 0, image.height, foo)
cv.SetMouseCallback(imagewindow, mousecallback, 0)
cv.WaitKey(0)
cv.DestroyAllWindows()
return 0
if __name__ == "__main__" :
main()