no face bug fix test
This commit is contained in:
parent
e3d2c201dc
commit
de7158b30b
92
main.py
92
main.py
@ -61,52 +61,56 @@ if cam.isOpened():
|
|||||||
img = cv2.flip(img, 0)
|
img = cv2.flip(img, 0)
|
||||||
img = cv2.rotate(img, cv2.ROTATE_90_COUNTERCLOCKWISE)
|
img = cv2.rotate(img, cv2.ROTATE_90_COUNTERCLOCKWISE)
|
||||||
# img = cv2.rotate(img, cv2.ROTATE_90_CLOCKWISE)
|
# img = cv2.rotate(img, cv2.ROTATE_90_CLOCKWISE)
|
||||||
predictions = DeepFace.analyze(img,actions=['emotion'])
|
try:
|
||||||
fearValue = predictions[0]["emotion"]["fear"]
|
predictions = DeepFace.analyze(img,actions=['emotion'])
|
||||||
surpriseValue = predictions[0]["emotion"]["surprise"]
|
fearValue = predictions[0]["emotion"]["fear"]
|
||||||
fearPoint = max(fearValue,surpriseValue)
|
surpriseValue = predictions[0]["emotion"]["surprise"]
|
||||||
print("FEAR:" + str(round(fearPoint,2)))
|
fearPoint = max(fearValue,surpriseValue)
|
||||||
print("SURPRISE:" + str(round(surpriseValue,2)))
|
print("FEAR:" + str(round(fearPoint,2)))
|
||||||
imgGray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
|
print("SURPRISE:" + str(round(surpriseValue,2)))
|
||||||
imgGray = cv2.equalizeHist(imgGray)
|
imgGray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
|
||||||
cv2.imwrite('scared.jpg', imgGray)
|
imgGray = cv2.equalizeHist(imgGray)
|
||||||
img = cv2.cvtColor(img,cv2.COLOR_BGR2RGB)
|
cv2.imwrite('scared.jpg', imgGray)
|
||||||
img = Image.fromarray(img)
|
img = cv2.cvtColor(img,cv2.COLOR_BGR2RGB)
|
||||||
draw = ImageDraw.Draw(img)
|
img = Image.fromarray(img)
|
||||||
font_size = 65
|
draw = ImageDraw.Draw(img)
|
||||||
font = ImageFont.truetype("HalloweenFont.ttf", font_size)
|
font_size = 65
|
||||||
text = "FEAR LEVEL"
|
font = ImageFont.truetype("HalloweenFont.ttf", font_size)
|
||||||
draw.text((59, 452), str(text), font=font,fill=(255,0,0,255))
|
text = "FEAR LEVEL"
|
||||||
img = cv2.cvtColor(np.array(img), cv2.COLOR_RGB2BGR)
|
draw.text((59, 452), str(text), font=font,fill=(255,0,0,255))
|
||||||
|
img = cv2.cvtColor(np.array(img), cv2.COLOR_RGB2BGR)
|
||||||
|
|
||||||
cv2.rectangle(img,(30,550),(30+math.floor(int(fearPoint)*420/100),600),(255,255,255), -1)
|
cv2.rectangle(img,(30,550),(30+math.floor(int(fearPoint)*420/100),600),(255,255,255), -1)
|
||||||
cv2.rectangle(img,(30,550),(450,600),(0,0,255), 8)
|
cv2.rectangle(img,(30,550),(450,600),(0,0,255), 8)
|
||||||
img = cv2.rotate(img, cv2.ROTATE_90_CLOCKWISE)
|
img = cv2.rotate(img, cv2.ROTATE_90_CLOCKWISE)
|
||||||
|
|
||||||
cv2.imshow('webcam',img)
|
cv2.imshow('webcam',img)
|
||||||
cv2.waitKey(2000)
|
cv2.waitKey(2000)
|
||||||
if fearPoint>0:
|
if fearPoint>0:
|
||||||
#rotoImg = cv2.rotate(img, cv2.ROTATE_90_CLOCKWISE)
|
#rotoImg = cv2.rotate(img, cv2.ROTATE_90_CLOCKWISE)
|
||||||
# cv2.imshow('webcam',img)
|
# cv2.imshow('webcam',img)
|
||||||
basewidth = 384
|
basewidth = 384
|
||||||
imgCrop = Image.open('scared.jpg')
|
imgCrop = Image.open('scared.jpg')
|
||||||
wpercent = (basewidth/float(imgCrop.size[0]))
|
wpercent = (basewidth/float(imgCrop.size[0]))
|
||||||
hsize = int((float(imgCrop.size[1])*float(wpercent)))
|
hsize = int((float(imgCrop.size[1])*float(wpercent)))
|
||||||
imgCrop = imgCrop.resize((basewidth,hsize), Image.Resampling.LANCZOS)
|
imgCrop = imgCrop.resize((basewidth,hsize), Image.Resampling.LANCZOS)
|
||||||
imgCrop = imgCrop.save("cropScared.jpg")
|
imgCrop = imgCrop.save("cropScared.jpg")
|
||||||
# cv2.waitKey(2000)
|
# cv2.waitKey(2000)
|
||||||
printer.set(align='center',font='b',width=2,height=2)
|
printer.set(align='center',font='b',width=2,height=2)
|
||||||
|
|
||||||
printer.image("cropScared.jpg",high_density_vertical=True,high_density_horizontal=False,impl="bitImageRaster")
|
printer.image("cropScared.jpg",high_density_vertical=True,high_density_horizontal=False,impl="bitImageRaster")
|
||||||
printer.text("Fear Level: \n" + str(round(fearValue,2))+"/100\n")
|
printer.text("Fear Level: \n" + str(round(fearPoint,1))+"%\n")
|
||||||
printer.text("Surprise Level: \n" + str(round(surpriseValue,2))+"/100\n")
|
# printer.text("Surprise Level: \n" + str(round(surpriseValue,2))+"/100\n")
|
||||||
printer.text("Overall: \n" + str(round(fearPoint,2))+"/100\n")
|
# printer.text("Overall: \n" + str(round(fearPoint,2))+"/100\n")
|
||||||
#printer.text("(Scream Queen)\n")
|
#printer.text("(Scream Queen)\n")
|
||||||
printer.text("\n\n\n\n")
|
printer.text("\n\n\n\n")
|
||||||
#printer.set(align='center',font='b',width=1,height=1)
|
#printer.set(align='center',font='b',width=1,height=1)
|
||||||
#printer.text("Spooky Night 2023")
|
#printer.text("Spooky Night 2023")
|
||||||
#printer.text("2023\n")
|
#printer.text("2023\n")
|
||||||
# cv2.waitKey(5000)
|
# cv2.waitKey(5000)
|
||||||
|
except:
|
||||||
|
cameraMode = False
|
||||||
|
TIMER = 5
|
||||||
|
|
||||||
#print(30+math.floor(int(fearPoint)*580/100))
|
#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)
|
# ft.putText(img=img,text='TEST',org=(15, 70),fontHeight=60,color=(255, 255, 255),thickness=-1,line_type=cv2.LINE_AA,bottomLeftOrigin=True)
|
||||||
|
Loading…
Reference in New Issue
Block a user