Exemplo n.º 1
0
def takePhoto():
	global photocounter
	photoids = []
	cnx = sqlconnection.connecttodb()
	cursor = cnx.cursor(dictionary=True)
	pictureSize=(1280,960)
	with picamera.PiCamera() as camera:
		camera.resolution = (2592,1944)
		time.sleep(10)
		print "start taking pictures"
		with picamera.array.PiRGBArray(camera, size=pictureSize) as output:
			while photocounter > 0:
				output.truncate(0)
				camera.capture(output, 'rgb', resize=pictureSize, use_video_port=False)
				image = Image.fromarray(output.array)
				image.show()
				query = ("INSERT INTO images (imgdata, imgtype, userid) VALUES (%s, %s, %s)")
				data, imgtype = sqlfaces.PilImg2SqlImgData(image)
				cursor.execute(query, (data, imgtype, userid))
				photoids.append(cursor.lastrowid)
				cnx.commit()
				
				photocounter -= 1
				if photocounter > 0:
					time.sleep(5)
		jsonAnswer = json.dumps({"type":"photoids","photoids":photoids})
		with open(pipename_fotoout, "a") as pipe:
						pipe.write(jsonAnswer)
		cursor.close()
	return
Exemplo n.º 2
0
def takePhoto():
    global photocounter
    photoids = []
    cnx = sqlconnection.connecttodb()
    cursor = cnx.cursor(dictionary=True)
    pictureSize = (1280, 960)
    with picamera.PiCamera() as camera:
        camera.resolution = (2592, 1944)
        time.sleep(10)
        print "start taking pictures"
        with picamera.array.PiRGBArray(camera, size=pictureSize) as output:
            while photocounter > 0:
                output.truncate(0)
                camera.capture(output, "rgb", resize=pictureSize, use_video_port=False)
                image = Image.fromarray(output.array)
                image.show()
                query = "INSERT INTO images (imgdata, imgtype, userid) VALUES (%s, %s, %s)"
                data, imgtype = sqlfaces.PilImg2SqlImgData(image)
                cursor.execute(query, (data, imgtype, userid))
                photoids.append(cursor.lastrowid)
                cnx.commit()

                photocounter -= 1
                if photocounter > 0:
                    time.sleep(5)
        jsonAnswer = json.dumps({"type": "photoids", "photoids": photoids})
        with open(pipename_fotoout, "a") as pipe:
            pipe.write(jsonAnswer)
        cursor.close()
    return
Exemplo n.º 3
0
def getLabels():
    imgs,person_labels, person_labels_num, gender_labels, gender_labels_num = [], [], [], [], []
    cnx = sqlconnection.connecttodb()
    cursor = cnx.cursor(dictionary=True)
    query = ("SELECT imgdata, userid FROM faces ORDER BY userid")
    cursor.execute(query)
    result = cursor.fetchall()
    imgs = [convertDbImgToNumpy(item["imgdata"]) for item in result]
    person_labels = [str(item["userid"]) for item in result]
    userid_set = set()
    userid_set.update(person_labels)
    userid_dict = dict()
    i = 0
    userid_num = []
    for id in userid_set:
        userid_num.append(i)
        i += 1
        query = ("SELECT sex FROM user WHERE id = %s")
        cursor.execute(query, (id, ))
        for row in cursor:
            userid_dict[id] = row["sex"].pop()
    person_dict = {
        "person2num": dict(zip(userid_set, userid_num)),
        "num2person": dict(zip(userid_num, userid_set))
    }
    for user in person_labels:
        gender_labels.append(userid_dict[user])
    cursor.close()
    cnx.close()
    gender_set = set(userid_dict.values())
    i = 0
    gender_num = []
    for gender in gender_set:
        gender_num.append(i)
        i += 1
    gender_dict = {
        "gender2num": dict(zip(gender_set, gender_num)),
        "num2gender": dict(zip(gender_num, gender_set))
    }
    for person in person_labels:
        person_labels_num.append(person_dict["person2num"][person])
    for gender in gender_labels:
        gender_labels_num.append(gender_dict["gender2num"][gender])
    return [
        imgs, person_labels_num, gender_labels_num, person_dict, gender_dict
    ]
