Exemplo n.º 1
0
def main():
    '''main function'''
    app_name = 'split.py'
    data = myutil.read_setting('setting.json')

    home = os.environ["HOME"]
    image = home + '/' + data[app_name]['image_file']

    if not os.path.exists(image):
        print("image not found {}!".format(image))
        exit(1)

    setup_windows()

    img = cv2.imread(image)
    split_and_show(img)

    mrg = apply_mean(img)
    output_img('merged.png', mrg)

    newimg = preprocess(img)
    output_img('preproc.png', newimg)

    print('press any key to quit...')
    cv2.waitKey()
    # When everything done, release the capture
    cv2.destroyAllWindows()
Exemplo n.º 2
0
def main():
    ''' main function '''
    parser = argparse.ArgumentParser(description='''
        example scripts to run module sp or lcp
        to test if specified integers are prime numbers or not
    ''', usage='''
    (auto)     $ run_example.py
    (integers) $ run_example.py 97 101 307''')
    parser.add_argument("ints", metavar='int', type=int, nargs='*',
        help="specify some integers to test primes")
    #parser.add_argument("-v", "--verbose", action='store_true', help='verbose')
    parser.add_argument("-l", "--lcp", action='store_true', help='run lcp, LoadCompressPrime')
    args = parser.parse_args()

    # if args.lcp:
    #     print('run lcp')
    # else:
    #     print('run sp')

    data = read_setting('setting.json')
    txtfn = data['prime_large']
    pfn = data['pickle_large']
    print(txtfn, pfn)

    if args.lcp:
        with LoadCompressPrime() as lcp:
            test(args.ints, lcp)
    else:
        with StorePrime(txtfn, pfn) as sp:
            test(args.ints, sp)
Exemplo n.º 3
0
def main(argv):
    ''' main '''
    data = read_setting('setting.json')
    prime_big = data['prime_big']
    prime_path = data['prime_path']
    paths = []
    paths.append(get_home())
    paths.append(get_home() + '/' + prime_path)
    fn = _try_fn(prime_big, paths)
    sz = get_filesize(fn)
    lnc = bufcount(fn)
    print(f'text file: {fn}, size: {sz}, lines: {lnc}')
    res = get_nth_line_from_file(fn, 1)
    print(f'first line: {res}')
    res = get_nth_line_from_file(fn, lnc)
    print(f'last line: {res}')

    targets = [2, 15485863, 1, 16999777]
    if not argv:
        for _ in range(6):
            targets.append(random.randint(2, 15485863))
    else:
        targets = [int(x) for x in argv]

    for t in targets:
        print(f'search {t} ... ', end='')
        (p, q) = search_from_file(t, fn, lnc)
        if p is not None:
            print(f'between ({p}, {q})')
    print('total IO calls:', TOTAL_CALLS)
Exemplo n.º 4
0
def main():
    '''main function'''
    WIN_NAME = 'foobar'
    cv2.namedWindow(WIN_NAME)
    cv2.moveWindow(WIN_NAME, 50, 50)
    if len(sys.argv) > 1:  # has argument
        for ff in sys.argv[1:]:
            print('imread {}'.format(ff))
            img = cv2.imread(ff)
            cv2.imshow(WIN_NAME, img)
            cv2.waitKey(0)
    else:
        setting_fn = 'setting.json'
        if not myutil.isfile(setting_fn):
            print('[ERROR] cannot find setting: {}'.format(setting_fn))
            print('[INFO] may use argument')
        else:
            app_name = 'readim.py'
            data = myutil.read_setting(setting_fn)
            home = os.environ['HOME']
            picpath = home + '/' + data[app_name]['path']
            print(picpath)

        for img_file in data[app_name]['images']:
            pic1 = picpath + '/' + img_file
            print(pic1)
            if os.path.isfile(pic1):
                cv_test(pic1)
            else:
                print("file not found: {}".format(pic1))

    #cv_drawline()
    cv2.destroyAllWindows()
Exemplo n.º 5
0
def main():
    '''main function'''
    WIN_NAME = 'foobar'
    cv2.namedWindow(WIN_NAME)
    cv2.moveWindow(WIN_NAME, 50, 50)
    if len(sys.argv) > 1:   # has argument
        for ff in sys.argv[1:]:
            print('imread {}'.format(ff))
            img = cv2.imread(ff)
            cv2.imshow(WIN_NAME, img)
            cv2.waitKey(0)
    else:
        setting_fn = 'setting.json'
        if not myutil.isfile(setting_fn):
            print('[ERROR] cannot find setting: {}'.format(setting_fn))
            print('[INFO] may use argument')
        else:
            app_name = 'readim.py'
            data = myutil.read_setting(setting_fn)
            home = os.environ['HOME']
            picpath = home + '/' + data[app_name]['path']
            print(picpath)

        for img_file in data[app_name]['images']:
            pic1 = picpath + '/' + img_file
            print(pic1)
            if os.path.isfile(pic1):
                cv_test(pic1)
            else:
                print("file not found: {}".format(pic1))

    #cv_drawline()
    cv2.destroyAllWindows()
