├── images.png ├── Demo ├── WhatsApp Image 2022-12-05 at 12.41.25 AM (1).jpeg ├── WhatsApp Image 2022-12-05 at 12.41.25 AM (10).jpeg ├── WhatsApp Image 2022-12-05 at 12.41.25 AM (6).jpeg ├── WhatsApp Image 2022-12-05 at 12.41.25 AM (8).jpeg ├── WhatsApp Image 2022-12-05 at 12.41.25 AM (9).jpeg ├── WhatsApp Image 2022-12-05 at 12.41.26 AM (5).jpeg ├── WhatsApp Image 2022-12-05 at 12.41.26 AM (6).jpeg ├── WhatsApp Image 2022-12-05 at 12.41.26 AM (7).jpeg ├── WhatsApp Image 2022-12-05 at 12.41.26 AM (8).jpeg └── WhatsApp Image 2022-12-05 at 12.41.26 AM (9).jpeg ├── README.md └── intangible_painting.py /images.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Srdash0/Intangible-Painting/HEAD/images.png -------------------------------------------------------------------------------- /Demo/WhatsApp Image 2022-12-05 at 12.41.25 AM (1).jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Srdash0/Intangible-Painting/HEAD/Demo/WhatsApp Image 2022-12-05 at 12.41.25 AM (1).jpeg -------------------------------------------------------------------------------- /Demo/WhatsApp Image 2022-12-05 at 12.41.25 AM (10).jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Srdash0/Intangible-Painting/HEAD/Demo/WhatsApp Image 2022-12-05 at 12.41.25 AM (10).jpeg -------------------------------------------------------------------------------- /Demo/WhatsApp Image 2022-12-05 at 12.41.25 AM (6).jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Srdash0/Intangible-Painting/HEAD/Demo/WhatsApp Image 2022-12-05 at 12.41.25 AM (6).jpeg -------------------------------------------------------------------------------- /Demo/WhatsApp Image 2022-12-05 at 12.41.25 AM (8).jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Srdash0/Intangible-Painting/HEAD/Demo/WhatsApp Image 2022-12-05 at 12.41.25 AM (8).jpeg -------------------------------------------------------------------------------- /Demo/WhatsApp Image 2022-12-05 at 12.41.25 AM (9).jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Srdash0/Intangible-Painting/HEAD/Demo/WhatsApp Image 2022-12-05 at 12.41.25 AM (9).jpeg -------------------------------------------------------------------------------- /Demo/WhatsApp Image 2022-12-05 at 12.41.26 AM (5).jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Srdash0/Intangible-Painting/HEAD/Demo/WhatsApp Image 2022-12-05 at 12.41.26 AM (5).jpeg -------------------------------------------------------------------------------- /Demo/WhatsApp Image 2022-12-05 at 12.41.26 AM (6).jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Srdash0/Intangible-Painting/HEAD/Demo/WhatsApp Image 2022-12-05 at 12.41.26 AM (6).jpeg -------------------------------------------------------------------------------- /Demo/WhatsApp Image 2022-12-05 at 12.41.26 AM (7).jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Srdash0/Intangible-Painting/HEAD/Demo/WhatsApp Image 2022-12-05 at 12.41.26 AM (7).jpeg -------------------------------------------------------------------------------- /Demo/WhatsApp Image 2022-12-05 at 12.41.26 AM (8).jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Srdash0/Intangible-Painting/HEAD/Demo/WhatsApp Image 2022-12-05 at 12.41.26 AM (8).jpeg -------------------------------------------------------------------------------- /Demo/WhatsApp Image 2022-12-05 at 12.41.26 AM (9).jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Srdash0/Intangible-Painting/HEAD/Demo/WhatsApp Image 2022-12-05 at 12.41.26 AM (9).jpeg -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Intangible-Painting 2 | It is an OpenCV project which allows you to draw simple structures by using hand signs. 3 | To run the project you should have certain python libraries installed. Those are: cv2, mediapipe and Numpy. 4 | -------------------------------------------------------------------------------- /intangible_painting.py: -------------------------------------------------------------------------------- 1 | import mediapipe as mp 2 | import cv2 3 | import numpy as np 4 | import time 5 | 6 | #contants 7 | ml = 150 8 | max_x, max_y = 250+ml, 50 9 | curr_tool = "select tool" 10 | time_init = True 11 | rad = 40 12 | var_inits = False 13 | thick = 4 14 | prevx, prevy = 0,0 15 | 16 | #get tools function 17 | def getTool(x): 18 | if x < 50 + ml: 19 | return "line" 20 | 21 | elif x<100 + ml: 22 | return "rectangle" 23 | 24 | elif x < 150 + ml: 25 | return"draw" 26 | 27 | elif x<200 + ml: 28 | return "circle" 29 | 30 | else: 31 | return "erase" 32 | 33 | def index_raised(yi, y9): 34 | if (y9 - yi) > 40: 35 | return True 36 | 37 | return False 38 | 39 | 40 | 41 | hands = mp.solutions.hands 42 | hand_landmark = hands.Hands(min_detection_confidence=0.6, min_tracking_confidence=0.6, max_num_hands=1) 43 | draw = mp.solutions.drawing_utils 44 | 45 | 46 | # drawing tools 47 | tools = cv2.imread("tools.png") 48 | tools = tools.astype('uint8') 49 | 50 | mask = np.ones((480, 640))*255 51 | mask = mask.astype('uint8') 52 | ''' 53 | tools = np.zeros((max_y+5, max_x+5, 3), dtype="uint8") 54 | cv2.rectangle(tools, (0,0), (max_x, max_y), (0,0,255), 2) 55 | cv2.line(tools, (50,0), (50,50), (0,0,255), 2) 56 | cv2.line(tools, (100,0), (100,50), (0,0,255), 2) 57 | cv2.line(tools, (150,0), (150,50), (0,0,255), 2) 58 | cv2.line(tools, (200,0), (200,50), (0,0,255), 2) 59 | ''' 60 | 61 | cap = cv2.VideoCapture(0) 62 | while True: 63 | _, frm = cap.read() 64 | frm = cv2.flip(frm, 1) 65 | 66 | rgb = cv2.cvtColor(frm, cv2.COLOR_BGR2RGB) 67 | 68 | op = hand_landmark.process(rgb) 69 | 70 | if op.multi_hand_landmarks: 71 | for i in op.multi_hand_landmarks: 72 | draw.draw_landmarks(frm, i, hands.HAND_CONNECTIONS) 73 | x, y = int(i.landmark[8].x*640), int(i.landmark[8].y*480) 74 | 75 | if x < max_x and y < max_y and x > ml: 76 | if time_init: 77 | ctime = time.time() 78 | time_init = False 79 | ptime = time.time() 80 | 81 | cv2.circle(frm, (x, y), rad, (0,255,255), 2) 82 | rad -= 1 83 | 84 | if (ptime - ctime) > 0.8: 85 | curr_tool = getTool(x) 86 | print("your current tool set to : ", curr_tool) 87 | time_init = True 88 | rad = 40 89 | 90 | else: 91 | time_init = True 92 | rad = 40 93 | 94 | if curr_tool == "draw": 95 | xi, yi = int(i.landmark[12].x*640), int(i.landmark[12].y*480) 96 | y9 = int(i.landmark[9].y*480) 97 | 98 | if index_raised(yi, y9): 99 | cv2.line(mask, (prevx, prevy), (x, y), 0, thick) 100 | prevx, prevy = x, y 101 | 102 | else: 103 | prevx = x 104 | prevy = y 105 | 106 | 107 | 108 | elif curr_tool == "line": 109 | xi, yi = int(i.landmark[12].x*640), int(i.landmark[12].y*480) 110 | y9 = int(i.landmark[9].y*480) 111 | 112 | if index_raised(yi, y9): 113 | if not(var_inits): 114 | xii, yii = x, y 115 | var_inits = True 116 | 117 | cv2.line(frm, (xii, yii), (x, y), (50,152,255), thick) 118 | 119 | else: 120 | if var_inits: 121 | cv2.line(mask, (xii, yii), (x, y), 0, thick) 122 | var_inits = False 123 | 124 | elif curr_tool == "rectangle": 125 | xi, yi = int(i.landmark[12].x*640), int(i.landmark[12].y*480) 126 | y9 = int(i.landmark[9].y*480) 127 | 128 | if index_raised(yi, y9): 129 | if not(var_inits): 130 | xii, yii = x, y 131 | var_inits = True 132 | 133 | cv2.rectangle(frm, (xii, yii), (x, y), (0,255,255), thick) 134 | 135 | else: 136 | if var_inits: 137 | cv2.rectangle(mask, (xii, yii), (x, y), 0, thick) 138 | var_inits = False 139 | 140 | elif curr_tool == "circle": 141 | xi, yi = int(i.landmark[12].x*640), int(i.landmark[12].y*480) 142 | y9 = int(i.landmark[9].y*480) 143 | 144 | if index_raised(yi, y9): 145 | if not(var_inits): 146 | xii, yii = x, y 147 | var_inits = True 148 | 149 | cv2.circle(frm, (xii, yii), int(((xii-x)**2 + (yii-y)**2)**0.5), (255,255,0), thick) 150 | 151 | else: 152 | if var_inits: 153 | cv2.circle(mask, (xii, yii), int(((xii-x)**2 + (yii-y)**2)**0.5), (0,255,0), thick) 154 | var_inits = False 155 | 156 | elif curr_tool == "erase": 157 | xi, yi = int(i.landmark[12].x*640), int(i.landmark[12].y*480) 158 | y9 = int(i.landmark[9].y*480) 159 | 160 | if index_raised(yi, y9): 161 | cv2.circle(frm, (x, y), 30, (0,0,0), -1) 162 | cv2.circle(mask, (x, y), 30, 255, -1) 163 | 164 | 165 | --------------------------------------------------------------------------------