Beispiel #1
0
def detect(path):

	input_image = io.imread(path)
	gnb = joblib.load('/home/qburst/Desktop/Emotion_detection/ED_dist/Classifier/gnb.pkl')
	face_count, features, faces = p.feature_extraction(input_image)
	if face_count:
		emotions = gnb.predict(features)
		print emotions
		for d, emotion in zip(faces, emotions):
			print d, emotion
			if emotion == 0:
				cv2.rectangle(input_image, (d.left(), d.top()), (d.right(), d.bottom()), (0, 0, 0), 2)

			elif emotion == 1:
                                cv2.rectangle(input_image, (d.left(), d.top()), (d.right(), d.bottom()), (0, 0, 255), 3)


			elif emotion == 2:
                                cv2.rectangle(input_image, (d.left(), d.top()), (d.right(), d.bottom()), (255, 255, 0), 3)


			elif emotion == 3:
				cv2.rectangle(input_image, (d.left(), d.top()), (d.right(), d.bottom()), (255, 0, 0), 3)

				
		io.imsave('Detected/emotion.jpg', input_image)
		return face_count, 'Detected/emotion.jpg'
	else:
	 	return face_count, 'err'
Beispiel #2
0
def detect(path):

    input_image = io.imread(path)
    gnb = joblib.load(
        '/home/qburst/Desktop/Emotion_detection/ED_dist/Classifier/gnb.pkl')
    face_count, features, faces = p.feature_extraction(input_image)
    if face_count:
        emotions = gnb.predict(features)
        print emotions
        for d, emotion in zip(faces, emotions):
            print d, emotion
            if emotion == 0:
                cv2.rectangle(input_image, (d.left(), d.top()),
                              (d.right(), d.bottom()), (0, 0, 0), 2)

            elif emotion == 1:
                cv2.rectangle(input_image, (d.left(), d.top()),
                              (d.right(), d.bottom()), (0, 0, 255), 3)

            elif emotion == 2:
                cv2.rectangle(input_image, (d.left(), d.top()),
                              (d.right(), d.bottom()), (255, 255, 0), 3)

            elif emotion == 3:
                cv2.rectangle(input_image, (d.left(), d.top()),
                              (d.right(), d.bottom()), (255, 0, 0), 3)

        io.imsave('Detected/emotion.jpg', input_image)
        return face_count, 'Detected/emotion.jpg'
    else:
        return face_count, 'err'
#Convert to numpy array
y = np.asarray(y, dtype = np.int32)
x = np.asarray(x)

count = 0


#Extracting features
for emotion_folder in os.listdir(train_path):
    print emotion_folder
    for img_file in os.listdir(train_path + '/' + emotion_folder):
        count += 1
        print count, img_file
        img = io.imread(train_path + '/' + emotion_folder + '/' + img_file)

        face_count, feature, faces = p.feature_extraction(img)
        x = np.vstack((x, feature[0]))

        #Assigning code to each emotion
        if emotion_folder == 'sad':
            y = np.append(y, 0)
        elif emotion_folder == 'surprise':
            y = np.append(y, 1)
        elif emotion_folder == 'happy':
            y = np.append(y, 2)
        elif emotion_folder == 'angry':
            y = np.append(y, 3)
            
        

#Deleting the 1st element in x array
Beispiel #4
0
import processing as p
from sklearn.naive_bayes import GaussianNB
from sklearn.externals import joblib
import numpy as np


input_image_path = '/home/qburst/Desktop/test_sad1.jpg'

input_image = io.imread(input_image_path)

##x = np.load('/home/qburst/Desktop/Emotion Classification/Numpy arrays with only distances/dist_only_x.npy')
##y = np.load('/home/qburst/Desktop/Emotion Classification/Numpy arrays with only distances/y.npy')

###initializing a NB classifier
##gnb = GaussianNB()
##gnb.fit(x, y)

##joblib.dump(gnb, '/home/qburst/Desktop/TrainedGNB.pkl')

gnb = joblib.load('/home/qburst/Desktop/Emotion_detection/ED_dist/Classifier/gnb.pkl')

face_count, features, faces = p.feature_extraction(input_image)

emotions = gnb.predict(features)
print emotions

##for count, face in enumerate(faces):
##     gnb.predict(features[0])


Beispiel #5
0
#Convert to numpy array
y = np.asarray(y, dtype=np.int32)
x = np.asarray(x)

count = 0

#Extracting features
for emotion_folder in os.listdir(train_path):
    print emotion_folder
    for img_file in os.listdir(train_path + '/' + emotion_folder):
        count += 1
        print count, img_file
        img = io.imread(train_path + '/' + emotion_folder + '/' + img_file)

        face_count, feature, faces = p.feature_extraction(img)
        x = np.vstack((x, feature[0]))

        #Assigning code to each emotion
        if emotion_folder == 'sad':
            y = np.append(y, 0)
        elif emotion_folder == 'surprise':
            y = np.append(y, 1)
        elif emotion_folder == 'happy':
            y = np.append(y, 2)

#Deleting the 1st element in x array
#x = np.delete(x, 0, 0)

#np.save('/home/qburst/Desktop/dist_only_x', x)
#np.save('/home/qburst/Desktop/y', y)
Beispiel #6
0
from skimage import io
import processing as p
from sklearn.naive_bayes import GaussianNB
from sklearn.externals import joblib
import numpy as np

input_image_path = '/home/qburst/Desktop/Test images/testsaveopencvimg without resize.jpg'

input_image = io.imread(input_image_path)

##x = np.load('/home/qburst/Desktop/Emotion Classification/Numpy arrays with only distances/dist_only_x.npy')
##y = np.load('/home/qburst/Desktop/Emotion Classification/Numpy arrays with only distances/y.npy')

###initializing a NB classifier
##gnb = GaussianNB()
##gnb.fit(x, y)

##joblib.dump(gnb, '/home/qburst/Desktop/TrainedGNB.pkl')

gnb = joblib.load('/home/qburst/Desktop/TrainedGNB.pkl')

face_count, features, faces = p.feature_extraction(input_image)

emotions = gnb.predict(features)
print emotions

##for count, face in enumerate(faces):
##     gnb.predict(features[0])