Esempio n. 1
0
def child():
    
    pipeout = os.open(pipe_name, os.O_WRONLY)
    out_analysis = FastRadialFeatureFinder()
    image_queue = Queue.Queue()  
    worker = PipelinedWorkerProcessManager(queue_length) 
    output_queues = []
    output_queues.append(worker.output_queue)
    data = worker_loop(None,image_queue,output_queues)
    (im, guess) = data.worker_loop(None,image_queue,output_queues)
    
    out_analysis.reuse_storage = 0
    out_analysis.use_sse3 = 0
    out_analysis.filter = 'sepfir'
    
    
    while True:
        
        time.sleep(1)
       
        
        #debug code
      #  f = open('/Users/Intern/Documents/pipe_debug.txt','w')
      #  for i in len(pupil_coords):
       #    f.write(pupil_coords[i])  
        pupil_coords = out_analysis.analysis(im, guess, filter='sepfir')
        os.write(pipeout, '%d, %d \n' % (pupil_coords[0], pupil_coords[1]))
        def test_ff_on_image(test_image_name):

            print test_image_name
            test_image = double(asarray(PIL.Image.open(test_image_name)))
            if len(test_image.shape) == 3:
                test_image = mean(test_image, 2)

            radial_ff = FastRadialFeatureFinder()
            radial_ff.target_kpixels = 3.0
            radial_ff.correct_downsampling = True
            radial_ff.radius_steps = 20
            radial_ff.min_radius_fraction = 1. / 200
            radial_ff.max_radius_fraction = 1. / 5
            starburst_ff = \
                CLSubpixelStarburstEyeFeatureFinder()
            composite_ff = CompositeEyeFeatureFinder(radial_ff, starburst_ff)

            composite_ff.analyze_image(test_image, {'timestamp': 0})
            features = composite_ff.get_result()

            # do it twice to allow compilation
            composite_ff.analyze_image(test_image)
            features = composite_ff.get_result()

            plt.figure()
            plt.imshow(test_image, interpolation='nearest')
            plt.gray()
            plt.hold(True)
            cr_position = features['cr_position']
            pupil_position = features['pupil_position']

            plt.plot([cr_position[1]], [cr_position[0]], 'g+')
            plt.plot([pupil_position[1]], [pupil_position[0]], 'g+')

            sb = features['starburst']
            cr_bounds = sb['cr_boundary']
            pupil_bounds = sb['pupil_boundary']

            for b in cr_bounds:
                plt.plot([b[1]], [b[0]], 'rx')

            for b in pupil_bounds:
                plt.plot([b[1]], [b[0]], 'gx')
        def test_ff_on_image(test_image_name):

            print test_image_name
            test_image = double(asarray(PIL.Image.open(test_image_name)))
            if len(test_image.shape) == 3:
                test_image = mean(test_image, 2)

            radial_ff = FastRadialFeatureFinder()
            radial_ff.target_kpixels = 3.0
            radial_ff.correct_downsampling = True
            radial_ff.radius_steps = 20
            radial_ff.min_radius_fraction = 1. / 200
            radial_ff.max_radius_fraction = 1. / 5
            starburst_ff = \
                CLSubpixelStarburstFeatureFinder()
            composite_ff = CompositeFeatureFinder(radial_ff, starburst_ff)

            composite_ff.analyze_image(test_image, {'timestamp': 0})
            features = composite_ff.get_result()

            # do it twice to allow compilation
            composite_ff.analyze_image(test_image)
            features = composite_ff.get_result()

            plt.figure()
            plt.imshow(test_image, interpolation='nearest')
            plt.gray()
            plt.hold(True)
            cr_position = features['cr_position']
            pupil_position = features['pupil_position']

            plt.plot([cr_position[1]], [cr_position[0]], 'g+')
            plt.plot([pupil_position[1]], [pupil_position[0]], 'g+')

            sb = features['starburst']
            cr_bounds = sb['cr_boundary']
            pupil_bounds = sb['pupil_boundary']

            for b in cr_bounds:
                plt.plot([b[1]], [b[0]], 'rx')

            for b in pupil_bounds:
                plt.plot([b[1]], [b[0]], 'gx')
        def test_ff_on_image(test_image_name):

            print test_image_name
            test_image = double(asarray(PIL.Image.open(test_image_name)))
            if len(test_image.shape) == 3:
                test_image = mean(test_image, 2)
            (sobelified, x, y) = sobel3x3_separable(test_image)

            radial_ff = FastRadialFeatureFinder()
            radial_ff.target_kpixels = 3.0
            radial_ff.correct_downsampling = True
            radial_ff.radius_steps = 20
            radial_ff.min_radius_fraction = 1. / 200
            radial_ff.max_radius_fraction = 1. / 5
            starburst_ff = \
                SubpixelStarburstEyeFeatureFinder(cached_sobel=sobelified)
            composite_ff = CompositeEyeFeatureFinder(radial_ff, starburst_ff)

            composite_ff.analyze_image(test_image)
            features = composite_ff.get_result()

            # do it twice to allow compilation
            composite_ff.analyze_image(test_image)
            features = composite_ff.get_result()

            figure()
            imshow(test_image, interpolation='nearest')
            gray()
            hold(True)
            cr_position = features['cr_position']
            pupil_position = features['pupil_position']

            plot([cr_position[1]], [cr_position[0]], 'g+')
            plot([pupil_position[1]], [pupil_position[0]], 'g+')

            sb = features['starburst']
            cr_bounds = sb['cr_boundary']
            pupil_bounds = sb['pupil_boundary']

            for b in cr_bounds:
                plot([b[1]], [b[0]], 'rx')

            for b in pupil_bounds:
                plot([b[1]], [b[0]], 'rx')

            # pw = 20;
            # axis((cr_position[1]+pw, cr_position[0]+pw, cr_position[1]-pw, cr_position[0]-pw))

            figure()

            imshow(sobelified, interpolation='nearest')
            cr_ray_start = sb['cr_rays_start']
            cr_ray_end = sb['cr_rays_end']

            pupil_ray_start = sb['pupil_rays_start']
            pupil_ray_end = sb['pupil_rays_end']

            for i in range(0, len(cr_ray_start)):
                plot([cr_ray_start[i][1], cr_ray_end[i][1]],
                     [cr_ray_start[i][0], cr_ray_end[i][0]], 'r-')
            for i in range(0, len(pupil_ray_start)):
                plot([pupil_ray_start[i][1], pupil_ray_end[i][1]],
                     [pupil_ray_start[i][0], pupil_ray_end[i][0]], 'b-')

            for b in cr_bounds:
                plot([b[1]], [b[0]], 'rx')
            for b in pupil_bounds:
                plot([b[1]], [b[0]], 'rx')
