def calibrationDisplay(source, display, loop=False): key = None frame = 0 t0 = time.time() span = 30 while key != 27: source.updatePlayMode() display.update() key = cv2.waitKey(10) if key >= 0: char = chr(key) print "Key: ", key, char if frame == 150: key == 27 break frame += 1 if frame % span == 0: t1 = time.time() print "{0:8.5f} fps".format(span / (t1 - t0)) t0 = t1 if loop: source.increment()
def test_process_objects(source=None): ''' Tests process objects. Returns a set of displays that need to be updated. ''' displays = [] source_display = Display(input=source,title='source') displays.append(source_display) source.updatePlayMode() source.update() # test dark current callibrator # source -> dc_collector dc_collector = Image_Mean(input=source,max_frames=30)#,max_frames=300) dc_collector_display = Display(input=dc_collector,title='dc_collector') displays.append(dc_collector_display) # collect until we have enough data raw_input('Press any key when ready to collect dark current input...') while( dc_collector.get_frame_count() < dc_collector.get_max_frames() ): source.updatePlayMode() dc_collector.update() print 'Dark current collected and calibrated.' dark_current_image = dc_collector.getOutput(0).getData()#self.calibrate_dark_current() # create pipeline for ff # source -> dc corrector -> rgb2xyz -> mean dark_current_corrector = Dark_Current_Corrector(input=source, dark_current_image=dark_current_image) dark_current_corrector_display = Display(input=dark_current_corrector, title='dark current correction') displays.append(dark_current_corrector_display) rgb2xyz = ConvertRGBtoXYZ(input=dark_current_corrector) rgb2xyz_display = Display(input=rgb2xyz, title='cie xyz (will look bad)') displays.append(rgb2xyz_display) # test flat field callibrator dark_current_corrector.update() #TODO: need to get an image before creating an Image_Mean, please be aware of this, or better yet, change it rgb2xyz.update() ff_collector = Image_Mean(input=rgb2xyz,max_frames=30) ff_collector_display = Display(input=ff_collector, title='ff_collector') displays.append(ff_collector_display) raw_input('Press any key when ready to collect flat field input...') while( ff_collector.get_frame_count() < ff_collector.get_max_frames() ): source.updatePlayMode() dark_current_corrector.update() rgb2xyz.update() ff_collector.update() #print 'collected ',str(ff_collector.get_frame_count()) print 'Flat field callibration input collected.' # calculate F(x) from Y channel # F(x) = F(x) = (ff mean intensity) / (ff correction image) flat_field_image = ff_collector.getOutput(0).getData()[:,:,1].astype(numpy.float) print flat_field_image flat_field_image = flat_field_image.mean() / flat_field_image print flat_field_image.dtype # test flat_field_corrector flat_field_corrector = Flat_Field_Corrector(input=rgb2xyz,flat_field_image=flat_field_image) flat_field_corrector_display = Display(input=flat_field_corrector,title='flat field correction') displays.append(flat_field_corrector_display) # test color_corrector (using information from flat_field_calibrator) # Calibrate on X channel for now x_mean = ff_collector.getOutput(0).getData()[:,:,0].mean() z_mean = ff_collector.getOutput(0).getData()[:,:,2].mean() print 'x mean:',str(x_mean),' z_mean:',str(z_mean) color_corrector = Color_Corrector(input=flat_field_corrector, x_mean=x_mean, z_mean=z_mean, reference_mean=x_mean) # test xyz2rgb #rgb2xyzTEST = ConvertRGBtoXYZ(input=source) #rgb2xyzTEST.update() #xyz2rgbTEST = ConvertXYZtoRGB(input=rgb2xyzTEST) #xyz2rgbTEST_display = Display(input=xyz2rgbTEST, title='test xyz2rgb') #displays.append(xyz2rgbTEST_display) xyz2rgb_ff = ConvertXYZtoRGB(input=flat_field_corrector) xyz2rgb_ff_display = Display(input=xyz2rgb_ff, title='flat field in rgb') displays.append(xyz2rgb_ff_display) xyz2rgb = ConvertXYZtoRGB(input=color_corrector) xyz2rgb_display = Display(input=xyz2rgb,title='color corrected in rgb') displays.append(xyz2rgb_display) return displays
if __name__ == "__main__": #main = Main(source_name='camera') source = open_source('camera') displays = test_calibrator(source) #test_process_objects(source) # loop to update displays and pull from source print 'done, start up the displays' key = None frame = 0 t0 = time.time() span = 30 while key != 27: source.updatePlayMode() for d in displays: d.update() #map(update, displays) key = cv2.waitKey(33) frame += 1 if frame % span == 0: t1 = time.time() print "{0:8.5f} fps".format(span / (t1 - t0)) t0 = t1 print "done, bye"