Пример #1
0
    def post(self):
        args = self.reqparse.parse_args()
        file = request.files['uploadFile']
        if file and upload.allowed_file(file.filename):

            filename = upload.generate_new_filename(file)
            savepath = os.path.join(app.config['UPLOAD_FOLDER'], filename)
            abspath = os.path.join(os.path.abspath(''), savepath)
            file.save(abspath)

            # call search_by_image(indexmatrix, imagepath) to get images list
            imagesrst = imagesearch.search_image(abspath,
                                     current_app.codebook,
                                     current_app.tfidf)
            imagesrst = imagesrst[::-1]
            businessinfo = upload.result_in_order(mongo.db, imagesrst)
            res = {
                'result': businessinfo,
                'status': { 'text': None, 'file': abspath }
            }

            return Response(
                json_util.dumps(res, default=json_util.default),
                mimetype='application/json'
            )
Пример #2
0
    def get(self):
        args = self.reqparse.parse_args()
        abspath = args['file']
        query = args['query']
        offset = args['offset'];

        if offset:
            if abspath:
                imagesrst = imagesearch.search_image(abspath,
                                            current_app.codebook,
                                            current_app.tfidf)

                # result_list = findhelper.find_image_by_id(mongo.db,
                #                              imagesrst, offset)
                
                imagesrst = imagesrst[::-1]
                result_list = upload.result_in_order(mongo.db, imagesrst, offset)

            elif query:
                if query == 'homepage':
                    imagesrst = current_app.randimages
                    # result_list = findhelper.find_image_by_id(mongo.db, 
                    #                             imagesrst, offset)
                    result_list = upload.result_in_order(mongo.db, imagesrst, offset)
                else:
                    result_list = findhelper.find_image_by_text(mongo.db,
                                             query, offset)
        else:
            if query == 'homepage':
                # imagesrst = [int(10000*random.random()) for i in xrange(50)]
                # current_app.randimages = imagesrst
                # result_list = findhelper.find_image_by_id(mongo.db, 
                #                             imagesrst)
                location = 'hoboken'
                imagesrst = findhelper.homepage_image(mongo.db, location)
                current_app.randimages = imagesrst
                result_list = upload.result_in_order(mongo.db, imagesrst)
            else:
                result_list = findhelper.find_image_by_text(mongo.db, query)

        res = {
            'result': result_list,
            'status': { 'text': query, 'file': abspath }
        }

        return Response(
            json_util.dumps(res),
            mimetype='application/json'
        )