def dewarp(imagedir): # Loading from json file C = CameraParams() C.load(imagedir+"/params.json") K = cv.fromarray(C.K) D = cv.fromarray(C.D) print "loaded camera parameters" mapx = None mapy = None for f in os.listdir(imagedir): if (f.find('pgm')<0): continue image = imagedir+'/'+f print image original = cv.LoadImage(image,cv.CV_LOAD_IMAGE_GRAYSCALE) dewarped = cv.CloneImage(original); # setup undistort map for first time if (mapx == None or mapy == None): im_dims = (original.width, original.height) mapx = cv.CreateImage( im_dims, cv.IPL_DEPTH_32F, 1 ); mapy = cv.CreateImage( im_dims, cv.IPL_DEPTH_32F, 1 ); cv.InitUndistortMap(K,D,mapx,mapy) cv.Remap( original, dewarped, mapx, mapy ) tmp1=cv.CreateImage((im_dims[0]/2,im_dims[1]/2),8,1) cv.Resize(original,tmp1) tmp2=cv.CreateImage((im_dims[0]/2,im_dims[1]/2),8,1) cv.Resize(dewarped,tmp2) cv.ShowImage("Original", tmp1 ) cv.ShowImage("Dewarped", tmp2) cv.WaitKey(-1)
def getCameraWidth(self, alt): '''Using the camera parameters, with the width of the ground strip that the camera can see from a particular altitude''' #use the camera parameters c_params = CameraParams(lens=4.0) # load camera params and get the width of an image on the ground path = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'data', 'chameleon1_arecont0.json') c_params.load(path) aov = math.degrees(2.0*math.atan((c_params.sensorwidth/1000.0)/(2.0*c_params.lens/1000.0))) groundWidth = 2.0*alt*math.tan(math.radians(aov/2)) return groundWidth
class camera_state(object): def __init__(self): self.running = False self.unload = threading.Event() self.unload.clear() self.capture_thread = None self.save_thread = None self.scan_thread1 = None self.scan_thread2 = None self.transmit_thread = None self.view_thread = None self.settings = mp_settings.MPSettings([('depth', int, 8), ('gcs_address', str, None), ('gcs_view_port', int, 7543), ('bandwidth', int, 40000), ('bandwidth2', int, 2000), ('capture_brightness', int, 150), ('gamma', int, 950), ('brightness', float, 1.0), ('quality', int, 75), ('save_pgm', int, 1), ('transmit', int, 1), ('roll_stabilised', int, 1), ('minscore', int, 75), ('minscore2', int, 500), ('altitude', int, None), ('send1', int, 1), ('send2', int, 1), ('maxqueue1', int, None), ('maxqueue2', int, 30), ('thumbsize', int, 60), ('packet_loss', int, 0), ('gcs_slave', str, None)]) self.capture_count = 0 self.scan_count = 0 self.error_count = 0 self.error_msg = None self.region_count = 0 self.fps = 0 self.scan_fps = 0 self.cam = None self.save_queue = Queue.Queue() self.scan_queue = Queue.Queue() self.transmit_queue = Queue.Queue() self.viewing = False self.c_params = CameraParams(lens=4.0) self.jpeg_size = 0 self.xmit_queue = 0 self.xmit_queue2 = 0 self.efficiency = 1.0 self.last_watch = 0 self.frame_loss = 0 self.boundary = None self.boundary_polygon = None self.bandwidth_used = 0 self.rtt_estimate = 0 self.bsocket = None self.bsend2 = None self.bsend_slave = None # setup directory for images self.camera_dir = os.path.join(os.path.dirname(mpstate.logfile_name), "camera") cuav_util.mkdir_p(self.camera_dir) self.mpos = mav_position.MavInterpolator(backlog=5000, gps_lag=0.3) self.joelog = cuav_joe.JoeLog(os.path.join(self.camera_dir, 'joe.log'), append=mpstate.continue_mode) # load camera params path = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', '..', '..', 'cuav', 'data', 'chameleon1_arecont0.json') self.c_params.load(path)
class camera_state(object): def __init__(self): self.running = False self.unload = threading.Event() self.unload.clear() self.capture_thread = None self.save_thread = None self.scan_thread1 = None self.scan_thread2 = None self.transmit_thread = None self.view_thread = None self.settings = mp_settings.MPSettings( [ ('depth', int, 8), ('gcs_address', str, None), ('gcs_view_port', int, 7543), ('bandwidth', int, 40000), ('bandwidth2', int, 2000), ('capture_brightness', int, 150), ('gamma', int, 950), ('brightness', float, 1.0), ('quality', int, 75), ('save_pgm', int, 1), ('transmit', int, 1), ('roll_stabilised', int, 1), ('minscore', int, 75), ('minscore2', int, 500), ('altitude', int, None), ('send1', int, 1), ('send2', int, 1), ('maxqueue1', int, None), ('maxqueue2', int, 30), ('thumbsize', int, 60), ('packet_loss', int, 0) ] ) self.capture_count = 0 self.scan_count = 0 self.error_count = 0 self.error_msg = None self.region_count = 0 self.fps = 0 self.scan_fps = 0 self.cam = None self.save_queue = Queue.Queue() self.scan_queue = Queue.Queue() self.transmit_queue = Queue.Queue() self.viewing = False self.c_params = CameraParams(lens=4.0) self.jpeg_size = 0 self.xmit_queue = 0 self.xmit_queue2 = 0 self.efficiency = 1.0 self.last_watch = 0 self.frame_loss = 0 self.boundary = None self.boundary_polygon = None self.bandwidth_used = 0 self.rtt_estimate = 0 self.bsocket = None self.bsend2 = None # setup directory for images self.camera_dir = os.path.join(os.path.dirname(mpstate.logfile_name), "camera") cuav_util.mkdir_p(self.camera_dir) self.mpos = mav_position.MavInterpolator(backlog=5000, gps_lag=0.3) self.joelog = cuav_joe.JoeLog(os.path.join(self.camera_dir, 'joe.log'), append=mpstate.continue_mode) # load camera params path = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', '..', '..', 'cuav', 'data', 'chameleon1_arecont0.json') self.c_params.load(path)
class camera_state(object): def __init__(self): self.running = False self.unload = threading.Event() self.unload.clear() self.capture_thread = None self.save_thread = None self.scan_thread1 = None #self.scan_thread2 = None self.transmit_thread = None self.view_thread = None self.capture_count = 0 self.scan_count = 0 self.error_count = 0 self.error_msg = None self.region_count = 0 self.fps = 0 self.scan_fps = 0 self.cam = None self.save_queue = Queue.Queue() self.scan_queue = Queue.Queue() self.transmit_queue = Queue.Queue() self.viewing = False self.depth = 8 self.gcs_address = None self.gcs_view_port = 7543 self.bandwidth = 40000 self.bandwidth2 = 800 self.capture_brightness = 150 self.gamma = 950 self.c_params = CameraParams(lens=4.0) self.brightness = 1.0 self.quality = 75 self.jpeg_size = 0 self.xmit_queue = 0 self.xmit_queue2 = 0 self.efficiency = 1.0 self.last_watch = 0 self.frame_loss = 0 self.colour = 1 self.boundary = None self.boundary_polygon = None self.packet_loss = 0 self.save_pgm = True self.bandwidth_used = 0 self.rtt_estimate = 0 self.transmit = True self.roll_stabilised = True self.minscore = 3 self.altitude = None self.bsocket = None self.bsend2 = None self.send2 = False self.thumbsize = 60 # setup directory for images self.camera_dir = os.path.join(os.path.dirname(mpstate.logfile_name), "camera") cuav_util.mkdir_p(self.camera_dir) self.mpos = mav_position.MavInterpolator(backlog=5000, gps_lag=0.3) self.joelog = cuav_joe.JoeLog(os.path.join(self.camera_dir, 'joe.log'), append=mpstate.continue_mode) # load camera params path = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', '..', '..', 'cuav', 'data', 'chameleon1_arecont0.json') self.c_params.load(path)