import sys import numpy as np from ldgp import calcgrad from ldgp import hist import easygui def dist(x,y): return np.sqrt(np.sum((x-y)**2)) path=easygui.fileopenbox("select the image") image=cv2.imread(path,0) image=cv2.resize(image,(240,240)) naming=np.load("database/naming.npy") labels=np.load("database/labels.npy") data=np.load("database/data.npy") grad=calcgrad(image) histogram=hist(grad) a=[] for i in xrange(len(data)): a.append(dist(histogram,data[i])) b=np.copy(a) temp=np.copy(labels) temp2=np.copy(labels) a,temp=zip(*sorted(zip(a,temp))) b,locations=zip(*sorted(zip(b,temp2))) for i in xrange(10):
print "USAGE python client1.py <ip of server> <port of server>" ip = sys.argv[1] port = int(sys.argv[2]) ret = s.connect((ip, port)) #print ret while True: ret, frame = camera.read() gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) faces = face_cascade.detectMultiScale(gray, 2.5, 3) for (x, y, w, h) in faces: face = gray[y:y + h, x:x + w] face = cv2.resize(face, (240, 240)) gradient = calcgrad(face) #gradient=4*gradient #gradient=np.array(gradient,dtype='uint8') histogram = hist(gradient) histogram = str(histogram) print 'histogram', histogram s.sendall(histogram) print 'histogram sent' name = s.recv(4096) cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 3) font = cv2.FONT_HERSHEY_SIMPLEX #cv2.putText(frame,naming[labels[0]],(x,y), font, 0.5,(255,255,255),2,cv2.LINE_AA) cv2.putText(frame, name, (x, y), font, 0.5, (255, 255, 255), 2, cv2.LINE_AA) print "" cv2.imshow("original", frame) k = cv2.waitKey(5) & 0xFF if k == 27: break
import os import sys import numpy as np import cv2 from ldgp import calcgrad from ldgp import hist path = sys.argv[1] naming = [] labels = [] locations = [] data = [] k = 0 for folders in os.listdir(path): folder = path + '/' + folders naming.append(folders) for images in os.listdir(folder): image = folder + '/' + images print image locations.append(image) labels.append(k) data.append( hist(calcgrad(cv2.resize(cv2.imread(image, 0), (240, 240))))) k += 1 os.chdir("database") np.save("naming", np.array(naming)) np.save("labels", np.array(labels)) np.save("locations", np.array(locations)) np.save("data", np.array(data))