title: Detection of Eye movement in sleep state using a thermal recorded video
body: <p>I want to detect the eye movement when it is closed in Far-infrared. I am able to detect the eye region in a thermal video. Once I cropped out the eye, to calculate the eye ball movement in closed eye is with the help of movement of eye lashes. </p>
  
  <p>For this part I thought of finding the intensity value of each pixel and it's location then I will store these values as an array element i.e  A[(x1,y1,z1),(x2,y2,z2)......(xn,yn,zn)]. where x,y represent location and z represents pixel intensity value. Once i am able to make this cropped out part as an array representation. Then i can sort this array then divide this array according to the pixel intensity values. </p>
  
  <p>These values consists of so many intensities but then i will be dividing this into two Arrays according to the occurrence of intensities.
  1. The background as it has same intensity values.
  2. The roi eye lashes.</p>
  
  <p>when we get the 2nd array, I will store these (x,y,z) of the present frame then i repeat this procedure for the next  frame where i will be getting another 2nd array then i can check the difference between the (x,y) of two frames. If the difference is 0, it shows there is no eye movement but if it's not zero then we can say that there is a slight detectable change in eye movement.</p>
  
  <pre><code>import numpy as np
  import cv2
  import scipy
  import matplotlib.pyplot as plt
  from PIL import Image
  from collections import Counter
  
  blur_radius = 1.0
  threshold = 50
  A = ()
  
  
  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]
          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) &amp; 0xFF == ord('q'):
                  break
  
  video.release()
  cv2.destroyAllWindows()
  </code></pre>
  
  <p><img src="https://i.imgur.com/EdIup1g.jpg" alt="http://i.imgur.com/EdIup1g.jpg"><br>
  detected eye in a single frame</p>
  
  <p><img src="https://i.imgur.com/tNYIbZc.jpg" alt="http://i.imgur.com/tNYIbZc.jpg"><br>
  the cropped eye region from a thermal video</p>
  
  <p>I am not sure whether it is the correct way to do. I am unable to figure out how to put the above explained as a code.Is it a feesible thing. sorry if this doesn't make any sense. </p>