Example #1
0
def process_images(num):
    images = MongoHelper.get_unprocessed(num)
    for image in images:
        process_location(image)
        process_desc(image)
        process_faces(image)
        MongoHelper.save_image(image)
Example #2
0
    def post(self):
        result = {'status': False}
        try:
            user_id = self.get_argument('user_id', '')
            user_name = self.get_argument('username', '')
            password = self.get_argument('password', '')
            lang = self.get_argument('lang', 'zh-CN')
            if user_id == '' or user_name == '' or password == '':
                self.write(json.dumps(result))
                return

            user = MongoHelper.get_user_by_id(user_id)
            if user is not None:
                self.write(json.dumps(result))
                return

            user = {
                'user_id': user_id,
                'user_name': user_name,
                'password': password,
                'lang': lang
            }
            server = Utils.allocate_user_server(user_id)
            user['server'] = server
            MongoHelper.register_user(user)
            MongoHelper.increase_server_usage(server, 1)
            result['status'] = True
            user["_id"] = ''
            result['user'] = user
            result['token'] = Utils.generate_access_token(user_id)

            FaceUtils.train_default(user_id)
        finally:
            self.write(json.dumps(result))
Example #3
0
def process_images(num):
    images = MongoHelper.get_unprocessed(num)
    for image in images:
        process_location(image)
        process_desc(image)
        process_faces(image)
        MongoHelper.save_image(image)