Esempio n. 5
0
        def test_ff_on_image(test_image_name):

            print test_image_name
            test_image = double(asarray(PIL.Image.open(test_image_name)))
            if (len(test_image.shape) == 3):
                test_image = mean(test_image, 2)
            (sobelified, x, y) = sobel3x3_separable(test_image)

            radial_ff = FastRadialFeatureFinder()
            radial_ff.target_kpixels = 3.0
            radial_ff.correct_downsampling = True
            radial_ff.radius_steps = 20
            radial_ff.min_radius_fraction = 1. / 200
            radial_ff.max_radius_fraction = 1. / 5
            starburst_ff = SubpixelStarburstEyeFeatureFinder(
                cached_sobel=sobelified)
            composite_ff = CompositeEyeFeatureFinder(radial_ff, starburst_ff)

            composite_ff.analyze_image(test_image)
            features = composite_ff.get_result()

            # do it twice to allow compilation
            composite_ff.analyze_image(test_image)
            features = composite_ff.get_result()

            figure()
            imshow(test_image, interpolation="nearest")
            gray()
            hold(True)
            cr_position = features["cr_position"]
            pupil_position = features["pupil_position"]

            plot([cr_position[1]], [cr_position[0]], 'g+')
            plot([pupil_position[1]], [pupil_position[0]], 'g+')

            sb = features["starburst"]
            cr_bounds = sb["cr_boundary"]
            pupil_bounds = sb["pupil_boundary"]

            for b in cr_bounds:
                plot([b[1]], [b[0]], "rx")

            for b in pupil_bounds:
                plot([b[1]], [b[0]], "rx")

            #pw = 20;
            #axis((cr_position[1]+pw, cr_position[0]+pw, cr_position[1]-pw, cr_position[0]-pw))

            figure()

            imshow(sobelified, interpolation="nearest")
            cr_ray_start = sb["cr_rays_start"]
            cr_ray_end = sb["cr_rays_end"]

            pupil_ray_start = sb["pupil_rays_start"]
            pupil_ray_end = sb["pupil_rays_end"]

            for i in range(0, len(cr_ray_start)):
                plot([cr_ray_start[i][1], cr_ray_end[i][1]],
                     [cr_ray_start[i][0], cr_ray_end[i][0]], 'r-')
            for i in range(0, len(pupil_ray_start)):
                plot([pupil_ray_start[i][1], pupil_ray_end[i][1]],
                     [pupil_ray_start[i][0], pupil_ray_end[i][0]], 'b-')

            for b in cr_bounds:
                plot([b[1]], [b[0]], "rx")
            for b in pupil_bounds:
                plot([b[1]], [b[0]], "rx")