I'm using
OS : Ubuntu
Python : 3.8*
Opencv version: 4.6.0
What I'm trying to do is capture the emotion & save the feed..For that I've used opencv 4.0
Code I've
while True:
ret, frame = cap.read()
frame = cv2.resize(frame, (720, 480))
if not ret:
break
grayFrame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
rects = detector(grayFrame, 0)
for rect in rects:
shape = predictor(grayFrame, rect)
points = shapePoints(shape)
(x, y, w, h) = rectPoints(rect)
grayFace = grayFrame[y:y + h, x:x + w]
try:
grayFace = cv2.resize(grayFace, (emotionTargetSize))
except:
continue
grayFace = grayFace.astype('float32')
grayFace = grayFace / 255.0
grayFace = (grayFace - 0.5) * 2.0
grayFace = np.expand_dims(grayFace, 0)
grayFace = np.expand_dims(grayFace, -1)
emotion_prediction = emotionClassifier.predict(grayFace)
emotion_probability = np.max(emotion_prediction)
if (emotion_probability > 0.36):
emotion_label_arg = np.argmax(emotion_prediction)
color = emotions[emotion_label_arg]['color']
cv2.rectangle(frame, (x, y), (x + w, y + h), color, 2)
cv2.line(frame, (x, y + h), (x + 20, y + h + 20),
color,
thickness=2)
cv2.rectangle(frame, (x + 20, y + h + 20), (x + 110, y + h + 40),
color, -1)
cv2.putText(frame, emotions[emotion_label_arg]['emotion'],
(x + 25, y + h + 36), cv2.FONT_HERSHEY_SIMPLEX, 0.5,
(255, 255, 255), 1, cv2.LINE_AA)
else:
color = (255, 255, 255)
cv2.rectangle(frame, (x, y), (x + w, y + h), color, 2)
out.write(frame)
#Wait for user input - q, then you will stop the loop
k = cv2.waitKey(1)
if k == 27:
break
cap.release()
if args["isVideoWriter"] == True:
videoWrite.release()
cv2.destroyAllWindows()
Here Issue with wait key
...when I hit on esc
program is not exiting...I've tried all the possible methods...the only method that working is keyboard interruption i.e, ctrl+c
Method1: Not working :(
c = cv2.waitKey(0) % 256
if c == ord('a'):
break
Method 2: Not working :(
if cv2.waitKey(0) & 0xFF == ord('q'):
break
Did i missing anything?...Thanks in advance