Examples

vtest_main.py

import os
import subprocess as sp

## make list of files in folder
fileList = os.listdir(os.getcwd())
f = open('vision_test_results', 'w')

## iterate over list of files (jpegs only)
for photo in fileList:
    if 'JPG' in photo:
        output = sp.check_output(['./VisionTest',
        photo, 'sample_threshold_matrix.xml'])
        print output
        outputf = output.split(',')
## write out name of file and result
        f.write(outputf[0] + ' ')
        f.write(outputf[6] + '\n')
f.close()

self_identify.py

import numpy as np
import os
from matplotlib import pyplot as plt

namingcounter = 0
## get a list of current files in directory
filelist = os.listdir(os.getcwd())
fig = plt.figure()


def onclick(event):
    print 'button=%d, x=%d, y=%d, xdata=%f, ydata=%f'%(
        event.button, event.x, event.y, event.xdata, event.ydata)
    ## rename file with expected x and y
    os.rename(image,'%dLOC_%d_%d.JPG'%(namingcounter,event.xdata,event.ydata))
    plt.close()
    
## connect to onclick event    
cid = fig.canvas.mpl_connect('button_press_event', onclick)

## iterate over list and deal with only JPGs
for image in filelist:
    if 'JPG' in image:
        namingcounter += 1
        img = plt.imread(image,0)
        plt.imshow(img, cmap = 'gray', interpolation = 'bicubic')        
        
        plt.show()
	## create new figure for next loop
        fig = plt.figure()
        cid = fig.canvas.mpl_connect('button_press_event', onclick)


Advertisements