Ejemplo n.º 1
0
def upload_client_avatar(client_id):
    data = request.get_json()
    if not data:
        return jsonify(status="failed", message="No Data Sent!")
    if not data.get('type'):
        return jsonify(status="failed", message="Image type required!")
    if not data.get('img'):
        return jsonify(status="failed", message="Image data not sent!")
    if data.get('type').lower() not in Config.ALLOWED_EXTENSIONS:
        return jsonify(status="failed", message="Extension not supported!")

    client = Client.query.get(client_id)
    if not client:
        return jsonify(status='failed', message='Admin Not Found')

    unique_filename = str(uuid.uuid4()) + '.' + data['type'].lower()
    if client.img:
        delete_file(client.img, Config.AVATAR_UPLOAD_FOLDER)

    save_image(
        unique_filename,
        data['img'],
        Config.AVATAR_UPLOAD_FOLDER,
        Config.AVATAR_SIZE, True
    )
    client.img = unique_filename

    db.session.commit()

    return jsonify(
        status='success',
        message='Client Avatar Upload',
        data=ClientSchema().dump(client)
    )
Ejemplo n.º 2
0
    def to_text(self):
        image = cv2.imread(self.image_location)
        gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
        gray = cv2.threshold(gray, 0, 255,
                             cv2.THRESH_BINARY | cv2.THRESH_OTSU)[1]

        file_location = '{}.png'.format(os.getpid())
        cv2.imwrite(file_location, gray)

        text = pytesseract.image_to_string(Image.open(file_location))
        delete_file(file_location)
        print(text)

        cv2.imshow('Image', image)
        cv2.imshow('Output', gray)
        cv2.waitKey(0)
        return text
Ejemplo n.º 3
0
def delete_image(mapper, connection, target):
    delete_file(target.img, Config.ADVERT_UPLOAD_FOLDER)
Ejemplo n.º 4
0
from app.checker import Checker
from app.ocr import OCR
from app.prober import Prober
from app.utils import seconds_to_time, delete_file


if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument('-f', '--file-location', required=True, help="path to input video to be OCR'd")
    parser.add_argument('-n', '--number-frames', default=5, type=int, help="number of frames")
    args = vars(parser.parse_args())

    file_location = args['file_location']
    number_of_frames = args['number_frames']

    prober = Prober(file_location)
    duration = prober.get_video_duration()
    prober.generate_frame(number_of_frames, duration)

    checker = Checker()
    is_spam = False
    for frame in range(number_of_frames):
        image_name = '{file_location}_{frame}.png'.format(file_location=file_location, frame=frame)
        ocr = OCR(image_name)
        text = ocr.to_text()
        is_spam = is_spam or checker.is_spam(text)
        delete_file(image_name)
    print('Ini adalah: {status}'.format(status='Spam' if is_spam else 'Ham'))
    sys.exit(1)