示例#1
0
文件: _main.py 项目: xiaottang2/OldCR
def render():
    session_id = request.args.get('session_id', 0)
    path = request.args.get('imageUrl', '')
    pixDeg = request.args.get('pixDeg', 1)
    leakgDeg = request.args.get('leakgDeg', 0)
    leakdDeg = request.args.get('leakdDeg', 0)
    spotMaxNum = request.args.get('spotMaxNum', 15)
    spotNumVariance = request.args.get('spotNumVariance', 10)
    spotBaseColor = request.args.get('spotBaseColor', '#FF0000')
    spotBaseColorRGB = _util.hex_to_rgb(spotBaseColor)
    spotColorVariance = request.args.get('spotColorVariance', 20)
    spotBlur = request.args.get('spotBlur', 0)
    spotNoise = request.args.get('spotNoise', 0)
    paperColor = request.args.get('paperColor', '#5C1C56')
    paperColorRGB = _util.hex_to_rgb(paperColor)

    splited = path.split('/')
    filename = splited[len(splited)-1]

    thisRender =  (
        session_id,
        path, #'imageUrl'
        pixDeg,  #'pixDeg'
        leakgDeg,  #'leakgDeg' 
        leakdDeg,  #'leakdDeg' 
        spotMaxNum,  #'spotMaxNum' 
        spotNumVariance,  #'spotNumVariance' 
        spotBaseColor,  #'spotBaseColor' 
        spotColorVariance,  #'spotColorVariance'
        spotBlur,  #'spotBlur'
        spotNoise,  #'spotNoise' 
        paperColor,  #'paperColor' 
        filename, #'filename' 
        'RENDER', # 'action'
        )
    _util.saveRenderToDB(thisRender)
    
    poorTyper = _process_image.ImagePoortyper(filename, isFadeGeneral=False, isFadeShallow=True, isLeakDown=True, leakDeg=leakgDeg, leakHeight=leakdDeg, spotMaxNum=spotMaxNum, spotNumVariance=spotNumVariance, spotBaseColor=spotBaseColorRGB, spotColorVariance=spotColorVariance, spotBlur=spotBlur, spotNoise=spotNoise, paperColor=paperColorRGB)
    filename_rendered = poorTyper.render()
    # filename_rendered = poorTyper.printWtRotNScl(leakdDeg)
    pixelator = _process_image.ImagePixelator(filename_rendered)
    filename_rendered_pixed = pixelator.pixelate(degree=pixDeg)
    return jsonify(result=url_for('static', filename=('created/' + filename_rendered_pixed)))
示例#2
0
文件: _main.py 项目: xiaottang2/OldCR
def train():
    # imgUrl = request.args.get('imageUrl', '')
    # splited = imgUrl.split('/')
    # imgName = splited[len(splited)-1]
    # imgPath = _util.getImagePath(imgName)
    session_id = request.args.get('session_id', 0)
    imageUrl = request.args.get('imageUrl', '') # only for debugging purposes
    pixDeg = request.args.get('pixDeg', 1)
    leakgDeg = request.args.get('leakgDeg', 0)
    leakdDeg = request.args.get('leakdDeg', 0)
    spotMaxNum = request.args.get('spotMaxNum', 15)
    spotNumVariance = request.args.get('spotNumVariance', 10)
    spotBaseColor = request.args.get('spotBaseColor', '#FF0000')
    spotBaseColorRGB = _util.hex_to_rgb(spotBaseColor)
    spotColorVariance = request.args.get('spotColorVariance', 20)
    spotBlur = request.args.get('spotBlur', 0)
    spotNoise = request.args.get('spotNoise', 0)
    paperColor = request.args.get('paperColor', '#5C1C56')
    paperColorRGB = _util.hex_to_rgb(paperColor)

    # Draw Image with actual training text
    text = request.args.get('text', trainingText)
    drawer = _create_image.ImageDrawer(text, _util.size_training)
    path = drawer.drawImage() # Note we re-assign 

    # Get filename and absolute imgPath
    splited = path.split('/')
    filename = splited[len(splited)-1]

    poorTyper = _process_image.ImagePoortyper(filename, trainingText=trainingText, trainingSize=_util.size_training, isFadeGeneral=False, isFadeShallow=True, isLeakDown=True, leakDeg=leakgDeg, leakHeight=leakdDeg, spotMaxNum=spotMaxNum, spotNumVariance=spotNumVariance, spotBaseColor=spotBaseColorRGB, spotColorVariance=spotColorVariance, spotBlur=spotBlur, spotNoise=spotNoise, paperColor=paperColorRGB)
    filename_rendered = poorTyper.render()

    pixelator = _process_image.ImagePixelator(filename_rendered)
    filename_rendered_pixed = pixelator.pixelate(degree=pixDeg)

    imgPath = _util.getImagePath(filename_rendered_pixed)

    thisRender =  (
        session_id,
        path, #'imageUrl'
        pixDeg,  #'pixDeg'
        leakgDeg,  #'leakgDeg' 
        leakdDeg,  #'leakdDeg' 
        spotMaxNum,  #'spotMaxNum' 
        spotNumVariance,  #'spotNumVariance' 
        spotBaseColor,  #'spotBaseColor' 
        spotColorVariance,  #'spotColorVariance'
        spotBlur,  #'spotBlur'
        spotNoise,  #'spotNoise' 
        paperColor,  #'paperColor' 
        filename, #'filename' 
        'TRAIN', # 'action'
        )
    _util.saveRenderToDB(thisRender)


    trainer = _train_tesseract.Trainer(imgPath) # absolute path
    traineddataPath = trainer.train()
    if (traineddataPath is not None):
        return jsonify(status='success', result=url_for('static',filename=traineddataPath))
    return jsonify(status='fail')