added rotations

This commit is contained in:
gocivici 2023-10-21 13:28:52 +03:00
parent 1fd481e64f
commit 13c70a2173

13
main.py
View File

@ -32,6 +32,7 @@ if cam.isOpened():
ret, img = cam.read()
# img = cv2.rotate(img, cv2.ROTATE_90_CLOCKWISE)
# cv2.putText(img, str(TIMER), (200, 250), cv2.FONT_HERSHEY_SIMPLEX, 7, (0, 255, 255), 4, cv2.LINE_AA)
img = cv2.rotate(img, cv2.ROTATE_90_CLOCKWISE)
img = cv2.cvtColor(img,cv2.COLOR_BGR2RGB)
img = Image.fromarray(img)
draw = ImageDraw.Draw(img)
@ -40,6 +41,7 @@ if cam.isOpened():
if TIMER>1:
draw.text((231, 50), str(TIMER), font=font,fill=(255,0,0,255))
img = cv2.cvtColor(np.array(img), cv2.COLOR_RGB2BGR)
img = cv2.rotate(img, cv2.ROTATE_90_COUNTERCLOCKWISE)
cv2.imshow('webcam',img)
# print(str(TIMER))
cur = time.time() #current time
@ -51,13 +53,14 @@ if cam.isOpened():
break
else:
ret, img = cam.read()
img = cv2.rotate(img, cv2.ROTATE_90_CLOCKWISE)
# img = cv2.rotate(img, cv2.ROTATE_90_CLOCKWISE)
predictions = DeepFace.analyze(img,actions=['emotion'])
fearPoint = predictions[0]["emotion"]["fear"]
print("FEAR:" + str(round(fearPoint,2)))
if fearPoint>0:
rotoImg = cv2.rotate(img, cv2.ROTATE_90_CLOCKWISE)
cv2.imwrite('scared.jpg', rotoImg)
#rotoImg = cv2.rotate(img, cv2.ROTATE_90_CLOCKWISE)
cv2.imwrite('scared.jpg', img)
basewidth = 384
imgCrop = Image.open('scared.jpg')
wpercent = (basewidth/float(imgCrop.size[0]))
@ -85,9 +88,9 @@ if cam.isOpened():
img = cv2.cvtColor(np.array(img), cv2.COLOR_RGB2BGR)
#print(30+math.floor(int(fearPoint)*580/100))
# ft.putText(img=img,text='TEST',org=(15, 70),fontHeight=60,color=(255, 255, 255),thickness=-1,line_type=cv2.LINE_AA,bottomLeftOrigin=True)
cv2.rectangle(img,(30,400),(610,450),(255,255,255), 5)
cv2.rectangle(img,(30,400),(30+math.floor(int(fearPoint)*580/100),450),(255,255,255), -1)
#cv2.rectangle(img,(30,400),(610,450),(255,255,255), 5)
#cv2.rectangle(img,(30,400),(30+math.floor(int(fearPoint)*580/100),450),(255,255,255), -1)
img = cv2.rotate(img, cv2.ROTATE_90_COUNTERCLOCKWISE)
cv2.imshow('webcam',img)
cv2.waitKey(5000)