def on_status(self, status): global backoff backoff = BACKOFF # Collect logging and debugging data tweet_id = status.id tweet_text = status.text tweet_from = status.user.screen_name if tweet_from.lower() in BLACKLIST or hasattr(status, "retweeted_status"): return True logging.info("on_status: %s--%s" % (tweet_id, tweet_text)) # Parse tweet for search term tagged_users, img_url = parse_tweet(status) filename = download_image(img_url) try: result_filename = process(filename) if not result_filename: api.update_status( status="@%s Could not find any faces there.." % tweet_from, in_reply_to_status_id=tweet_id ) return True reply_tweet = generate_reply_tweet(tagged_users) reply_status = api.update_with_media( filename=result_filename, status=reply_tweet, in_reply_to_status_id=tweet_id ) logging.info("on_status_sent: %s %s" % (reply_status.id_str, reply_status.text)) except Exception, e: logging.error("face_detect error: %s" % e) err_tweet = "@%s Something' not quite right here. cc: @karangoel" % tweet_from reply_status = api.update_status(status=err_tweet, in_reply_to_status_id=tweet_id)
def post(self): # get and save original picture data = self.get_argument("data") picData = base64.b64decode(data) pic_file = open("static/original.jpg", "w") pic_file.write(picData) pic_file.close() # face detection region = face_detect.process("static/original.jpg", "static/detected.jpg") # pretreatment pic_pretreatment.process( region, grayfile="static/gray.jpg", smoothfile="static/smooth.jpg", equfile="static/equ.jpg" ) self.write("uploadok")
def post(self): # get picture and sid pic = self.get_argument("pic") sid = self.get_argument("sid") picData = base64.b64decode(pic) buf = StringIO.StringIO() buf.write(picData) buf.seek(0) face_tmp_path = "static/records/faces/%s_tmp.jpg" % sid grayface_tmp_path = "static/records/grayfaces/%s_tmp.jpg" % sid # face detection region = face_detect.process(imgData = buf, outfile = face_tmp_path) # pretreatment if region: pic_pretreatment.process(region, powfile = grayface_tmp_path, ) self.write("success") else: self.write("failed")
def post(self): pic = self.get_argument("pic") sid = self.get_argument("sid") picData = base64.b64decode(pic) buf = StringIO.StringIO() buf.write(picData) buf.seek(0) # face detection region = face_detect.process(imgData = buf) # pretreatment if region: cvImage = pic_pretreatment.process(region) cv2Data = numpy.asarray(cvImage[:]) # get mean and eigenvectors from DB db = dbhandler.DBHandler() try: mean, eigenvectors = db.get_pca() except: print "Error: Failed to get mean and eigenvectors from DB" # project # convert mean and eigenvectors to numpy array mean_list = [float(i) for i in mean.split(" ")] mean_numpy = numpy.asarray(mean_list[:]).reshape(1, -1) vec_strings = [s for s in eigenvectors.split("|")] eigenvectors_list = [] for vec_str in vec_strings: vec_list = [float(i) for i in vec_str.split(" ")] eigenvectors_list.append(vec_list) eigenvectors_numpy = numpy.asarray(eigenvectors_list[:]).reshape(len(eigenvectors_list),-1) # get eigenface eigenface = face_recognise.get_eigenface(mean_numpy, eigenvectors_numpy, cvData = cv2Data) # compute distance staff = db.get_staff(sid = sid) if len(staff) == 0: self.write("-2") # sid is not exist return False eface_str = staff[0]["eigenface"] staff_dis = float(staff[0]["distance"]) eface = [float(i) for i in eface_str.split(" ")] dis = L1(eigenface[0], eface) ''' print eigenface[0] print eface print dis ''' if dis <= staff_dis: image_path = "static/records/checkin/%s_%s.jpg" % (sid, datetime.now().strftime("%Y-%m-%d_%H-%M-%S")) buf.seek(0) image = Image.open(buf) image.save(image_path, "JPEG", quality = 80) msg = checkin.checkin(sid, image_path) if msg[1] == -1 or msg[1] == 0: os.remove(image_path) # check in error reponse_msg = str(msg[1]) + '|' + msg[0] self.write(reponse_msg) print msg[0] else: self.write("-1") else: self.write("-1")