Exemplo n.º 6
0
def main():
    '''main function'''
    app_name = 'split.py'
    data = myutil.read_setting('setting.json')

    home = os.environ["HOME"]
    image = home + '/' + data[app_name]['image_file']

    if not os.path.exists(image):
        print("image not found {}!".format(image))
        sys.exit(1)

    setup_windows()

    img = cv2.imread(image)
    split_and_show(img)

    mrg = apply_mean(img)
    output_img('merged.png', mrg)

    newimg = preprocess(img)
    output_img('preproc.png', newimg)

    print('press any key to quit...')
    cv2.waitKey()
    # When everything done, release the capture
    cv2.destroyAllWindows()
Exemplo n.º 7
0
 def read_config(self):
     ''' read settings from json '''
     app_name = self.name
     data = myutil.read_setting('setting.json')
     try:
         self.width = data[app_name]['width']
         self.height = data[app_name]['height']
     except KeyError:
         print('no such key, fallback using default values')
     print('config read...')
Exemplo n.º 8
0
 def read_config(self):
     ''' read settings from json '''
     app_name = self.name
     data = myutil.read_setting('setting.json')
     try:
         self.width = data[app_name]['width']
         self.height = data[app_name]['height']
     except KeyError:
         print('no such key, fallback using default values')
     print('config read...')
Exemplo n.º 9
0
 def read_config(self):
     ''' read settings from json '''
     app_name = self.name
     data = myutil.read_setting('setting.json')
     try:
         #self.foobar = data[app_name]['foo_bar']
         self.video_index = data[app_name]['video_index']
         print("video input from: {}".format(self.video_index))
         self.width = data[app_name]['width']
         self.height = data[app_name]['height']
         self.sigma_x = data[app_name]['sigma_x']
         self.sigma_y = data[app_name]['sigma_y']
     except KeyError:
         print('no such key, fallback using default values')
     print('config read...')
Exemplo n.º 10
0
def main():
    '''main function'''
    app_name = 'imgur.py'
    data = myutil.read_setting('setting.json')
    json_data = data[app_name]['picture']
    title = 'deer'
    fn = 'deer.png'

    if myutil.isfile(fn):
        print('file {} already exists, will not download'.format(fn))
    else:
        fn = try_to_download(json_data, title)

    im = Image.open(fn)
    im.show()
Exemplo n.º 11
0
 def read_config(self):
     ''' read settings from json '''
     app_name = self.name
     data = myutil.read_setting('setting.json')
     try:
         #self.foobar = data[app_name]['foo_bar']
         self.video_index = data[app_name]['video_index']
         print("video input from: {}".format(self.video_index))
         self.width = data[app_name]['width']
         self.height = data[app_name]['height']
         self.sigma_x = data[app_name]['sigma_x']
         self.sigma_y = data[app_name]['sigma_y']
     except KeyError:
         print('no such key, fallback using default values')
     print('config read...')
Exemplo n.º 12
0
def main():
    '''main function'''
    app_name = 'imgur.py'
    data = myutil.read_setting('setting.json')
    json_data = data[app_name]['picture']
    title = 'deer'
    fn = 'deer.png'

    if myutil.isfile(fn):
        print('file {} already exists, will not download'.format(fn))
    else:
        fn = try_to_download(json_data, title)

    im = Image.open(fn)
    im.show()
Exemplo n.º 13
0
def main():
    '''main function'''
    app_name = 'loadimgur.py'
    data = myutil.read_setting('setting.json')
    url = data[app_name]['lego']

    print('url: {}'.format(url))
    # pylint: disable=using-constant-test
    if False:
        ofn = "output.jpg"
        print('url:{} => {}'.format(url, ofn))
        img = fetch_image(url, ofn)
    else:
        img = load_image(url)

    io.imshow(img)
    io.show()
Exemplo n.º 14
0
Arquivo: fc.py Projeto: ericosur/ccbox
def test_proc():
    json = read_setting('setting.json')
    #print(json['base_dir'])
    for ii in range(json['min'], json['max']):
        #print('ii: {}'.format(ii))
        test_with_setting(json, str(ii))