Exemplo n.º 4
0
def updateFaces():
	cnx = sqlconnection.connecttodb()
	cursor = cnx.cursor()
	# Get all image ids where the face is not up to date or no face has been generated. Eyes coordinates must be available
	query = ("(SELECT i.id FROM images AS i "
	"INNER JOIN faces AS f "
	"ON i.id = f.id AND i.last_modified > f.last_modified) "
	"UNION "
	"(SELECT DISTINCT i.id FROM images AS i "
	"LEFT JOIN faces as f USING (id) "
	"WHERE (f.id IS NULL) AND (i.lefteye_x IS NOT NULL OR i.righteye_x IS NOT NULL))")
	cursor.execute(query)
	ids = [item[0] for item in cursor.fetchall()]
	cursor.close()
	imageToFaceCnx(ids, cnx)
	cnx.close()

	return
Exemplo n.º 5
0
def updateFaces():
    cnx = sqlconnection.connecttodb()
    cursor = cnx.cursor()
    # Get all image ids where the face is not up to date or no face has been generated. Eyes coordinates must be available
    query = (
        "(SELECT i.id FROM images AS i "
        "INNER JOIN faces AS f "
        "ON i.id = f.id AND i.last_modified > f.last_modified) "
        "UNION "
        "(SELECT DISTINCT i.id FROM images AS i "
        "LEFT JOIN faces as f USING (id) "
        "WHERE (f.id IS NULL) AND (i.lefteye_x IS NOT NULL OR i.righteye_x IS NOT NULL))"
    )
    cursor.execute(query)
    ids = [item[0] for item in cursor.fetchall()]
    cursor.close()
    imageToFaceCnx(ids, cnx)
    cnx.close()

    return
Exemplo n.º 6
0
def getLabels():
	imgs,person_labels, person_labels_num, gender_labels, gender_labels_num = [], [], [], [], []
	cnx = sqlconnection.connecttodb()
	cursor = cnx.cursor(dictionary=True)
	query = ("SELECT imgdata, userid FROM faces ORDER BY userid")
	cursor.execute(query)
	result = cursor.fetchall()
	imgs = [convertDbImgToNumpy(item["imgdata"]) for item in result]
	person_labels = [str(item["userid"]) for item in result]
	userid_set = set()
	userid_set.update(person_labels)
	userid_dict = dict()
	i = 0	
	userid_num = []
	for id in userid_set:	
		userid_num.append(i)
		i += 1
		query = ("SELECT sex FROM user WHERE id = %s")
		cursor.execute(query, (id,))
		for row in cursor: 
			userid_dict[id] = row["sex"].pop()
	person_dict	= {"person2num": dict(zip(userid_set, userid_num)),"num2person": dict(zip(userid_num,userid_set))}
	for user in person_labels:
		gender_labels.append(userid_dict[user])
	cursor.close()
	cnx.close()
	gender_set = set(userid_dict.values())
	i = 0
	gender_num = []
	for gender in gender_set:
		gender_num.append(i)
		i += 1
	gender_dict = {"gender2num": dict(zip(gender_set,gender_num)),"num2gender": dict(zip(gender_num,gender_set))}
	for person in person_labels:
		person_labels_num.append(person_dict["person2num"][person])
	for gender in gender_labels:
		gender_labels_num.append(gender_dict["gender2num"][gender])
	return [imgs, person_labels_num, gender_labels_num, person_dict, gender_dict]
Exemplo n.º 7
0
def imageToFace(ids):
	cnx = sqlconnection.connecttodb()
	imageToFaceCnx(ids, cnx)
	cnx.close()
Exemplo n.º 8
0
def imageToFace(ids):
    cnx = sqlconnection.connecttodb()
    imageToFaceCnx(ids, cnx)
    cnx.close()