示例#1
0
def get_features(bw):
    features = []
    objects = get_objects(bw)
    tulang = zhangsuen.penulangan(bw)
    for object in objects:
        feature = get_feature(tulang[object[0]-1:object[1]+2, object[2]-1:object[3]+2])
        features.append(feature)
    return features
示例#2
0
def main(path):
    img = gambar.read(path)
    gray = gambar.to_gray(img)
    bw = gambar.to_bw(gray)
    tulang = zhangsuen.penulangan(bw)
    
    with open('ocr_train.json') as infile:
        train = json.load(infile)
    
    results = []
    objects = get_objects(bw)
    for object in objects:
        feature = get_feature(tulang[object[0]-1:object[1]+2, object[2]-1:object[3]+2])
        results.append(classify(train, feature))
    return ''.join(results)
示例#3
0
def main():
    method = sys.argv[1]
    input = sys.argv[2]
    id = sys.argv[3]
    home = os.path.expanduser('~')+'\\.IF5181\\'
    dir = home+id+'\\'

    if not os.path.isdir(dir):
        if os.path.isdir(home):
            shutil.rmtree(home, ignore_errors=True)
        if not os.path.isdir(home):
            os.mkdir(home)
        os.mkdir(dir)

    os.chdir('py')
    
    if method == 'histogram':
        img = gambar.read(input)
        hist = gambar.get_histogram(img)
        json_save({
            'r': list(gambar.get_histogram(img[:, :, 0])),
            'g': list(gambar.get_histogram(img[:, :, 1])),
            'b': list(gambar.get_histogram(img[:, :, 2])),
        }, dir+'histogram.json')

    elif method == 'equalize':
        img = gambar.read(input)
        gray = gambar.to_gray(img)
        hist_gray = gambar.get_histogram(gray)
        result, hist_result = gambar.equalize(gray, hist_gray)
        
        gambar.save(gray, dir+'gray.jpg')
        json_save(list(hist_gray), dir+'histogram_gray.json')
        
        gambar.save(result, dir+'equalized.jpg')
        json_save(list(hist_result), dir+'histogram_equalized.json')
    
    elif method == 'otsu':
        img = gambar.read(input)
        
        gray = gambar.to_gray(img)
        gambar.save(gray, dir+'gray.jpg')
        
        bw = gambar.to_bw(gray)
        gambar.save(bw, dir+'binary.jpg')
    
    elif method == 'derajat0':
        img = gambar.read(input)
        
        gray = gambar.to_gray(img)
        gambar.save(gray, dir+'gray.jpg')
        
        average = konvolusi.derajat0(gray, 'average')
        gambar.save(average, dir+'derajat0-average.jpg')
        
        homogen = konvolusi.derajat0(gray, 'homogen')
        gambar.save(homogen, dir+'derajat0-homogen.jpg')
        
        difference = konvolusi.derajat0(gray, 'difference')
        gambar.save(difference, dir+'derajat0-difference.jpg')
    
    elif method == 'derajat1':
        img = gambar.read(input)
        
        gray = gambar.to_gray(img)
        gambar.save(gray, dir+'gray.jpg')
        
        sobel = konvolusi.derajat1(gray, 'sobel')
        gambar.save(sobel, dir+'derajat1-sobel.jpg')
        
        prewitt = konvolusi.derajat1(gray, 'prewitt')
        gambar.save(prewitt, dir+'derajat1-prewitt.jpg')
    
    elif method == 'derajat2':
        img = gambar.read(input)
        
        gray = gambar.to_gray(img)
        gambar.save(gray, dir+'gray.jpg')
        
        kirsch = konvolusi.derajat2(gray, 'kirsch')
        gambar.save(kirsch, dir+'derajat2-kirsch.jpg')
        
        prewitt = konvolusi.derajat2(gray, 'prewitt')
        gambar.save(prewitt, dir+'derajat2-prewitt.jpg')
    
    elif method == 'gauss':
        img = gambar.read(input)
        gambar.save(konvolusi.gaussian(img), dir+'gauss.jpg')
    
    elif method == 'chaincode':
        img = gambar.read(input)
        gray = gambar.to_gray(img)
        bw = gambar.to_bw(gray)
        gambar.save(bw, dir+'binary.jpg')
        
        kopong = gambar.koponging(bw)
        gambar.save(kopong, dir+'kopong.jpg')
        
        code = chaincode.get_chaincode(kopong)
        belok = chaincode.get_kodebelok(code)
        json_save(code, dir+'chaincode.json')
        json_save(belok, dir+'kodebelok.json')
    
    elif method == 'skeleton':
        img = gambar.read(input)
        gray = gambar.to_gray(img)
        bw = gambar.to_bw(gray)
        gambar.save(bw, dir+'binary.jpg')
        
        tulang = zhangsuen.penulangan(bw)
        gambar.save(tulang, dir+'tulang.jpg')
        
        ujung, simpangan = zhangsuen.get_identity(tulang)
        json_save({
            'ujung': [[int(y), int(x)] for y, x in ujung],
            'simpangan': [[int(y), int(x)] for y, x in simpangan],
        }, dir+'tulang-identity.json')
        
        code = zhangsuen.get_chaincode(tulang)
        belok = chaincode.get_kodebelok(code)
        json_save(code, dir+'tulang-chaincode.json')
        json_save(belok, dir+'tulang-kodebelok.json')
    
    elif method == 'ocr':
        result = ocr.main(input)
        json_save({
            'result': result
        }, dir+'ocr-result.json')
    
    elif method == 'face-warna':
        img = gambar.read(input)
        
        masker = wajah.get_masker(img)
        maskered = wajah.draw_masker(img, masker)
        gambar.save(maskered, dir+'face-masker.jpg')
        
        wajahs = wajah.get_wajahs(masker)
        kotaked = wajah.draw_kotak(img, wajahs)
        gambar.save(kotaked, dir+'face-kotak.jpg')
    
    elif method == 'face-bentuk':
        img = gambar.read(input)
        wajah.limatitik(img)
        wajah.titikobjek(img)
    
    elif method == 'face-recognition':
        facer.main(input)