-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSwitch_ColorPalatte.py
64 lines (50 loc) · 1.55 KB
/
Switch_ColorPalatte.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
# -*- coding: utf-8 -*-
"""
Created on Tue Sep 24 19:11:32 2019
@author: garima.misra
"""
import cv2
import numpy as np
ix, iy = -1,-1
left_press = False
def value_change(x):
pass
def mouse_brush(event,x,y,flags, param):
global ix, iy, left_press
if event == cv2.EVENT_LBUTTONDOWN:
ix = x
iy = y
left_press = True
elif event == cv2.EVENT_MOUSEMOVE:
if left_press == True:
cv2.circle(img, (x,y), param[0], param[1], -1)
elif event == cv2.EVENT_LBUTTONUP:
left_press = False
#create a black image
img = np.zeros((300,512,3), np.uint8)
cv2.namedWindow('image')
#create colorTrackBar
cv2.createTrackbar('R', 'image',0,255, value_change)
cv2.createTrackbar('G', 'image',0,255, value_change)
cv2.createTrackbar('B', 'image',0,255, value_change)
#create brush
brush = 'OFF:0 \nON:1'
cv2.createTrackbar('brush', 'image',0,1, mouse_brush)
radius = 'Min:1 \nMax:10'
cv2.createTrackbar('radius', 'image',1,10, value_change)
while(1):
cv2.imshow('image', img)
k = cv2.waitKey(1) & 0xFF
if k == 27:
break
r = cv2.getTrackbarPos('R', 'image')
g = cv2.getTrackbarPos('G', 'image')
b = cv2.getTrackbarPos('B', 'image')
B = cv2.getTrackbarPos('brush', 'image')
R = cv2.getTrackbarPos('radius', 'image')
if B == 0:
img[:] = [255,255,255]
else:
param = [R, (r,g,b)]
cv2.setMouseCallback('image', mouse_brush, param)
cv2.destroyAllWindows()