def test(): import os import sys lib_path = os.path.abspath('../utilization/') sys.path.append(lib_path) from dir_processing import DirProcessing from file_op import FileOp LSF.build_dictionary() landmarks_urls = DirProcessing.get_all_landmarks_urls_from_sequence('87','4') test_one_sequence = True if test_one_sequence: video = LSF.lsf_from_sequence(landmarks_urls) print video.landmarks_urls test_one_landmark = False if test_one_landmark: landmarks = FileOp.read_landmarks_file(landmarks_urls[11]) landmarks_neural = FileOp.read_landmarks_file(landmarks_urls[0]) lsf_document = LSF.lsf(landmarks, landmarks_neural) landmark = landmarks[35,:] landmark_neural = landmarks_neural[35, :] word = LSF.compute_word(35, landmark, landmark_neural) print landmark, landmark_neural, word
def draw_landmarks_on_sequence(img_urls): from dir_processing import DirProcessing landmarks_urls = [] for i in xrange(0, len(img_urls)): img_url = img_urls[i] landmarks_url = DirProcessing.generate_landmarks_url_from_img_url(img_url) landmarks_urls.append(landmarks_url) from file_op import FileOp for i in xrange(0, len(img_urls)): img_url = img_urls[i] landmarks_url = landmarks_urls[i] img = FileOp.read_img_file(img_url) landmarks = FileOp.read_landmarks_file(landmarks_url) for i in xrange(0, landmarks.shape[0]): # for every point loc = landmarks[i, :] x = int(round(loc[0])) y = int(round(loc[1])) cv2.circle(img, (x, y), 1, 255) print img_url cv2.imshow('image', img) k = cv2.waitKey(0) if k == 27: # Esc key to stop break cv2.destroyAllWindows()
def generate_features_pool(self): """ generate train and test files for classification """ from analysis import Analysis from dir_processing import DirProcessing from file_op import FileOp landmarks_urls_list, features = Analysis.get_topic_proportions_for_every_image() subsets_dict = self.divide_persons_into_subsets() for i in range(0, len(landmarks_urls_list)): landmarks_url = landmarks_urls_list[i] label_url = DirProcessing.get_label_url_from_landmarks_url(landmarks_url) loc = DirProcessing.get_location_from_sequence(landmarks_url, 3) if label_url and loc != "MIDDLE": person_id, perform_id, index_id = DirProcessing.get_id_from_label_url(label_url) subset_id = subsets_dict[person_id] feature = features[i, :] if loc == "START": label = 0 else: label = FileOp.read_label_file(label_url) self.features_pool[subset_id].append(feature) self.labels_pool[subset_id].append(label) self.urls_pool[subset_id].append(landmarks_url) print "Features pools have been generated. "
def draw_landmarks_on_img(img_url, drawtext=False): from dir_processing import DirProcessing landmarks_url = DirProcessing.generate_landmarks_url_from_img_url(img_url) from file_op import FileOp img = FileOp.read_img_file(img_url) landmarks = FileOp.read_landmarks_file(landmarks_url) for i in xrange(0, landmarks.shape[0]): # for every point loc = landmarks[i, :] x = int(round(loc[0])) y = int(round(loc[1])) cv2.circle(img, (x, y), 2, 255) if drawtext: cv2.putText(img, str(i), (x,y), cv2.FONT_HERSHEY_SIMPLEX, 0.25, 255) cv2.imshow('image',img) cv2.waitKey(0) cv2.destroyAllWindows()
def lsf_from_sequence(landmarks_urls): """ computer the lsf feature from a expression sequence """ from file_op import FileOp landmarks_sequence = FileOp.read_landmarks_sequence(landmarks_urls) lsf_sequence = [] for i in xrange(0, len(landmarks_urls)): landmarks = landmarks_sequence[i] landmarks_neural = landmarks_sequence[0] lsf_document = LSF.lsf(landmarks, landmarks_neural) #get the lsf word feature from one image (document) lsf_sequence.append(lsf_document) return LSFSequence(landmarks_urls, landmarks_sequence, lsf_sequence)
def draw_img(img_url): from file_op import FileOp img = FileOp.read_img_file(img_url) cv2.imshow('image',img) cv2.waitKey(0) cv2.destroyAllWindows()
import cv2 import os, sys lib_path = os.path.abspath("../utilization/") sys.path.append(lib_path) from file_op import FileOp img = FileOp.read_img_file( "/Users/sangruoxin/Documents/research/dataset/CK+/cohn-kanade-images/S022/001/S022_001_00000007.png" ) cv2.imshow("img", img) cv2.waitKey(0) img = FileOp.read_img_file( "/Users/sangruoxin/Documents/research/dataset/CK+/cohn-kanade-images/S022/001/S022_001_00000001.png" ) cv2.imshow("img", img) cv2.waitKey(0) img = FileOp.read_img_file( "/Users/sangruoxin/Documents/research/dataset/CK+/cohn-kanade-images/S022/001/S022_001_00000004.png" ) cv2.imshow("img", img) cv2.waitKey(0) cv2.destroyAllWindows()