-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
169 lines (136 loc) · 6.79 KB
/
test.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# flake8: noqa: E501
from opencv_wrap import cv2Decorator
import cv2
from opencv_wrap.detectors import Face, Hand, Pose
from opencv_wrap.utils.helper import saveFrame, detectionBox, show_all_frames, clipImage
# reading a single frame from the directory
# @cv2Decorator.DetectInEachFrame(detector=cv2.CascadeClassifier(cv2.data.haarcascades+"haarcascade_frontalface_default.xml"),name='face')
# @cv2Decorator.MirrorFrame()
# @cv2Decorator.ConvertCOLOR(converter=cv2.COLOR_BGR2GRAY)
# def all_actions(**kwargs):
# frame = kwargs['frame']
# # detect face from trainerd data and detectMultiScale use to deteat every size of face
# face_coordinate = kwargs['face'].detectMultiScale(kwargs['greyScale'],1.3,5)
# detectionBox(detectedArr=face_coordinate, frame=frame)
# return kwargs
# frame = cv2.imread('./opencv_wrap/testMedia/test.jpg')
# kwargs = all_actions(frame=frame)
# cv2.imshow('frame',kwargs['frame'])
# key = cv2.waitKey(0)
# reading a video from the directory
# face detection
# @cv2Decorator.DetectInEachFrame(
# detector=Face(verbose=True),
# name="face",
# )
# @cv2Decorator.TotalTimeTaken(show=True)
# # @cv2Decorator.AccessCamOrVideo(show=False, videoPath="./opencv_wrap/testMedia/test.mp4", fps=12)
# @cv2Decorator.AccessCamOrVideo(show=False)
# @cv2Decorator.CalculateFps(draw=True)
# @cv2Decorator.MirrorFrame()
# @cv2Decorator.ConvertCOLOR(converter=cv2.COLOR_BGR2GRAY)
# @cv2Decorator.ConvertCOLOR(converter=cv2.COLOR_RGB2BGR, frameName="bgr_frame")
# def all_actions(**kwargs):
# # detect face from trainerd data and detectMultiScale use to deteat every size of face
# # face_coordinate = kwargs["face"].detectMultiScale(kwargs["greyScale"], 1.3, 5)
# mainFrameCopy = kwargs["frame"].copy()
# processed = kwargs["face"].detect(kwargs["bgr_frame"])
# face_coordinate = kwargs["face"].getDetectionBox(
# processed, kwargs["frame"], draw=True
# )
# kwargs["face"].getLandmarks(processed, kwargs["frame"])
# # print(len(face_coordinate))
# kwargs["detected"] = [clipImage(mainFrameCopy, i) for i in face_coordinate]
# # saveFrame(frame=frame,count=kwargs['frame_count'],destination='./test2')
# # detectionBox(detectedArr=face_coordinate, frame=kwargs["frame"])
# # show_all_frames(kwargs,keysToShow=['frame','greyScale','mirror_frame','detected'])
# # show_all_frames(kwargs,keysToShow=['frame','greyScale','mirror_frame'])
# show_all_frames(kwargs, keysToShow=["frame", "detected"])
# return kwargs
# kwargs = all_actions()
# Hand
@cv2Decorator.DetectInEachFrame(
detector=Hand(verbose=True),
name="hand",
)
@cv2Decorator.TotalTimeTaken(show=True)
# @cv2Decorator.AccessCamOrVideo(show=False, videoPath="./opencv_wrap/testMedia/test.mp4", fps=12)
@cv2Decorator.AccessCamOrVideo(show=False, fps=12)
@cv2Decorator.CalculateFps(draw=True)
@cv2Decorator.MirrorFrame()
@cv2Decorator.ConvertCOLOR(converter=cv2.COLOR_BGR2GRAY)
@cv2Decorator.ConvertCOLOR(converter=cv2.COLOR_RGB2BGR, frameName="bgr_frame")
def all_actions(**kwargs):
# detect hand from trainerd data and detectMultiScale use to deteat every size of hand
# face_coordinate = kwargs["hand"].detectMultiScale(kwargs["greyScale"], 1.3, 5)
mainFrameCopy = kwargs["frame"].copy()
processed = kwargs["hand"].detect(kwargs["bgr_frame"])
face_coordinate = kwargs["hand"].getDetectionBox(
processed, kwargs["frame"], draw=True
)
kwargs["hand"].getLandmarks(processed, kwargs["frame"], draw=True)
# print(len(face_coordinate))
kwargs["detected"] = [clipImage(mainFrameCopy, i) for i in face_coordinate]
# saveFrame(frame=frame,count=kwargs['frame_count'],destination='./test2')
# detectionBox(detectedArr=face_coordinate, frame=kwargs["frame"])
# show_all_frames(kwargs,keysToShow=['frame','greyScale','mirror_frame','detected'])
# show_all_frames(kwargs,keysToShow=['frame','greyScale','mirror_frame'])
show_all_frames(kwargs, keysToShow=["frame", "detected"])
return kwargs
kwargs = all_actions()
# pose detection
# @cv2Decorator.DetectInEachFrame(
# detector=Pose(verbose=True),
# name="pose",
# )
# @cv2Decorator.TotalTimeTaken(show=True)
# @cv2Decorator.AccessCamOrVideo(show=False, videoPath="./opencv_wrap/testMedia/test.mp4", fps=12)
# # @cv2Decorator.AccessCamOrVideo(show=False, fps=12)
# @cv2Decorator.CalculateFps(draw=True)
# @cv2Decorator.MirrorFrame()
# @cv2Decorator.ConvertCOLOR(converter=cv2.COLOR_BGR2GRAY)
# @cv2Decorator.ConvertCOLOR(converter=cv2.COLOR_RGB2BGR, frameName="bgr_frame")
# def all_actions(**kwargs):
# # detect pose from trainerd data and detectMultiScale use to deteat every size of pose
# # face_coordinate = kwargs["pose"].detectMultiScale(kwargs["greyScale"], 1.3, 5)
# mainFrameCopy = kwargs["frame"].copy()
# processed = kwargs["pose"].detect(kwargs["bgr_frame"])
# face_coordinate = kwargs["pose"].getDetectionBox(
# processed, kwargs["frame"], draw=True
# )
# kwargs["pose"].getLandmarks(processed, kwargs["frame"], draw=True)
# # print(len(face_coordinate))
# kwargs["detected"] = [clipImage(mainFrameCopy, i) for i in face_coordinate]
# # saveFrame(frame=frame,count=kwargs['frame_count'],destination='./test2')
# # detectionBox(detectedArr=face_coordinate, frame=kwargs["frame"])
# # show_all_frames(kwargs,keysToShow=['frame','greyScale','mirror_frame','detected'])
# # show_all_frames(kwargs,keysToShow=['frame','greyScale','mirror_frame'])
# show_all_frames(kwargs, keysToShow=["frame", "detected"])
# return kwargs
# all_actions()
# reading the cam feed
# @cv2Decorator.TotalTimeTaken(show=True)
# @cv2Decorator.DetectInEachFrame(detector=cv2.CascadeClassifier(cv2.data.haarcascades+"haarcascade_frontalface_default.xml"),name='face')
# @cv2Decorator.AccessCamOrVideo(show=True, videoPath="./opencv_wrap/testMedia/test.mp4", )
# @cv2Decorator.CalculateFps(draw = True)
# @cv2Decorator.MirrorFrame()
# @cv2Decorator.ConvertCOLOR(converter=cv2.COLOR_BGR2GRAY)
# def all_actions(**kwargs):
# frame = kwargs['frame']
# # detect face from trainerd data and detectMultiScale use to deteat every size of face
# face_coordinate = kwargs['face'].detectMultiScale(kwargs['greyScale'],1.3,5)
# # saveFrame(frame=frame,count=kwargs['frame_count'],destination='./test2')
# detectionBox(detectedArr=face_coordinate, frame=frame)
# return kwargs
# a = all_actions()
# print(a['frame_count'])
# show converted frames in smart view
# @cv2Decorator.TotalTimeTaken(show=True)
# @cv2Decorator.AccessCamOrVideo(show=False, videoPath="./opencv_wrap/testMedia/test.mp4", fps=12)
# @cv2Decorator.CalculateFps(draw=True)
# @cv2Decorator.MirrorFrame()
# @cv2Decorator.ConvertCOLOR(converter=cv2.COLOR_BGR2GRAY)
# def all_actions(**kwargs):
# show_all_frames(kwargs,keysToShow=['frame','greyScale','mirror_frame'])
# return kwargs
# all_actions()