def spawn_image_threads(num_threads, fname, bar_width, height, width):
    # change directories if it already isn't in frames
    if not 'frames' in os.getcwd():
        os.chdir('frames')

    q = queue.Queue()

    # get a distributed list of images for the threads
    images = helpers.distribute_frame_lists(num_threads)

    threads = []
    for i in range(num_threads):
        t_fname = 'thread_{}_barcode.png'.format(i)
        thread = threading.Thread(target=create_thread_barcode,
                                  args=(bar_width, height, t_fname, images[i],
                                        i, q))
        threads.append(thread)

    # stitch together several smaller barcodes on seperate threads
    # to speed up the process
    print('{} threads creating barcodes with {} frames each...'.format(
        num_threads, len(images[0])))
    print(
        'Progress bar may take a while to start moving if there are a lot of frames.'
    )
    for thread in threads:
        # thread.daemon = True
        thread.start()

    pieces_width = 0
    # a list to put the thread results in the correct order
    thread_results = [None] * num_threads
    for i in pyprind.prog_bar(range(num_threads)):
        result = q.get()
        thread_results[result[0]] = [result[1], result[2]]
        pieces_width += result[2]

    # then finally stitch together all the pices that the threads
    # generated
    print('Generating final barcode...')
    create_final_image_barcode(pieces_width, width, height, fname,
                               thread_results)

    # delete thread pieces
    for i in range(num_threads):
        os.remove('frames/thread_{}_barcode.png'.format(i))

    return
def spawn_image_threads(num_threads, fname, bar_width, height, width):
    # change directories if it already isn't in frames
    if not 'frames' in os.getcwd():
        os.chdir('frames')

    q = queue.Queue()

    # get a distributed list of images for the threads
    images = helpers.distribute_frame_lists(num_threads)
    
    threads = []
    for i in range(num_threads):
        t_fname = 'thread_{}_barcode.png'.format(i)
        thread = threading.Thread(target=create_thread_barcode, 
                                  args=(bar_width, height, t_fname, images[i], i, q))
        threads.append(thread)


    # stitch together several smaller barcodes on seperate threads
    # to speed up the process
    print('{} threads creating barcodes with {} frames each...'.format(num_threads, len(images[0])))
    print('Progress bar may take a while to start moving if there are a lot of frames.')
    for thread in threads:
        # thread.daemon = True
        thread.start()

    pieces_width = 0
    # a list to put the thread results in the correct order
    thread_results = [None] * num_threads 
    for i in pyprind.prog_bar(range(num_threads)):
        result = q.get()
        thread_results[result[0]] = [result[1], result[2]]
        pieces_width += result[2]

    # then finally stitch together all the pices that the threads
    # generated
    print('Generating final barcode...')
    create_final_image_barcode(pieces_width, width, height, fname, thread_results)

    # delete thread pieces
    for i in range(num_threads):
        os.remove('frames/thread_{}_barcode.png'.format(i))

    return
Example #3
0
def spawn_threads(threads, kmeans):
    # change directories if it already isn't in frames
    if not 'frames' in os.getcwd():
        os.chdir('frames')

    q = queue.Queue()
    num_threads = threads

    # get a distributed list of images for the threads
    images = helpers.distribute_frame_lists(num_threads)

    threads = []
    for i in range(num_threads):
        if kmeans:
            thread = threading.Thread(target=kc.get_image_colors,
                                      args=(i, q, images[i]))
        else:
            thread = threading.Thread(target=pc.get_image_colors,
                                      args=(i, q, images[i]))

        threads.append(thread)

    print('{} threads generating frame colors with {} frames each...'.format(
        num_threads, len(images[0])))
    for thread in threads:
        thread.daemon = True
        thread.start()

    thread_results = [None] * num_threads
    for i in pyprind.prog_bar(range(num_threads)):
        result = q.get()
        thread_results[result[0]] = result[1]

    # return to the original directory
    os.chdir('..')

    return [item for sublist in thread_results for item in sublist]
def spawn_threads(threads, kmeans):
    # change directories if it already isn't in frames
    if not 'frames' in os.getcwd():
        os.chdir('frames')

    q = queue.Queue()
    num_threads = threads

    # get a distributed list of images for the threads
    images = helpers.distribute_frame_lists(num_threads)

    threads = []
    for i in range(num_threads):
        if kmeans:
            thread = threading.Thread(target=kc.get_image_colors,
                                      args=(i, q, images[i]))
        else:
            thread = threading.Thread(target=pc.get_image_colors,
                                      args=(i, q, images[i]))

        threads.append(thread)

    print('{} threads generating frame colors with {} frames each...'.format(num_threads, len(images[0])))
    for thread in threads:
        thread.daemon = True
        thread.start()

    thread_results = [None] * num_threads
    for i in pyprind.prog_bar(range(num_threads)):
        result = q.get()
        thread_results[result[0]] = result[1]

    # return to the original directory
    os.chdir('..')

    return [item for sublist in thread_results for item in sublist]