In [1]:
import os
import numpy as np
import cv2
from sklearn.externals import joblib

In [2]:
os.getcwd()


Out[2]:
'/home/saif/Desktop/Minor'

In [3]:
from image_transformation import apply_image_transformation

In [4]:
os.listdir('.')


Out[4]:
['code',
 'Avid.mov',
 'image_transformation.pyc',
 'snapshots',
 'camera.py',
 'run.sh',
 'vidToFrame.java',
 'predict.py',
 '.ipynb_checkpoints',
 'final_run.sh',
 'vidToFrames.class',
 'image_transformation.py',
 'data',
 'modules',
 'Elephant.mp4',
 'Untitled.ipynb']

In [5]:
clf= joblib.load('./modules/model-serialized-logistic.pkl')

In [5]:
os.chdir('./snapshots/')

In [7]:
l=os.listdir('.')

In [6]:
from matplotlib import pyplot as plt

In [10]:
l=sorted(l)

In [7]:
%matplotlib inline

In [16]:
str=[]
for i in l:
    frame= cv2.imread(i)
    frame= apply_image_transformation(frame)
    frame_flattened=frame.flatten()
    predicted_labels= clf.predict(np.reshape(frame_flattened,(1,frame_flattened.size)))
    predicted_label = predicted_labels[0]
    str.append(predicted_label)
print(str)


Resizing image to 100...
Done!
Making background black...
Done!
Making skin white...
Done!
Removing arm...
Done!
Drawing contour around white color...
Done!
Centering the image...
Done!
Resizing image to 30...
Done!
Resizing image to 100...
Done!
Making background black...
Done!
Making skin white...
Done!
Removing arm...
Done!
Drawing contour around white color...
Done!
Centering the image...
Done!
Resizing image to 30...
Done!
Resizing image to 100...
Done!
Making background black...
Done!
Making skin white...
Done!
Removing arm...
Done!
Drawing contour around white color...
Done!
Centering the image...
Done!
Resizing image to 30...
Done!
Resizing image to 100...
Done!
Making background black...
Done!
Making skin white...
Done!
Removing arm...
Done!
Drawing contour around white color...
Done!
Centering the image...
Done!
Resizing image to 30...
Done!
Resizing image to 100...
Done!
Making background black...
Done!
Making skin white...
Done!
Removing arm...
Done!
Drawing contour around white color...
Done!
Centering the image...
Done!
Resizing image to 30...
Done!
Resizing image to 100...
Done!
Making background black...
Done!
Making skin white...
Done!
Removing arm...
Done!
Drawing contour around white color...
Done!
Centering the image...
Done!
Resizing image to 30...
Done!
Resizing image to 100...
Done!
Making background black...
Done!
Making skin white...
Done!
Removing arm...
Done!
Drawing contour around white color...
Done!
Centering the image...
Done!
Resizing image to 30...
Done!
Resizing image to 100...
Done!
Making background black...
Done!
Making skin white...
Done!
Removing arm...
Done!
Drawing contour around white color...
Done!
Centering the image...
Done!
Resizing image to 30...
Done!
Resizing image to 100...
Done!
Making background black...
Done!
Making skin white...
Done!
Removing arm...
Done!
Drawing contour around white color...
Done!
Centering the image...
Done!
Resizing image to 30...
Done!
Resizing image to 100...
Done!
Making background black...
Done!
Making skin white...
Done!
Removing arm...
Done!
Drawing contour around white color...
Done!
Centering the image...
Done!
Resizing image to 30...
Done!
['E', 'E', 'E', 'Y', 'E', 'P', 'H', 'A', 'N', 'T']

In [8]:
cap = cv2.VideoCapture(0)

In [9]:
ret, frame = cap.read()

In [10]:
gray = frame#cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
cv2.rectangle(gray,(250,250),(450,450),(0,255,0),3)

In [11]:
plt.imshow(gray)


Out[11]:
<matplotlib.image.AxesImage at 0x7f178a026c90>

In [12]:
detect= gray[250:450,250:450]

In [13]:
plt.imshow(detect)


Out[13]:
<matplotlib.image.AxesImage at 0x7f1789f5aad0>

In [14]:
fr= apply_image_transformation(detect)
frame_flattened=frame.flatten()
predicted_labels= clf.predict(np.reshape(frame_flattened,(1,frame_flattened.size)))
predicted_label = predicted_labels[0]
print(predicted_label)


---------------------------------------------------------------------------
Exception                                 Traceback (most recent call last)
<ipython-input-14-144778b09da7> in <module>()
----> 1 fr= apply_image_transformation(detect)
      2 frame_flattened=frame.flatten()
      3 predicted_labels= clf.predict(np.reshape(frame_flattened,(1,frame_flattened.size)))
      4 predicted_label = predicted_labels[0]
      5 print(predicted_label)

/home/saif/Desktop/Minor/image_transformation.pyc in apply_image_transformation(frame)
    170     frame = remove_arm(frame)
    171     frame, contour_dimensions = draw_contours(frame)
--> 172     frame = centre_frame(frame, contour_dimensions)
    173     frame = resize_image(frame, 30)
    174     return frame

/home/saif/Desktop/Minor/image_transformation.pyc in centre_frame(frame, contour_dimensions)
    157     else:
    158         log_message = "No contour found!!"
--> 159         raise Exception(log_message)
    160 
    161     ##print("Done!")

Exception: No contour found!!

In [15]:
fr= apply_image_transformation(detect)


---------------------------------------------------------------------------
Exception                                 Traceback (most recent call last)
<ipython-input-15-99e3ed6a189c> in <module>()
----> 1 fr= apply_image_transformation(detect)

/home/saif/Desktop/Minor/image_transformation.pyc in apply_image_transformation(frame)
    170     frame = remove_arm(frame)
    171     frame, contour_dimensions = draw_contours(frame)
--> 172     frame = centre_frame(frame, contour_dimensions)
    173     frame = resize_image(frame, 30)
    174     return frame

/home/saif/Desktop/Minor/image_transformation.pyc in centre_frame(frame, contour_dimensions)
    157     else:
    158         log_message = "No contour found!!"
--> 159         raise Exception(log_message)
    160 
    161     ##print("Done!")

Exception: No contour found!!

In [ ]: