-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
123 lines (85 loc) · 3.12 KB
/
main.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
112
113
114
115
116
117
118
119
120
121
122
123
#D:\study\prac\Scripts\activate
import cv2
import mediapipe as mp
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
import sys
from gethands import gethan
camwidth=640
camheight=480
camera = cv2.VideoCapture(1, cv2.CAP_DSHOW)
if not camera.isOpened():
print("Cannot open webcam")
#exit()
else :
print("camera is ON")
class Window(QMainWindow):
def __init__(self):
super().__init__()
# set the title
self.setWindowTitle("Drawscream")
# setting geometry to main window
#self.setGeometry(100, 100, 800, 600)
#settings for window
self.setWindowFlags(Qt.FramelessWindowHint)
self.setAttribute(Qt.WA_TranslucentBackground)
# default brush size
self.brushSize = 2
# default color
self.brushColor = Qt.green
# variables
# drawing flag
self.drawing = False
# QPoint object to tract the point
self.lastPoint = QPoint(0,0)
print(self.lastPoint.x(), self.lastPoint.y())
mainMenu = self.menuBar()
menu = mainMenu.addMenu("menu")
clear = QAction("clear", self)
menu.addAction(clear)
clear.triggered.connect(self.clear)
closeit= mainMenu.addMenu("close")
c=QAction("closeit", self)
closeit.addAction(c)
closeit.triggered.connect(self.closeit)
mainMenu.addMenu("PRESS & HOLD SPACE") #instructions
# creating image object
self.image = QImage(self.size(), QImage.Format_RGB32)
# making image color to white
#self.image.fill(Qt.white)
# setting the geometry of window
self.showMaximized()
def paintEvent(self, event):
canvasPainter = QPainter(self)
canvasPainter.drawImage(self.rect(), self.image, self.image.rect())
def clear(self):
# make the whole canvas white
self.image = QImage(self.size(), QImage.Format_RGB32)
# update
self.update()
def keyPressEvent(self, event):
self.drawing=True
painter = QPainter(self.image)
#painter.begin(self)
painter.setPen(QPen(self.brushColor, self.brushSize, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin))
finger=gethan(camwidth, camheight, camera)
if finger != (0,0) :
print("finger={}".format(finger))
nextPoint=QPoint()
nextPoint.setX(finger[0])
nextPoint.setY(finger[1])
#print(self.lastPoint, nextPoint)
painter.drawLine(self.lastPoint, nextPoint)
self.lastPoint=nextPoint
self.update()
else:
print("non")
def closeit(self):
self.close()
if __name__ == '__main__':
App = QApplication(sys.argv)
# create the instance of our Window
window = Window()
window.show()
sys.exit(App.exec())