I created and trained an SVM emotion classifier using a set of 700 image samples and after applying some testing, it scored very well. My problem is that when I use the svm.predict
function that I used to score the classifier on the current frame (after I extracted the HOG features), I get the error "samples.cols == var_count && samples.type() == 5 in function predict". I made sure my extracted features are float32 numpy arrays. If someone could help me find out why this is happening and how to solve it, I would really appreciate it! Thank you in advance.
# Create video capture object
video_capture = cv2.VideoCapture(0);
# Start creating loop, using webcam image every frame
while True:
# read method returns two elements, the last being the last frame captured by the camera - the _ allows us to ignore the first element
_, frame = video_capture.read();
# convert the camera frame into a grayscale version
grayscale_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
# Create dependancies for live detection
aoi = grayscale_frame;
aoi = pre_process_img(aoi);
# Extract feature
current_frame_features = hog.compute(aoi, (64, 64));
# Convert features to numpay array
current_frame_features = np.array(current_frame_features, dtype = np.float32);
# Use classifier to make a prediction
predicted_label = my_svm.predict(current_frame_features);
# Print the prediction on our frame
display_text = "Emotion: " + str(predicted_label);
font = cv2.FONT_HERSHEY_SIMPLEX;
cv2.putText(frame, display_text, (10, 50), font, 1, (255,255,255), 2, cv2.LINE_AA);
# Use open CV to display the final camera frame
cv2.imshow('Video', frame);
# implement way to discontinue the application
if cv2.waitKey(1) & 0xFF == ord('q'):
break
video_capture.release();
# destroy window
cv2.destroyAllWindows();