Example #4
0
    def post(self):
        result = {'status': False}
        Logger.debug('in login')
        try:
            user_id = self.get_argument('user_name', '')
            password = self.get_argument('password', '')
            Logger.info('userid: ' + user_id + ', pass:'******'' or password == '':
                Logger.debug('user id null')
                return

            user = MongoHelper.get_user(user_id, password)
            if user is None:
                Logger.debug('user none')
                return

            result['token'] = Utils.generate_access_token(user_id)
            user_token = result['token']
            MongoHelper.update_user_token(user_id, user_token)

            login_time = Utils.get_login_time(user_id)
            img_quota = Utils.get_img_quota(user_id, login_time)
            result['login_time'] = login_time
            result['img_quota'] = img_quota
            result['status'] = True

        finally:
            self.write(json.dumps(result))
Example #5
0
 def post(self):
     result = {'status': False}
     try:
         user_id = self.get_argument('user_id', '')
         user_name = self.get_argument('username', '')
         password = self.get_argument('password', '')
         lang = self.get_argument('lang', 'zh-CN')
         if user_id == '' or user_name == '' or password == '':
             self.write(json.dumps(result))
             return
         
         user = MongoHelper.get_user_by_id(user_id)
         if user is not None:
             self.write(json.dumps(result))
             return
         
         user = {'user_id': user_id, 'user_name': user_name, 'password': password, 'lang': lang}
         server = Utils.allocate_user_server(user_id)
         user['server'] = server
         MongoHelper.register_user(user)
         MongoHelper.increase_server_usage(server, 1)
         result['status'] = True
         user["_id"] = '';
         result['user'] = user
         result['token'] = Utils.generate_access_token(user_id)
         
         FaceUtils.train_default(user_id)
     finally:
         self.write(json.dumps(result))
Example #6
0
def process_faces(image):
    tags = image.get('tags', [])
    user_id = image.get('user_id', '')
    if not user_id:
        return
    
    exists = FaceUtils.is_person_group_exists(user_id)
    if not exists:
        FaceUtils.create_person_group(user_id)
        
    image_name = image.get('image_name', '')
    if not image_name:
        return
    
    names = Utils.get_human_names(image.get('desc', ''))
    names.reverse()
    faces = FaceUtils.detect_faces_in_photo(Utils.get_user_path(user_id) + "/" + image_name)
    result = FaceUtils.identify_faces(user_id, faces)
    
    for res in result:
        face_id = res['faceId']
        target_id = ''
        candidates = res.get('candidates', [])
        if len(candidates) > 0:
            target_id = candidates[0]
        
        if target_id:
            tags.append(target_id)
        else:
            person_id = FaceUtils.create_person(user_id, [face_id], uuid.uuid4())
            FaceUtils.train_person_group_wait(user_id)
            person = {'person_id': person_id, 'name': names.pop()}
            MongoHelper.save_person(person)
    
    image['tags'] = tags
Example #7
0
 def post(self):
     result = {'status': False}
     Logger.debug('in login')
     try:
         user_id = self.get_argument('user_name', '')
         password = self.get_argument('password', '')
         Logger.info('userid: ' + user_id + ', pass:'******'' or password == '':
             Logger.debug('user id null')
             return
         
         user = MongoHelper.get_user(user_id, password)
         if user is None:
             Logger.debug('user none')
             return
         
         result['token'] = Utils.generate_access_token(user_id)
         user_token = result['token']
         MongoHelper.update_user_token(user_id, user_token)
         
         login_time = Utils.get_login_time(user_id)
         img_quota = Utils.get_img_quota(user_id, login_time)
         result['login_time'] = login_time
         result['img_quota'] = img_quota
         result['status'] = True
             
     finally:
         self.write(json.dumps(result))
Example #8
0
def process_face_groups(image):
    faces = yield from FaceUtils.detect_faces_in_photo(
        Utils.get_user_path(image['user_id']) + "/" + image['image_name'])
    Logger.debug('processing: ' + Utils.get_user_path(image['user_id']) + "/" +
                 image['image_name'])
    #     faces = yield from FaceUtils.detect_faces_in_photo("e:/data/images/" + image['image_name'])
    #     Logger.debug('processing: ' + "e:/data/images/" + image['image_name'])
    if len(faces) == 0 or len(faces) > 10:
        return

    names = Utils.get_human_names(image.get('desc', ''))
    names.reverse()
    tags = image.get('tags', [])
    for face in faces:
        face_id = ''
        similars = yield from FaceUtils.find_similar_faces(
            image['user_id'], face)
        Logger.debug('similars: ' + str(similars))

        for simi in similars:
            conf = simi['confidence']
            if conf >= 0.9:
                face_id = simi['faceId']
                break

        if not face_id:
            Logger.debug('no face id detected')
            face_id = face
            yield from FaceUtils.add_face_to_group(image['user_id'], face)
            try:
                name = names.pop()
            except:
                name = ''

            face_info = {
                'user_id': image['user_id'],
                'face_id': face,
                'name': name,
                'candidates': similars
            }
            for simi in similars:
                fid = simi['faceId']
                sm = MongoHelper.get_person(image['user_id'], fid)
                smcd = [i['faceId'] for i in sm['candidates']]
                if not fid in smcd:
                    sm['candidates'].append({
                        'faceId': face,
                        'confidence': simi['confidence']
                    })
                MongoHelper.save_person(sm)

            MongoHelper.save_person(face_info)

        if not face_id in tags:
            tags.append(face_id)

    image['tags'] = tags
    Logger.debug('tags: ' + str(tags))
Example #9
0
def update_user_payment(user_id, plan):
    quota = MongoHelper.get_img_quota(user_id)

    for p in Config.config['payment_plans']:
        if plan is p.get('name'):
            quota += p.get('quota')
            MongoHelper.update_img_quota(user_id, quota)
            MongoHelper.update_user_payment(user_id, plan)

    return quota
Example #10
0
def update_user_payment(user_id, plan):
    quota = MongoHelper.get_img_quota(user_id)

    for p in Config.config["payment_plans"]:
        if plan is p.get("name"):
            quota += p.get("quota")
            MongoHelper.update_img_quota(user_id, quota)
            MongoHelper.update_user_payment(user_id, plan)

    return quota
Example #11
0
def update_image_tag(rawTags,userId,image_name):
                key_words = rawTags.split(' ')
                print('key_words:',key_words)
                tags = Utils.get_meaningful_keywords(key_words)
                print('tags:',tags)
                MongoHelper.extend_tags_in_existimage(userId,image_name,tags)
                
    
         
      
# if __name__ == "__main__":
#     
Example #12
0
def main(config, logger):
    # connect database and fetch the lastest segment
    target_segment = None
    mongo = None
    try:
        mongo           = MongoHelper(config)
        target_segment  = mongo.getLastSegment()
        lastest_result  = mongo.getLastResult()
    except ValueError as e:
        logger.exception(e)
        print(target_segment)
        logger.error(target_segment)
        return -1

    if mongo is None:
        logger.error("can not establish a connection")
        return -1
    elif target_segment is None:
        logger.error("something is wrong")
        return -1
    else:
        logger.info("fetch the newest segment from mongodb")

    # build a body object for each frame
    # and evaluate it based on current training
    logger.info("start evaluation of the user training")
    segment_id  = target_segment["_id"]
    segment_item= target_segment["item"]
    frames      = target_segment["frames"]
    training    = map(Body.create_body_from_frame, frames)

    # check if the lastest result is
    # for the current target_segment
    if(lastest_result is not None and segment_id == lastest_result["segment_id"]):
        logger.info("the current segment has been already evaluated")
        return 0

    # evaluate the training
    evl = evaluatorFactory(segment_id, segment_item, training)
    logger.info("start evaluation; segment_item:%s" % segment_item)
    statuses = evl.execute()

    for st in statuses: print(st.type, st.value)

    # insert an error into mongodb
    numStatuses = len(statuses)
    if(numStatuses > 0):
        random_idx  = random.randint(0, numStatuses-1)
        result      = statuses[random_idx]
        mongo.insertResult(result)
        logger.info("insert new status")
        return 0
Example #13
0
def get_img_quota(user_id, login_time):
    quota = MongoHelper.get_img_quota(user_id)

    index = next((i for i, d in enumerate(Config.config["bonus"]) if login_time in d), None)
    if index is not None:
        quota += Config.config["bonus"][index].get(login_time)

    new_date = date.today()
    if new_date.day() is 1:
        quota += Config.config["start_month_quota"]

    MongoHelper.update_img_quota(user_id, quota)
    return quota
Example #14
0
def get_img_quota(user_id, login_time):
    quota = MongoHelper.get_img_quota(user_id)

    index = next(
        (i for i, d in enumerate(Config.config['bonus']) if login_time in d),
        None)
    if index is not None:
        quota += Config.config['bonus'][index].get(login_time)

    new_date = date.today()
    if new_date.day() is 1:
        quota += Config.config['start_month_quota']

    MongoHelper.update_img_quota(user_id, quota)
    return quota
def time_api(str,user_id):
    search_string.clear()
    final.clear()
    result.clear()
    words = str.split(" ")
    global user_earliest_datetime
    user_earliest_datetime = MongoHelper.get_earliest_date(user_id)
    user_earliest_datetime_string = trans_datetime_to_string(user_earliest_datetime.year,user_earliest_datetime.month,user_earliest_datetime.day,user_earliest_datetime.hour,user_earliest_datetime.minute,user_earliest_datetime.second)
    user_earliest_datetime = datetime.datetime.strptime(user_earliest_datetime_string,'%Y-%m-%d %X %z')
    print(words)
    for word in words:
        if "_nt" in word:
             w = re.search(u'(\w+)_nt',word).group(1)
             final.append(w)
             search_string.append(w)
        if "_nd" in word:
             w = re.search(u'(\w+)_nd',word).group(1)
             final.append(w)
            
             sort_set = True
             break
    if(search_string == []):
        return None
    else:
         return parse_nl_date(search_string)
Example #16
0
 def do_post(self):
     result = {'status': False}
     Logger.debug('in DectHandler')
     try:
         userId = self.get_argument('user_id', '')
         token = self.get_argument('token','')
         user = MongoHelper.get_user_by_id(userId)
         if token != user['token']:      #add
             Logger.debug('token wrong')
             return
         
         #上传图片
         path = Utils.get_user_path(userId)    
                 #if self.request.files:
         files = self.request.files['image']
                 # process image file
         if files is None or len(files) == 0:
             self.write(json.dumps(result))
             return
         fileinfo = files[0]
         fname = fileinfo['filename']    
         fh = open(path + "/" + fname, 'wb')
         fh.write(fileinfo['body'])
         Logger.debug('complete upload')       
         faces = yield FaceUtils.detect_faces_in_photo(path + "/" + fname,userId)
         if len(faces) == 0 or len(faces) > 10:
             return
         
         
         result['faces'] = faces
                     
                 
     finally:
         self.write(json.dumps(result))
Example #17
0
    def do_post(self):
        result = {'status': False}
        Logger.debug('in DectHandler')
        try:
            userId = self.get_argument('user_id', '')
            token = self.get_argument('token', '')
            user = MongoHelper.get_user_by_id(userId)
            if token != user['token']:  #add
                Logger.debug('token wrong')
                return

            #上传图片
            path = Utils.get_user_path(userId)
            #if self.request.files:
            files = self.request.files['image']
            # process image file
            if files is None or len(files) == 0:
                self.write(json.dumps(result))
                return
            fileinfo = files[0]
            fname = fileinfo['filename']
            fh = open(path + "/" + fname, 'wb')
            fh.write(fileinfo['body'])
            Logger.debug('complete upload')

            faces = yield FaceUtils.detect_faces_in_photo(
                path + "/" + fname, userId)
            Logger.debug('faces:' + faces)
            if len(faces) == 0 or len(faces) > 10:  ##最多检测10张脸
                return
            result['faces'] = faces

        finally:
            self.write(json.dumps(result))
Example #18
0
def get_face_list(face_json,userId):
    faces = []
    try:
        for face in face_json:
            face_unit = ()
            true_faceid =''
            similars = yield find_similar_faces(userId, face['faceId'])
            Logger.debug('similars: ' + str(similars))
            for simi in similars:
                conf = simi['confidence']
                if conf >= 0.9:
                    true_faceid = simi['faceId']
                    break    
            if not true_faceid:
                Logger.debug('no face id detected')
                true_faceid = face['faceId']
                yield add_face_to_group(userId, face['faceId'])
            face_unit.append(true_faceid)
            face_unit.append(face['faceRectangle'])
            person = MongoHelper.get_person(userId, face['faceId'])
            if person['name']:
                face_unit.append(person['name'])
            else:
                face_unit.append('No Name')
            faces.append(face_unit)   
            return faces
    except Exception as e:
        Logger.error("[Errno {0}] {1}".format(e.errno, e.strerror))   
    
    return faces
Example #19
0
def get_face_list(face_json, userId):
    faces = []
    try:
        for face in face_json:
            face_unit = ()
            true_faceid = ''
            similars = yield find_similar_faces(userId, face['faceId'])
            Logger.debug('similars: ' + str(similars))
            for simi in similars:
                conf = simi['confidence']
                if conf >= 0.9:
                    true_faceid = simi['faceId']
                    break
            if not true_faceid:
                Logger.debug('no face id detected')
                true_faceid = face['faceId']
                yield add_face_to_group(userId, face['faceId'])
            face_unit.append(true_faceid)
            face_unit.append(face['faceRectangle'])
            person = MongoHelper.get_person(userId, face['faceId'])
            if person['name']:
                face_unit.append(person['name'])
            else:
                face_unit.append('No Name')
            faces.append(face_unit)
            return faces
    except Exception as e:
        Logger.error("[Errno {0}] {1}".format(e.errno, e.strerror))

    return faces
Example #20
0
 def post(self):
     result = {'status': False}
     Logger.debug('in payment')
     try:
         user_id = self.get_argument('user_id', '')
         token = self.get_argument('token', '')
         plan = self.get_argument('plan','')
         Logger.info('userid: ' + user_id + ', token:' + token + ', plan:' + plan)
         
         if user_id == '':
             Logger.debug('user id null')
             return
         
         user = MongoHelper.get_user_by_id(user_id)
         if user is None:
             Logger.debug('user none')
             return
         if token is not user['token']:
             self.write(json.dumps(result))
             Logger.debug('token wrong')
             return
         
         result['quota'] = Utils.update_user_payment(user_id, plan)
         result['status'] = True
             
     finally:
         self.write(json.dumps(result))
def process_face_groups(image):
    faces = yield from FaceUtils.detect_faces_in_photo(Utils.get_user_path(image['user_id']) + "/" + image['image_name'])
    Logger.debug('processing: ' + Utils.get_user_path(image['user_id']) + "/"  + image['image_name'])
#     faces = yield from FaceUtils.detect_faces_in_photo("e:/data/images/" + image['image_name'])
#     Logger.debug('processing: ' + "e:/data/images/" + image['image_name'])
    if len(faces) == 0 or len(faces) > 10:
        return
    
    names = Utils.get_human_names(image.get('desc', ''))
    names.reverse()
    tags = image.get('tags', [])
    for face in faces:
        face_id = ''
        similars = yield from FaceUtils.find_similar_faces(image['user_id'], face)
        Logger.debug('similars: ' + str(similars))
        
        for simi in similars:
            conf = simi['confidence']
            if conf >= 0.9:
                face_id = simi['faceId']
                break
            
        if not face_id:
            Logger.debug('no face id detected')
            face_id = face
            yield from FaceUtils.add_face_to_group(image['user_id'], face)
            try:
                name = names.pop()
            except:
                name = ''
                
            face_info = {'user_id':image['user_id'], 'face_id':face, 'name':name, 'candidates': similars}
            for simi in similars:
                fid = simi['faceId']
                sm = MongoHelper.get_person(image['user_id'], fid)
                smcd = [i['faceId'] for i in sm['candidates']]
                if not fid in smcd:
                    sm['candidates'].append({'faceId': face, 'confidence': simi['confidence']})
                MongoHelper.save_person(sm)
                
            MongoHelper.save_person(face_info)

        if not face_id in tags:
            tags.append(face_id)
        
    image['tags'] = tags
    Logger.debug('tags: ' + str(tags))
Example #22
0
def process_faces(image):
    faces = yield from FaceUtils.detect_faces_in_photo(
        Utils.get_user_path(image['user_id']) + "/" + image['image_name'])
    Logger.debug('processing: ' + Utils.get_user_path(image['user_id']) + "/" +
                 image['image_name'])
    if len(faces) == 0 or len(faces) > 10:
        return

    names = Utils.get_human_names(image.get('desc', ''))
    names.reverse()
    for face in faces:
        candidates = []
        person_id = ''
        identify_res = yield from FaceUtils.identify_faces(
            image['user_id'], [face], 3)
        if len(identify_res) > 0:
            result = identify_res[0]
            candidates = result['candidates']
            for cand in candidates:
                if cand['confidence'] > 0.9:
                    person_id = cand['personId']
                    break

        if not person_id:
            person_id = yield from FaceUtils.create_person(
                image['user_id'], [face], uuid.uuid4())
            Logger.debug('person created: ' + person_id)
            name = ''
            try:
                name = names.pop()
            except:
                pass
            person = {
                'user_id': image['user_id'],
                'person_id': person_id,
                'name': name,
                'candidates': candidates
            }
            MongoHelper.save_person(person)
            MongoHelper.add_train_person_groups(image['user_id'])

        tags = image.get('tags', set())
        tags.add(person_id)
        image['tags'] = tags
        Logger.debug('tags: ' + str(tags))
Example #23
0
def get_login_time(user_id):
    new_date = date.today()
    login_list = MongoHelper.get_login_list(user_id)

    if login_list:
        if (login_list[-1] - new_date) is timedelta(days=0):
            login_list = []
        if (login_list[-1] - new_date) is timedelta(days=1):
            login_list.append(new_date)
    else:
        login_list = []
        login_list.append(new_date)

    count = len(login_list)
    if count is 7:
        login_list = []
    MongoHelper.update_login_list(user_id, login_list)
    return count
Example #24
0
def get_login_time(user_id):
    new_date = date.today()
    login_list = MongoHelper.get_login_list(user_id)

    if login_list:
        if (login_list[-1] - new_date) is timedelta(days=0):
            login_list = []
        if (login_list[-1] - new_date) is timedelta(days=1):
            login_list.append(new_date)
    else:
        login_list = []
        login_list.append(new_date)

    count = len(login_list)
    if count is 7:
        login_list = []
    MongoHelper.update_login_list(user_id, login_list)
    return count
Example #25
0
def get_images_by_location(user_id, latitude, longitude, distance=1):
    image_unsort = []
    user_img = MongoHelper.get_images_by_user(user_id)
    location = user_img['location']           #update by peigang
    for img in user_img:
        abs_lat = abs(location['latitude'] - latitude)     #update by peigang
        abs_lon = abs(location['longitude'] - longitude)   #update by peigang
        if abs_lat < distance & abs_lon < distance:
            temp = ((abs_lat + abs_lon), img)
            image_unsort.append(temp)
    image_sort = sorted(image_unsort, key=lambda img: img[0])
    return image_sort[1]            #update by peigang
 def post(self):
     result = {'status': False}
     Logger.debug('in register')
     try:
         user_id = self.get_argument('user_id', '').lower()
         user_name = self.get_argument('user_name', '').lower()
         password = self.get_argument('password', '')
         lang = self.get_argument('lang', 'zh-CN')
         Logger.debug('user_id:' + user_id + ', user_name:' + user_name + ', password:'******'' or user_name == '' or password == '':
             self.write(json.dumps(result))
             return
         
         user = MongoHelper.get_user_by_id(user_id)
         if user is not None:
             self.write(json.dumps(result))
             return
         
         user = {'user_id': user_id, 'user_name': user_name, 'password': password, 'lang': lang}
         server = MongoHelper.allocate_user_server()
         user['server'] = server
         user['token'] = Utils.generate_access_token(user_id)
         MongoHelper.register_user(user)
         MongoHelper.increase_server_usage(server, 1)
         result['status'] = True
         user["_id"] = '';
         result['user'] = user
         result['token'] = user['token']
         result['server'] = user['server']
         
         Utils.create_face_group(user_id)
     finally:
         self.write(json.dumps(result))
Example #27
0
 def do_post(self):
     result = {'status': False}
     try:
         userId = self.get_argument('user_id', '')
         location = self.get_argument('loc', '')
         desc = self.get_argument('desc', '')
         time = self.get_argument('time', '')
         path = Utils.get_user_path(userId)
         files = self.request.files['image']
         if files is None or len(files) == 0:
             return
         
         fileinfo = files[0]
         fname = fileinfo['filename']
         fh = open(path + "/" + fname, 'wb')
         fh.write(fileinfo['body'])
         result['status'] = True
         
         image = {'user_id': userId, 'image_name': fname, 'loc': location, 'desc': desc, 'time':time, 'processed': False}
         MongoHelper.save_image(image)
     finally:
         self.write(json.dumps(result))
Example #28
0
def process_faces(image):
    tags = image.get('tags', [])
    user_id = image.get('user_id', '')
    if not user_id:
        return

    exists = FaceUtils.is_person_group_exists(user_id)
    if not exists:
        FaceUtils.create_person_group(user_id)

    image_name = image.get('image_name', '')
    if not image_name:
        return

    names = Utils.get_human_names(image.get('desc', ''))
    names.reverse()
    faces = FaceUtils.detect_faces_in_photo(
        Utils.get_user_path(user_id) + "/" + image_name)
    result = FaceUtils.identify_faces(user_id, faces)

    for res in result:
        face_id = res['faceId']
        target_id = ''
        candidates = res.get('candidates', [])
        if len(candidates) > 0:
            target_id = candidates[0]

        if target_id:
            tags.append(target_id)
        else:
            person_id = FaceUtils.create_person(user_id, [face_id],
                                                uuid.uuid4())
            FaceUtils.train_person_group_wait(user_id)
            person = {'person_id': person_id, 'name': names.pop()}
            MongoHelper.save_person(person)

    image['tags'] = tags
def process_faces(image):
    faces = yield from FaceUtils.detect_faces_in_photo(Utils.get_user_path(image['user_id']) + "/" + image['image_name'])
    Logger.debug('processing: ' + Utils.get_user_path(image['user_id']) + "/" + image['image_name'])
    if len(faces) == 0 or len(faces) > 10:
        return
    
    names = Utils.get_human_names(image.get('desc', ''))
    names.reverse()
    for face in faces:
        candidates = []
        person_id = ''
        identify_res = yield from FaceUtils.identify_faces(image['user_id'], [face], 3)
        if len(identify_res) > 0:
            result = identify_res[0]
            candidates = result['candidates']
            for cand in candidates:
                if cand['confidence'] > 0.9:
                    person_id = cand['personId']
                    break
        
        if not person_id:
            person_id = yield from FaceUtils.create_person(image['user_id'], [face], uuid.uuid4())
            Logger.debug('person created: ' + person_id)
            name = ''
            try:
                name = names.pop()
            except:
                pass
            person = {'user_id':image['user_id'], 'person_id':person_id, 'name':name, 'candidates': candidates} 
            MongoHelper.save_person(person)
            MongoHelper.add_train_person_groups(image['user_id'])
        
        tags = image.get('tags', set())
        tags.add(person_id)
        image['tags'] = tags
        Logger.debug('tags: ' + str(tags))
Example #30
0
 def post(self):
     result = {'status': False}
     try:
         user_id = self.get_argument('user_id', '')
         password = self.get_argument('password', '')
         
         if user_id == '' or password == '':
             return
         
         user = MongoHelper.get_user(user_id, password)
         if user is None:
             return
         else:
             result['status'] = True
             result['user'] = user
             result['token'] = Utils.generate_access_token(user_id)
     finally:
         self.write(json.dumps(result))
Example #31
0
    def post(self):
        result = {'status': False}
        try:
            user_id = self.get_argument('user_id', '')
            password = self.get_argument('password', '')

            if user_id == '' or password == '':
                return

            user = MongoHelper.get_user(user_id, password)
            if user is None:
                return
            else:
                result['status'] = True
                result['user'] = user
                result['token'] = Utils.generate_access_token(user_id)
        finally:
            self.write(json.dumps(result))
Example #32
0
def allocate_user_server(userId):
    servers = Config.config['servers']
    if len(servers) == 0:
        return None
    
    server_usage = MongoHelper.get_server_users()
    for name in server_usage:
        count = server_usage[name]
        capacity = 0
        for server in servers:
            if server['name'] == name:
                capacity = server['capacity']
                break
        
        if count >= capacity:
            continue
        else:
            return name
    
    return None
Example #33
0
def allocate_user_server(userId):
    servers = Config.config['servers']
    if len(servers) == 0:
        return None

    server_usage = MongoHelper.get_server_users()
    for name in server_usage:
        count = server_usage[name]
        capacity = 0
        for server in servers:
            if server['name'] == name:
                capacity = server['capacity']
                break

        if count >= capacity:
            continue
        else:
            return name

    return None
def main():
#     start_training_thread()
    loop = asyncio.get_event_loop()
    try:
        while True:
            images = MongoHelper.get_unprocessed(Config.config['image_process_batch'])
            tasks = []
            for img in images:
                tasks.append(asyncio.async(process_images(img)))
            if len(tasks) > 0:
                loop.run_until_complete(asyncio.wait(tasks))
                
#             train = MongoHelper.get_train_person_groups(10)
#             tasks = []
#             for tr in train:
#                 tasks.append(asyncio.async(train_person_group(tr['name'])))
#             if len(tasks) > 0:
#                 loop.run_until_complete(asyncio.wait(tasks))
                
            time.sleep(1)
    finally:
        loop.close()
Example #35
0
def main():
    #     start_training_thread()
    loop = asyncio.get_event_loop()
    try:
        while True:
            images = MongoHelper.get_unprocessed(
                Config.config['image_process_batch'])
            tasks = []
            for img in images:
                tasks.append(asyncio. async (process_images(img)))
            if len(tasks) > 0:
                loop.run_until_complete(asyncio.wait(tasks))


#             train = MongoHelper.get_train_person_groups(10)
#             tasks = []
#             for tr in train:
#                 tasks.append(asyncio.async(train_person_group(tr['name'])))
#             if len(tasks) > 0:
#                 loop.run_until_complete(asyncio.wait(tasks))

            time.sleep(1)
    finally:
        loop.close()
Example #36
0
    def post(self):
        result = {'status': False}
        Logger.debug('in register')
        try:
            user_id = self.get_argument('user_id', '').lower()
            user_name = self.get_argument('user_name', '').lower()
            password = self.get_argument('password', '')
            lang = self.get_argument('lang', 'zh-CN')

            Logger.debug('user_id:' + user_id + ', user_name:' + user_name +
                         ', password:'******'' or user_name == '' or password == '':
                Logger.debug('user_id or password null')
                self.write(json.dumps(result))
                return

            user = MongoHelper.get_user_by_id(user_id)
            if user is not None:
                Logger.debug('user_id is registered')
                self.write(json.dumps(result))
                return

            user = {
                'user_id': user_id,
                'user_name': user_name,
                'password': password,
                'lang': lang
            }
            server = MongoHelper.allocate_user_server()
            user['server'] = server
            user['token'] = Utils.generate_access_token(user_id)
            MongoHelper.register_user(user)
            MongoHelper.increase_server_usage(server, 1)
            result['status'] = True
            user["_id"] = ''
            result['user'] = user
            result['token'] = user['token']
            result['server'] = user['server']

            Utils.create_face_group(user_id)
        finally:
            self.write(json.dumps(result))
def process_images(image):
    yield from process_face_groups(image)
    yield from process_computor_vision(image)
    image['processed'] = True
    Logger.debug('final image: ' + str(image))
    MongoHelper.save_image(image)
Example #38
0
 def do_post(self):
     result = {'status': False}
     Logger.debug('in upload')
     try:
         userId = self.get_argument('user_id', '')
         rawLocation = self.get_argument('loc','')   #add           
         desc = [self.get_argument('tag', '')]
         rawTags = self.get_argument('tag', '')
         rowTime = self.get_argument('time', '')
         function = self.get_argument('func','')  #
         token = self.get_argument('token','')           #add
         image_name = self.get_argument('image_name','')    #add
         print('image_name:',image_name)
         print('function:',function)
         user = MongoHelper.get_user_by_id(userId)
         if token != user['token']:      #add
             Logger.debug('token wrong')
             return
         ###for images that has uploaded:if this image was existed,then the customer just want to extend image-tags###
         if function == 'UPDATE':
             print('rawTags:',rawTags)
             print('userId:',userId)
             print('image_name:',image_name)
             if not MongoHelper.check_img_exist(userId, image_name):
                 return    
             update_image_tag(rawTags,userId,image_name)
             MongoHelper.update_image_desc_and_status(desc,userId,image_name)  
             result['status'] = True
         
         elif function == 'UPLOAD':    ###for images that has not uploaded###    
             if MongoHelper.check_img_exist(userId, image_name):
                 return 
             print('userId',userId)
             print('rawTags',rawTags)
             try:
                 path = Utils.get_user_path(userId)    
             #if self.request.files:
                 files = self.request.files['image']
             # process image file
                 if files is None or len(files) == 0:
                     self.write(json.dumps(result))
                     return
                 fileinfo = files[0]
                 fname = fileinfo['filename']    
                 fh = open(path + "/" + fname, 'wb')
                 fh.write(fileinfo['body'])
             finally:
             # filter out meaningful tags
                 key_words = rawTags.split(' ')
                 print('key_words:',key_words)
                 tags = []
                 if key_words is not None and len(key_words) != 0:
                     tags = Utils.get_meaningful_keywords(key_words)
                     print('tags:',tags)
             # split date and time
                 temptime = datetime.strptime(rowTime, '%Y-%m-%d %X %z')
                 time = datetime(temptime.year, temptime.month, temptime.day, temptime.hour, temptime.minute, temptime.second, 17100)
                 
                 
                 key_location = rawLocation.split(',') # '1122, 234, beijing, zhongguan'
                 Logger.debug('key_location: ' + str(key_location))
                 raw_location_tag = []
                 if key_location is not None and len(key_location) > 1:
                     location = Utils.get_location_from_rawlocation(key_location)
                     Logger.debug('location: ' + str(location))
                     raw_location_tag = Utils.get_tag_from_rawlocation(key_location)
                     Logger.debug('raw_location_tag: ' + str(raw_location_tag))
                     tags.extend(raw_location_tag)
                     Logger.debug('tags: ' + str(tags))
                 
             
                 image = {'user_id': userId, 'image_name': fname, 'location':location, 'desc': desc, 'tags': tags, 'time':time, 'processed': False}
                 MongoHelper.save_image(image)
                 Utils.update_time_indexer(userId,image)
 #                 Utils.update_image_indexer(userId, image)
 #                 face_name = Utils.get_human_names(rawTags)
 #                 MongoHelper.update_person_list(userId,face_name)        ##此函数未写
                 result['status'] = True
     finally:
         self.write(json.dumps(result))
Example #39
0
    def do_post(self):
        result = {'status': False}
        Logger.debug('in upload')
        try:
            userId = self.get_argument('user_id', '')
            rawLocation = self.get_argument('loc', '')  #add
            desc = [self.get_argument('tag', '')]
            rawTags = self.get_argument('tag', '')
            rowTime = self.get_argument('time', '')
            function = self.get_argument('func', '')  #
            token = self.get_argument('token', '')  #add
            image_name = self.get_argument('image_name', '')  #add
            print('image_name:', image_name)
            print('function:', function)
            user = MongoHelper.get_user_by_id(userId)
            if token != user['token']:  #add
                Logger.debug('token wrong')
                return
            ###for images that has uploaded:if this image was existed,then the customer just want to extend image-tags###
            if function == 'UPDATE':
                print('rawTags:', rawTags)
                print('userId:', userId)
                print('image_name:', image_name)
                if not MongoHelper.check_img_exist(userId, image_name):
                    return
                update_image_tag(rawTags, userId, image_name)
                MongoHelper.update_image_desc_and_status(
                    desc, userId, image_name)
                result['status'] = True

            elif function == 'UPLOAD':  ###for images that has not uploaded###
                if MongoHelper.check_img_exist(userId, image_name):
                    return
                print('userId', userId)
                print('rawTags', rawTags)
                try:
                    path = Utils.get_user_path(userId)
                    #if self.request.files:
                    files = self.request.files['image']
                    # process image file
                    if files is None or len(files) == 0:
                        self.write(json.dumps(result))
                        return
                    fileinfo = files[0]
                    fname = fileinfo['filename']
                    fh = open(path + "/" + fname, 'wb')
                    fh.write(fileinfo['body'])
                finally:
                    # filter out meaningful tags
                    key_words = rawTags.split(' ')
                    print('key_words:', key_words)
                    tags = []
                    if key_words is not None and len(key_words) != 0:
                        tags = Utils.get_meaningful_keywords(key_words)
                        print('tags:', tags)
                # split date and time
                    temptime = datetime.strptime(rowTime, '%Y-%m-%d %X %z')
                    time = datetime(temptime.year, temptime.month,
                                    temptime.day, temptime.hour,
                                    temptime.minute, temptime.second, 17100)

                    key_location = rawLocation.split(
                        ',')  # '1122, 234, beijing, zhongguan'
                    Logger.debug('key_location: ' + str(key_location))
                    raw_location_tag = []
                    if key_location is not None and len(key_location) > 1:
                        location = Utils.get_location_from_rawlocation(
                            key_location)
                        Logger.debug('location: ' + str(location))
                        raw_location_tag = Utils.get_tag_from_rawlocation(
                            key_location)
                        Logger.debug('raw_location_tag: ' +
                                     str(raw_location_tag))
                        tags.extend(raw_location_tag)
                        Logger.debug('tags: ' + str(tags))

                    image = {
                        'user_id': userId,
                        'image_name': fname,
                        'location': location,
                        'desc': desc,
                        'tags': tags,
                        'time': time,
                        'processed': False
                    }
                    MongoHelper.save_image(image)
                    Utils.update_time_indexer(userId, image)
                    #                 Utils.update_image_indexer(userId, image)
                    #                 face_name = Utils.get_human_names(rawTags)
                    #                 MongoHelper.update_person_list(userId,face_name)        ##此函数未写
                    result['status'] = True
        finally:
            self.write(json.dumps(result))
Example #40
0
    def post(self):
        result = {'status': False}
        Logger.debug('in search')
        try:
            user_id = self.get_argument('user_id', '')
            desc = self.get_argument('desc','')   #add
#             desc = ['我_r 想_v 找_v 在_p 天安门_ns 的_u 照片_n']
            print('user_id:',user_id)
            rawTag = self.get_argument('tag', '')
#             rawTag = '我_r 想_v 找_v 去年_nt 夏天_nt 的_u 照片_n'
            # 我_r 想_v 找_v 去年_nt 夏天_nt 在_p 西雅图_ns 农贸市场_n 的_u 照片_n
            print('rawTag:',rawTag)
            rawLocation = self.get_argument('loc','')
            print('rawLocation:',rawLocation)
            token = self.get_argument('token','')
            print('token:',token)
            user = MongoHelper.get_user_by_id(user_id)
            print('user:'******'token']:
                self.write(json.dumps(result))
                Logger.debug('token wrong')
                return
        
            if user_id == '' or rawTag == '':
                self.write(json.dumps(result))
                return

            key_words = rawTag.split(' ')
            print(key_words)
            if key_words is None or len(key_words) == 0:
                self.write(json.dumps(result))
                return
            meaningful = Utils.get_meaningful_keywords(key_words)
            print('meaningful:',meaningful)
            if rawLocation != '': 
                key_location = rawLocation.split(',')
                print('key_locayion:',key_location)
                latitude = float(key_location[0])
                print('latitude:',latitude)
                longitude = float(key_location[1])  
                print('longitude:',longitude)
                key_location_tag = Utils.get_tag_from_rawlocation(key_location)
                print('key_location_tag:',key_location_tag)    
                meaningful.extend(key_location_tag)
                print('meaningful_add_rawlocation_tag::',meaningful)
            
            face_name = Utils.get_human_names(rawTag)
            print('face_name:',face_name)
            face_id = list(MongoHelper.get_similar_persons(user_id,face_name))  
            print('face_id:',face_id)
            if face_id :
                meaningful.extend(face_id)
                print('meaningful_add_face_id:',meaningful)
            Logger.debug("before cv: " + str(key_words))
            object_name = Utils.get_object_keywords(key_words)
            Logger.debug("before cv: " + str(object_name))
            cv_tags = Utils.translate_tags(object_name)
            Logger.debug("after cv: " + str(cv_tags))
            if cv_tags:
                meaningful.extend(cv_tags)
                print('meaningful_add_cv_tag:',meaningful)
#             Logger.debug('meaningful: ' + meaningful)

            
            time_range = NLPTimeConvertor.time_api(rawTag,user_id)
            print('time_range:',time_range)
            if time_range and rawLocation != '':
                image = Utils.get_image_by_time(user_id, time_range)
#                 image = Utils.get_images_by_tag_from_Timage(user_id,meaningful,Timage)
#                 image = Utils.sort_by_location(latitude,longitude,Tag_image)
            elif time_range and rawLocation == '':
                image = Utils.get_image_by_time(user_id, time_range)
#                 image = Utils.get_images_by_tag_from_Timage(user_id,meaningful,Timage)
            elif not time_range and rawLocation != '':
                image = Utils.get_images_by_tag(user_id, meaningful)
#                 image = Utils.sort_by_location(latitude,longitude,Tag_image)
            elif not time_range and rawLocation == '':
                Logger.debug('meaningful: ' + str(meaningful))
                image = Utils.get_images_by_tag(user_id, meaningful)

            print('image:',image)    
            result['status'] = True
            result['image'] = image
            Logger.debug('result: ' + str(result))


        finally:
            self.write(json.dumps(result))
Example #41
0
    def post(self):
        result = {'status': False}
        Logger.debug('in search')
        try:
            user_id = self.get_argument('user_id', '')
            desc = self.get_argument('desc','')
#             desc = ['我_r 想_v 找_v 在_p 天安门_ns 的_u 照片_n']
            rawTag = self.get_argument('tag', '')
#             rawTag = '我_r 想_v 找_v 今年_nt 在_p 兵马俑_ns 的_u 照片_n'
            # 我_r 想_v 找_v 去年_nt 夏天_nt 在_p 兵马俑_ns 农贸市场_n 的_u 照片_n
            rawLocation = self.get_argument('loc','')
            token = self.get_argument('token','')
            user = MongoHelper.get_user_by_id(user_id)
            Logger.info('user_id:' + user_id + ', raw tag:' + ', raw location:' + ', token:' + token)
            
            if token is not user['token']:
                self.write(json.dumps(result))
                Logger.debug('token wrong')
                return
         
            if user_id == '' or rawTag == '':
                Logger.debug('user id or tag null')
                self.write(json.dumps(result))
                return

            key_words = rawTag.split(' ')
            if key_words is None or len(key_words) == 0:
                Logger.debug('key words none')
                self.write(json.dumps(result))
                return
            
            meaningful = Utils.get_meaningful_keywords(key_words)
            if not meaningful:
                Logger.debug('meaningful key words none')
                return
            Logger.info('meaningful:' + str(meaningful))
            
            if rawLocation: 
                key_location = rawLocation.split(',')
                latitude = float(key_location[0])
                longitude = float(key_location[1])
                Logger.info('Latitude: ' + str(latitude) + ', Longitude: ' + str(longitude))
            else:
                latitude = None
                longitude = None
                Logger.info('No location info in search')
            
            face_name = Utils.get_human_names(rawTag)
            Logger.info('face name:' + str(face_name))
            face_id = list(MongoHelper.get_similar_persons(user_id,face_name))  
            Logger.info('Similar person face id:' + str(face_id))
            if face_id :
                meaningful.extend(face_id)
                Logger.info('meaningful_add_face_id:' + str(meaningful))
            Logger.debug("before cv: " + str(key_words))
            object_name = Utils.get_object_keywords(key_words)
            Logger.debug("before cv: " + str(object_name))
            cv_tags = Utils.translate_tags(object_name)
            Logger.debug("after cv: " + str(cv_tags))
            if cv_tags:
                meaningful.extend(cv_tags)
                Logger.debug('meaningful_add_cv_tag:' + str(meaningful))
            
            processed_time = NLPTimeConvertor.time_api(rawTag, user_id)
            Logger.debug('time api return:' + str(processed_time))
            
            image = []
            if processed_time[0]:
                image = Utils.get_image_by_time(user_id, processed_time[0])
            if processed_time[1]:
                meaningful.append(pypinyin.slug(processed_time[1]))
            if meaningful:
                image = Utils.get_images_by_tag(user_id, meaningful, image)
            image = Utils.sort_by_location(user_id, latitude, longitude, image)

            Logger.info('returned image:' + str(image))    
            result['status'] = True
            result['image'] = image
            Logger.debug('result: ' + str(result))


        finally:
            self.write(json.dumps(result))
Example #42
0
def update_image_tag(rawTags, userId, image_name):
    key_words = rawTags.split(' ')
    print('key_words:', key_words)
    tags = Utils.get_meaningful_keywords(key_words)
    print('tags:', tags)
    MongoHelper.extend_tags_in_existimage(userId, image_name, tags)
Example #43
0
    def do_post(self):
        result = {'status': False}
        Logger.debug('in upload')
        try:
            userId = self.get_argument('user_id', '')
            rawLocation = self.get_argument('loc', '')
            desc = [self.get_argument('tag', '')]
            rawTags = self.get_argument('tag', '')
            rowTime = self.get_argument('time', '')
            faceInfo = self.get_argument('face', '')
            token = self.get_argument('token', '')
            image_name = self.get_argument('image_name', '')
            print('image_name:', image_name)

            user = MongoHelper.get_user_by_id(userId)
            if token != user['token']:
                Logger.debug('token wrong')
                return

            print('userId', userId)
            print('rawTags', rawTags)

            try:
                path = Utils.get_user_path(userId)
                #if self.request.files:
                files = self.request.files['image']
                # process image file
                if files is None or len(files) == 0:
                    self.write(json.dumps(result))
                    return
                fileinfo = files[0]
                fname = fileinfo['filename']
                fh = open(path + "/" + fname, 'wb')
                fh.write(fileinfo['body'])

            finally:
                if not MongoHelper.check_img_exist(userId, image_name):
                    if faceInfo is not '':
                        face = faceInfo.split(' ')
                        face_final = FaceUtils.get_face_final(face)
                        # filter out meaningful tags
                    key_words = rawTags.split(' ')
                    print('key_words:', key_words)
                    tags = []
                    if key_words is not None and len(key_words) != 0:
                        tags = Utils.get_meaningful_keywords(key_words)
                        print('tags:', tags)
                        # split date and time
                    temptime = datetime.strptime(rowTime, '%Y-%m-%d %X %z')
                    time = datetime(temptime.year, temptime.month,
                                    temptime.day, temptime.hour,
                                    temptime.minute, temptime.second, 17100)

                    key_location = rawLocation.split(
                        ',')  # '1122, 234, beijing, zhongguan'
                    Logger.debug('key_location: ' + str(key_location))

                    if key_location is not None and len(key_location) > 1:
                        location = Utils.get_location_from_rawlocation(
                            key_location)
                        Logger.debug('location: ' + str(location))

                    image = {
                        'user_id': userId,
                        'image_name': fname,
                        'location': location,
                        'desc': desc,
                        'tags': tags,
                        'time': time,
                        'processed': False,
                        'face': face_final
                    }
                    MongoHelper.save_image(image)
                    Utils.update_time_indexer(userId, image)
                else:  ##图片上传过,则为更新tag或face
                    if faceInfo is not '':
                        face = faceInfo.split(' ')
                        face_final = FaceUtils.get_face_final(face)
                        MongoHelper.update_face_in_existimage(
                            userId, image_name, face_final)
                    Utils.update_image_tag(rawTags, userId, image_name)

                result['status'] = True

        finally:
            self.write(json.dumps(result))
Example #44
0
    def do_post(self):
        result = {'status': False}
        Logger.debug('in upload')
        try:
            userId = self.get_argument('user_id', '')
            rawLocation = self.get_argument('loc','')          
            desc = [self.get_argument('tag', '')]
            rawTags = self.get_argument('tag', '')
            rowTime = self.get_argument('time', '')
            faceInfo = self.get_argument('face', '')
            token = self.get_argument('token','')           
            image_name = self.get_argument('image_name','')    
            print('image_name:',image_name)
           
            user = MongoHelper.get_user_by_id(userId)
            if token != user['token']: 
                Logger.debug('token wrong')
                return

            print('userId',userId)
            print('rawTags',rawTags)
            

            try:
                path = Utils.get_user_path(userId)    
                        #if self.request.files:
                files = self.request.files['image']
                        # process image file
                if files is None or len(files) == 0:
                    self.write(json.dumps(result))
                    return
                fileinfo = files[0]
                fname = fileinfo['filename']    
                fh = open(path + "/" + fname, 'wb')
                fh.write(fileinfo['body'])

            finally:
                if not MongoHelper.check_img_exist(userId, image_name):
                    if faceInfo is not '':
                        face = faceInfo.split(' ')
                        face_final = FaceUtils.get_face_final(face)
                            # filter out meaningful tags
                    key_words = rawTags.split(' ')
                    print('key_words:',key_words)
                    tags = []
                    if key_words is not None and len(key_words) != 0:
                        tags = Utils.get_meaningful_keywords(key_words)
                        print('tags:',tags)
                            # split date and time
                    temptime = datetime.strptime(rowTime, '%Y-%m-%d %X %z')
                    time = datetime(temptime.year, temptime.month, temptime.day, temptime.hour, temptime.minute, temptime.second, 17100)
                                
                                
                    key_location = rawLocation.split(',') # '1122, 234, beijing, zhongguan'
                    Logger.debug('key_location: ' + str(key_location))
                    
                    if key_location is not None and len(key_location) > 1:
                        location = Utils.get_location_from_rawlocation(key_location)
                        Logger.debug('location: ' + str(location))
                        
                                
                            
                    image = {'user_id': userId, 'image_name': fname, 'location':location, 'desc': desc, 'tags': tags, 'time':time, 'processed': False,'face':face_final}
                    MongoHelper.save_image(image)
                    Utils.update_time_indexer(userId,image)
                else:   ##图片上传过,则为更新tag或face
                    if faceInfo is not '':
                        face = faceInfo.split(' ')
                        face_final = FaceUtils.get_face_final(face)
                        MongoHelper.update_face_in_existimage(userId,image_name,face_final)
                    Utils.update_image_tag(rawTags,userId,image_name)
                    
                    
                result['status'] = True           

        finally:
            self.write(json.dumps(result))
            

                
    
         
      
# if __name__ == "__main__":
#     
Example #45
0
    def post(self):
        result = {'status': False}
        Logger.debug('in search')
        try:
            user_id = self.get_argument('user_id', '')
            desc = self.get_argument('desc', '')
            #             desc = ['我_r 想_v 找_v 在_p 天安门_ns 的_u 照片_n']
            rawTag = self.get_argument('tag', '')
            #             rawTag = '我_r 想_v 找_v 今年_nt 在_p 兵马俑_ns 的_u 照片_n'
            # 我_r 想_v 找_v 去年_nt 夏天_nt 在_p 兵马俑_ns 农贸市场_n 的_u 照片_n
            rawLocation = self.get_argument('loc', '')
            token = self.get_argument('token', '')
            user = MongoHelper.get_user_by_id(user_id)
            Logger.info('user_id:' + user_id + ', raw tag:' +
                        ', raw location:' + ', token:' + token)

            if token is not user['token']:
                self.write(json.dumps(result))
                Logger.debug('token wrong')
                return

            if user_id == '' or rawTag == '':
                Logger.debug('user id or tag null')
                self.write(json.dumps(result))
                return

            key_words = rawTag.split(' ')
            if key_words is None or len(key_words) == 0:
                Logger.debug('key words none')
                self.write(json.dumps(result))
                return

            meaningful = Utils.get_meaningful_keywords(key_words)
            if not meaningful:
                Logger.debug('meaningful key words none')
                return
            Logger.info('meaningful:' + str(meaningful))

            if rawLocation:
                key_location = rawLocation.split(',')
                latitude = float(key_location[0])
                longitude = float(key_location[1])
                Logger.info('Latitude: ' + str(latitude) + ', Longitude: ' +
                            str(longitude))
            else:
                latitude = None
                longitude = None
                Logger.info('No location info in search')

            face_name = Utils.get_human_names(rawTag)
            Logger.info('face name:' + str(face_name))
            face_id = list(MongoHelper.get_similar_persons(user_id, face_name))
            Logger.info('Similar person face id:' + str(face_id))
            if face_id:
                meaningful.extend(face_id)
                Logger.info('meaningful_add_face_id:' + str(meaningful))
            Logger.debug("before cv: " + str(key_words))
            object_name = Utils.get_object_keywords(key_words)
            Logger.debug("before cv: " + str(object_name))
            cv_tags = Utils.translate_tags(object_name)
            Logger.debug("after cv: " + str(cv_tags))
            if cv_tags:
                meaningful.extend(cv_tags)
                Logger.debug('meaningful_add_cv_tag:' + str(meaningful))

            processed_time = NLPTimeConvertor.time_api(rawTag, user_id)
            Logger.debug('time api return:' + str(processed_time))

            image = []
            if processed_time[0]:
                image = Utils.get_image_by_time(user_id, processed_time[0])
            if processed_time[1]:
                meaningful.append(pypinyin.slug(processed_time[1]))
            if meaningful:
                image = Utils.get_images_by_tag(user_id, meaningful, image)
            image = Utils.sort_by_location(user_id, latitude, longitude, image)

            Logger.info('returned image:' + str(image))
            result['status'] = True
            result['image'] = image
            Logger.debug('result: ' + str(result))

        finally:
            self.write(json.dumps(result))
Example #46
0
def process_images(image):
    yield from process_face_groups(image)
    yield from process_computor_vision(image)
    image['processed'] = True
    Logger.debug('final image: ' + str(image))
    MongoHelper.save_image(image)
Example #47
0
def update_image_tag(rawTags, userId, image_name):
    key_words = rawTags.split(" ")
    print("key_words:", key_words)
    tags = get_meaningful_keywords(key_words)
    print("tags:", tags)
    MongoHelper.extend_tags_in_existimage(userId, image_name, tags)