I am trying to detect the closed eye movement in a thermal video to study sleep state. I am able to detect the closed eye region in a face then I am able to save each eye frame later it's converted to give me just the eyelash region but i am unable to save eyelash images with iterative numbering like i did for the eye region.
import numpy as np
import cv2
import scipy
import glob
import os
from pylab import *
from matplotlib import pyplot as plt
from PIL import Image
from collections import Counter
import time
blur_radius = 1.0
threshold = 50
video = cv2.VideoCapture('12.avi')
while True:
ret, frame = video.read()
frame = frame[:,1:600]
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
gray = cv2.GaussianBlur(gray, (15,15), 0)
(minVal, maxVal, minLoc, maxLoc) = cv2.minMaxLoc(gray)
image = frame
(x,y) = maxLoc
cv2.circle(image, maxLoc, 15, (255, 0, 0), 2)
cv2.rectangle(image,(maxLoc),(390,190),(0,255,0),2)
roi = frame [y:190,x:390]
roi = cv2.resize(roi, None, fx=4, fy=4, interpolation=cv2.INTER_AREA)
count = 0
while True:
cv2.imwrite("eye%d.tif" % count,roi)
count += 1
for eye in glob.glob("*.tif"):
im=Image.open(eye)
gray = im.convert('L')
bw = gray.point(lambda x: 0 if x<128 else 255, '1')
count1 = 0
while True:
cv2.imwrite("lashes%d.tif" % count,bw)
count += 1
count2 = 0
for eye in glob.glob("*.tif"):
os.remove("eye%d.tif" %count2)
count2 += 1
try:
roi = cv2.resize(roi, None, fx=4, fy=4, interpolation=cv2.INTER_AREA)
cv2.imshow("Eye",roi)
cv2.imshow("Eyecorner", image)
except:
print''
if cv2.waitKey(1) & 0xFF == ord('q'):
break
video.release()
cv2.destroyAllWindows()
This is the error i am receiving when i run this code
Traceback (most recent call last):
File "D:\Acads\7.1 Sem\BTP\Data\Thermal videos\after_getting_eye.py", line 39, in <module>
cv2.imwrite("lashes%d.tif" % count,bw)
TypeError: img is not a numpy array, neither a scalar
once i get these images, i am thinking of using this
diff = ImageChops.difference(im2, im1).getbbox()
to find the difference between previous eyelash image and present eyelash image. if the diff has some value apart from none, then it suggest that there is a eyelash movement which in return proves that there is a eye movement behind the closed lids. Also can anyone tell me a quick way without saving these images and directly work on them as the run time is getting so long and is this a feasible way to detect eye movement when the lid is closed? Any help is kindly appreciated