def __init__(self,filename,color,cascade,READ_FILE): labeled=zip(filename,color) label=[] feature_train=[] for (fd,c) in labeled: print fd if READ_FILE is True: img=cv2.imread(fd,0) else: img = filename if img is None: print "image can't be loaded in face recog" sys.exit(0) face_cascade=cv2.CascadeClassifier(cascade) features=Feature_extractor(img) face=face_cascade.detectMultiScale( img, scaleFactor=1.1, minNeighbors=2, minSize=(10,10) ) window=face[0] (x,y,w,h)=window #print "selectkp" #print window kp=features.keypoints() selectKp=features.select_kp(window) #print selectKp for (X,Y) in selectKp: plt.scatter(X,Y,color=c) label.append(c) feature_train.append([X,Y]) #cv2.rectangle(img,(x,y),(x+w,y+h),(0,255,0),1) #cv2.imshow("image",img) self.label=label self.feature_train=feature_train
__author__ = 'Abdullah_Rahman' #r=kath threshold=0.53 filenames=("aron.jpg","sharapova_test.jpg") color=('r','b') cascade="cascades/frontalface.xml" C=KMeans(n_clusters=4) face_cascade=cv2.CascadeClassifier(cascade) image=cv2.imread("sharapova_test.jpg",0) features=Feature_extractor(image) if image is None: print "IMAGE NOT FOUND in input_image.py" sys.exit(0) face=face_cascade.detectMultiScale( image, scaleFactor=1.1, minNeighbors=2, minSize=(400,400) ) window=face[0]
return zip([i for i in range(len(A))],A) print "READING THE IMAGE FILE AND EXTRACTING KEYPOINTS" input = cv2.imread("aron.jpg",0) height = np.size(input,0) width = np.size(input,1) print height,width cascade = cv2.CascadeClassifier('cascades/frontalface.xml') model_filename = "TRAINED_SUPPORT_VECTOR_MACHINE.pkl" model = pickle.load(open(model_filename,'rb')) features = Feature_extractor(input) pt = features.keypoints() normalized=[(100*(x)/width,100*(y)/height) for (x,y) in pt] pt=[(int(x),int(y)) for (x,y) in normalized] print len(pt) print "ANALYZING FEATURES" Kp = np.asarray(pt) segments = separate(Kp,50,50) ratios = ratio_face(segments) c ={1:'r',0:'b'} X1=np.linspace(0,45,40) Y1=np.linspace(0.5,1.5,40) for x in X1: