def initialize(): # Initialize the ASI camera library and confirm we have at least one ASI camera connected: # # Note that this application will always pick the first camera - fine for me because I will only have one camera connected but could be an issue if that is not the case for you. If you need support for more than one ASI camera, edit the code below accordingly. global camera # Hard coded library location as fallback: #TODO: Generalize this so that library does not need to be hard coded ASI_LIBRARY = "/usr/local/lib/libASICamera2.so" asi.init(ASI_LIBRARY) num_cameras = asi.get_num_cameras() if num_cameras == 0: print('No cameras found') sys.exit(0) else: cameras_found = asi.list_cameras() print('Found %d cameras' % num_cameras) for n in range(num_cameras): print(' %d: %s' % (n, cameras_found[n])) camera_id = 0 print('Using #%d: %s' % (camera_id, cameras_found[camera_id])) # Setup Camera: camera = asi.Camera(camera_id) return camera
def __init__(self, config): if zwoasi.zwolib is None: # Must initialise the library if config.has_option('camera', 'sdk'): sdk_filename = config.get('camera', 'sdk') else: # Hope the user has set LD_LIBRARY_PATH or similar.. sdk_filename = None zwoasi.init(sdk_filename) num_cameras = zwoasi.get_num_cameras() if num_cameras == 0: raise Exception('no camera present') if config.has_option('camera', 'model'): id_ = config.get('camera', 'model') try: # Assume it is an integer id_ = int(id_) except ValueError: # No it wasn't, must be the model name then pass else: id_ = 0 self.camera = zwoasi.Camera(id_) self.config = config self.capture_image_lock = threading.Lock()
def __init__(self): config = yaml.safe_load(open('solar_config.yml', 'r')) self.sio = socketio.Client() self.sio.connect(config['socketServer']) try: asi.init('./camera_software/lib/mac/libASICamera2.dylib') except: pass num_cameras = asi.get_num_cameras() if num_cameras == 0: print('No cameras found') sys.exit(0) self.camera = asi.Camera(0) self.camera_info = self.camera.get_camera_property() self.controls = self.camera.get_controls() self.camera.set_control_value(asi.ASI_BANDWIDTHOVERLOAD, self.camera.get_controls()['BandWidth']['MinValue']) self.camera.disable_dark_subtract() self.camera.set_control_value(asi.ASI_GAIN, 50) self.camera.set_control_value(asi.ASI_EXPOSURE, 800) self.camera.set_control_value(asi.ASI_GAIN, 100) self.camera.set_control_value(asi.ASI_EXPOSURE, 1000) self.camera.set_control_value(asi.ASI_WB_B, 99) self.camera.set_control_value(asi.ASI_WB_R, 75) self.camera.set_control_value(asi.ASI_GAMMA, 50) self.camera.set_control_value(asi.ASI_BRIGHTNESS, 50) self.camera.set_control_value(asi.ASI_FLIP, 0)
def init_cam(): asi.init(".\\ASICamera2.dll") num_cameras = asi.get_num_cameras() if num_cameras == 0: print('No cameras found') sys.exit(0) cameras_found = asi.list_cameras() # Models names of the connected cameras camera_id = 0 camera = asi.Camera(camera_id) print("found camera") camera.disable_dark_subtract() camera.set_control_value(asi.ASI_BANDWIDTHOVERLOAD, 40) camera.set_control_value(asi.ASI_GAIN, 20) camera.set_control_value(asi.ASI_EXPOSURE, int(0.00001 * 1000000)) camera.set_control_value(asi.ASI_GAMMA, 50) camera.set_control_value(asi.ASI_BRIGHTNESS, 85) camera.set_control_value(asi.ASI_FLIP, 0) camera.set_control_value(asi.ASI_FLIP, 0) camera.set_control_value(asi.ASI_HIGH_SPEED_MODE, 0) camera.set_control_value(asi.ASI_TARGET_TEMP, -14) camera.set_control_value(asi.ASI_COOLER_ON, 1) camera.set_control_value(asi.ASI_HARDWARE_BIN, 1) camera.set_roi(bins=3) camera.set_image_type(asi.ASI_IMG_RAW16) print("ready") return camera
def __init__(self,config, base =''): self.base_directory = base # load the SDK library asi.init(self.base_directory + "\dependencies\ASICamera2.dll") # initialize the camera self.camera = asi.Camera(0) # set 16 bit integer image type self.camera.set_image_type(asi.ASI_IMG_RAW16) # set gain for maximum dynamic range self.camera.set_control_value(asi.ASI_GAIN, 0) if socket.gethostname() == 'minerva19-01': self.xsize = 3096 self.ysize = 2080 else: self.xsize=1936 self.ysize=1216 self.guideimagelastupdate = datetime.datetime.utcnow() self.guidestarx = np.nan self.guidestary = np.nan self.x1 = 1 self.x2 = self.xsize self.y1 = 1 self.y2 = self.ysize self.imageReady = False # make it full frame self.camera.set_roi(start_x=0, start_y=0, width=self.xsize, height=self.ysize) self.img = np.asarray([])
def open(self): """Open module.""" BaseCamera.open(self) # init driver asi.init(self._sdk_path) # get number of cameras num_cameras = asi.get_num_cameras() if num_cameras == 0: raise ValueError('No cameras found') # get ID of camera # index() raises ValueError, if camera could not be found cameras_found = asi.list_cameras() camera_id = cameras_found.index(self._camera_name) # open driver self._camera = asi.Camera(camera_id) self._camera_info = self._camera.get_camera_property() log.info('Camera info:') for key, val in self._camera_info.items(): log.info(' - %s: %s', key, val) # Set some sensible defaults. They will need adjusting depending upon # the sensitivity, lens and lighting conditions used. self._camera.disable_dark_subtract() self._camera.set_control_value(asi.ASI_GAIN, 150) self._camera.set_control_value(asi.ASI_WB_B, 99) self._camera.set_control_value(asi.ASI_WB_R, 75) self._camera.set_control_value(asi.ASI_GAMMA, 50) self._camera.set_control_value(asi.ASI_BRIGHTNESS, 50) self._camera.set_control_value(asi.ASI_FLIP, 0) self._camera.set_image_type(asi.ASI_IMG_RAW16) # Enabling stills mode try: # Force any single exposure to be halted self._camera.stop_video_capture() self._camera.stop_exposure() except (KeyboardInterrupt, SystemExit): raise except: pass # get initial window and binning self._binning = self._camera.get_bin() self._window = self._camera.get_roi()
def main1(self): asi.init(self.zwo_asi_lib) num_cameras = asi.get_num_cameras() if num_cameras == 0: logging.error('No cameras found') sys.exit(0) camera = asi.Camera(0) camera.set_control_value(asi.ASI_BANDWIDTHOVERLOAD, camera.get_controls()['BandWidth']['MinValue']) try: while True: self.take_exposure(camera, self.build_filename()) time.sleep(self.inter_exposure_delay_seconds) except KeyboardInterrupt: print('Manual break by user') except asi.ZWO_CaptureError as e: logging.error('Error capturing' + str(e))
def __init__(self): logging.basicConfig( format='%(asctime)s %(levelname)s:falcon ZWOcamera %(message)s', level=logging.INFO) logging.info("Starting falcon ZWO Camera Server") self.env_filename = os.getenv('ZWO_ASI_LIB') if self.env_filename: asi.init(self.env_filename) else: logging.error('The filename of the SDK library is required \ (or set ZWO_ASI_LIB environment variable with the filename)') sys.exit(1) num_cameras = asi.get_num_cameras() if num_cameras == 0: logging.error('No cameras found') sys.exit(0) cameras_found = asi.list_cameras( ) # Models names of the connected cameras if num_cameras == 1: camera_id = 0 logging.info('Found one camera: %s' % cameras_found[0]) else: logging.info('Found %d cameras' % num_cameras) for n in range(num_cameras): logging.info(' %d: %s' % (n, cameras_found[n])) # TO DO: allow user to select a camera camera_id = 0 logging.info('Using #%d: %s' % (camera_id, cameras_found[camera_id])) self.camera = asi.Camera(camera_id) self.initCamera() # Accept connections on all tcp addresses, port 5555 self.sender = imageTransport.ImageSender(connect_to='tcp://*:5555', REQ_REP=False) self.zmqcontext = zmq.Context() self.myCmdSocket = self.zmqcontext.socket(zmq.REP) self.myCmdSocket.bind("tcp://*:5556") self.RUN = True self.CMDThread = self.zmqQueue() signal.signal(signal.SIGINT, self.signal_handler)
def setup_camera(camera_id): camera = asi.Camera(camera_id) camera_info = camera.get_camera_property() # Get all of the camera controls print('') print('Camera controls:') controls = camera.get_controls() for cn in sorted(controls.keys()): print(' %s:' % cn) for k in sorted(controls[cn].keys()): print(' %s: %s' % (k, repr(controls[cn][k]))) # Use minimum USB bandwidth permitted camera.set_control_value(asi.ASI_BANDWIDTHOVERLOAD, camera.get_controls()['BandWidth']['MinValue']) # Set some sensible defaults. They will need adjusting depending upon # the sensitivity, lens and lighting conditions used. camera.disable_dark_subtract() camera.set_control_value(asi.ASI_GAIN, 150) camera.set_control_value(asi.ASI_EXPOSURE, 30000) camera.set_control_value(asi.ASI_WB_B, 99) camera.set_control_value(asi.ASI_WB_R, 75) camera.set_control_value(asi.ASI_GAMMA, 50) camera.set_control_value(asi.ASI_BRIGHTNESS, 50) camera.set_control_value(asi.ASI_FLIP, 0) print('Enabling stills mode') try: # Force any single exposure to be halted camera.stop_video_capture() camera.stop_exposure() except (KeyboardInterrupt, SystemExit): raise except: pass # turn on high speed mode # camera.set_control_value(asi.ASI_HIGH_SPEED_MODE, 1) return camera
def __init__(self): try: asi.init('/home/jllama/asi_software/lib/x64/libASICamera2.so') except: pass num_cameras = asi.get_num_cameras() if num_cameras == 0: print('No cameras found') sys.exit(0) self.camera = asi.Camera(0) self.camera_info = self.camera.get_camera_property() self.controls = self.camera.get_controls() self.camera.set_control_value( asi.ASI_BANDWIDTHOVERLOAD, self.camera.get_controls()['BandWidth']['MinValue']) self.camera.disable_dark_subtract() self.camera.set_control_value(asi.ASI_GAIN, 60) self.camera.set_control_value(asi.ASI_EXPOSURE, 1500) self.camera.set_control_value(asi.ASI_WB_B, 99) self.camera.set_control_value(asi.ASI_WB_R, 75) self.camera.set_control_value(asi.ASI_GAMMA, 50) self.camera.set_control_value(asi.ASI_BRIGHTNESS, 50) self.camera.set_control_value(asi.ASI_FLIP, 0)
def capture_asi(buf, z1, t1, z2, t2, nx, ny, nz, tend, device_id, live, gain, maxgain, autogain, exposure, bins, brightness, bandwidth, high_speed, hardware_bin, sdk): # Array flag first = True # Initialize device asi.init(sdk) camera = asi.Camera(device_id) camera_info = camera.get_camera_property() logger.info('ASI Camera info: %s' % camera_info) logger.info(camera_info['MaxHeight']) camera.set_control_value(asi.ASI_BANDWIDTHOVERLOAD, bandwidth) camera.disable_dark_subtract() camera.set_control_value(asi.ASI_GAIN, gain, auto=autogain) camera.set_control_value(asi.ASI_EXPOSURE, exposure, auto=False) camera.set_control_value(asi.ASI_AUTO_MAX_GAIN, maxgain) camera.set_control_value(asi.ASI_AUTO_MAX_BRIGHTNESS, 20) camera.set_control_value(asi.ASI_WB_B, 99) camera.set_control_value(asi.ASI_WB_R, 75) camera.set_control_value(asi.ASI_GAMMA, 50) camera.set_control_value(asi.ASI_BRIGHTNESS, brightness) camera.set_control_value(asi.ASI_FLIP, 0) camera.set_control_value(asi.ASI_HIGH_SPEED_MODE, high_speed) camera.set_control_value(asi.ASI_HARDWARE_BIN, hardware_bin) camera.set_roi(bins=binning) camera.start_video_capture() camera.set_image_type(asi.ASI_IMG_RAW8) # Fix autogain if autogain: while True: # Get frame z = camera.capture_video_frame() # Break on no change in gain settings = camera.get_control_values() if gain == settings["Gain"]: break gain = settings["Gain"] camera.set_control_value(asi.ASI_GAIN, gain, auto=autogain) # Loop until reaching end time while float(time.time()) < tend: # Get settings settings = camera.get_control_values() gain = settings["Gain"] temp = settings["Temperature"] / 10.0 logging.info("Capturing frame with gain %d, temperature %.1f" % (gain, temp)) # Set gain if autogain: camera.set_control_value(asi.ASI_GAIN, gain, auto=autogain) # Get frames for i in range(nz): # Store start time t0 = float(time.time()) # Get frame z = camera.capture_video_frame() # Compute mid time t = (float(time.time()) + t0) / 2.0 # Display Frame if live is True: cv2.imshow("Capture", z) cv2.waitKey(1) # Store results if first: z1[i] = z t1[i] = t else: z2[i] = z t2[i] = t # Assign buffer ready if first: buf.value = 1 else: buf.value = 2 # Swap flag first = not first # End capture logger.info("Exiting capture") camera.stop_video_capture()
def get_Camera_photo(fileName): env_filename = os.getenv('ZWO_ASI_LIB') parser = argparse.ArgumentParser(description='Process and save images from a camera') parser.add_argument('filename', nargs='?', help='SDK library filename') args = parser.parse_args() # Initialize zwoasi with the name of the SDK library if args.filename: asi.init(args.filename) elif env_filename: asi.init(env_filename) else: print('The filename of the SDK library is required (or set ZWO_ASI_LIB environment variable with the filename)') sys.exit(1) num_cameras = asi.get_num_cameras() if num_cameras == 0: print('No cameras found') sys.exit(0) cameras_found = asi.list_cameras() # Models names of the connected cameras if num_cameras == 1: camera_id = 0 print('Found one camera: %s' % cameras_found[0]) else: print('Found %d cameras' % num_cameras) for n in range(num_cameras): print(' %d: %s' % (n, cameras_found[n])) # TO DO: allow user to select a camera camera_id = 0 print('Using #%d: %s' % (camera_id, cameras_found[camera_id])) camera = asi.Camera(camera_id) camera_info = camera.get_camera_property() # Get all of the camera controls print('') print('Camera controls:') controls = camera.get_controls() for cn in sorted(controls.keys()): print(' %s:' % cn) for k in sorted(controls[cn].keys()): print(' %s: %s' % (k, repr(controls[cn][k]))) # Use minimum USB bandwidth permitted camera.set_control_value(asi.ASI_BANDWIDTHOVERLOAD, camera.get_controls()['BandWidth']['MinValue']) # Set some sensible defaults. They will need adjusting depending upon # the sensitivity, lens and lighting conditions used. camera.disable_dark_subtract() camera.set_control_value(asi.ASI_GAIN, 150) camera.set_control_value(asi.ASI_EXPOSURE, 20000) camera.set_control_value(asi.ASI_WB_B, 99) camera.set_control_value(asi.ASI_WB_R, 75) camera.set_control_value(asi.ASI_GAMMA, 50) camera.set_control_value(asi.ASI_BRIGHTNESS, 50) camera.set_control_value(asi.ASI_FLIP, 0) print('Enabling stills mode') try: # Force any single exposure to be halted camera.stop_video_capture() camera.stop_exposure() except (KeyboardInterrupt, SystemExit): raise except: pass print('Capturing a single 8-bit mono image') filename =fileName+ '_image_mono.jpg' camera.set_image_type(asi.ASI_IMG_RAW8) camera.capture(filename=filename) print('Saved to %s' % filename) save_control_values(filename, camera.get_control_values()) print('Capturing a single 16-bit mono image') filename = 'image_mono16.tiff' camera.set_image_type(asi.ASI_IMG_RAW16) camera.capture(filename=filename) print('Saved to %s' % filename) save_control_values(filename, camera.get_control_values()) if camera_info['IsColorCam']: filename = fileName+'image_color.jpg' camera.set_image_type(asi.ASI_IMG_RGB24) print('Capturing a single, color image') camera.capture(filename=filename) print('Saved to %s' % filename) save_control_values(filename, camera.get_control_values()) else: print('Color image not available with this camera') # Enable video mode try: # Force any single exposure to be halted camera.stop_exposure() except (KeyboardInterrupt, SystemExit): raise except: pass print('Enabling video mode') camera.start_video_capture() # Restore all controls to default values except USB bandwidth for c in controls: if controls[c]['ControlType'] == asi.ASI_BANDWIDTHOVERLOAD: continue camera.set_control_value(controls[c]['ControlType'], controls[c]['DefaultValue']) # Can autoexposure be used? k = 'Exposure' if 'Exposure' in controls and controls['Exposure']['IsAutoSupported']: print('Enabling auto-exposure mode') camera.set_control_value(asi.ASI_EXPOSURE, controls['Exposure']['DefaultValue'], auto=True) if 'Gain' in controls and controls['Gain']['IsAutoSupported']: print('Enabling automatic gain setting') camera.set_control_value(asi.ASI_GAIN, controls['Gain']['DefaultValue'], auto=True) # Keep max gain to the default but allow exposure to be increased to its maximum value if necessary camera.set_control_value(controls['AutoExpMaxExpMS']['ControlType'], controls['AutoExpMaxExpMS']['MaxValue']) print('Waiting for auto-exposure to compute correct settings ...') sleep_interval = 0.100 df_last = None gain_last = None exposure_last = None matches = 0 while True: time.sleep(sleep_interval) settings = camera.get_control_values() df = camera.get_dropped_frames() gain = settings['Gain'] exposure = settings['Exposure'] if df != df_last: print(' Gain {gain:d} Exposure: {exposure:f} Dropped frames: {df:d}' .format(gain=settings['Gain'], exposure=settings['Exposure'], df=df)) if gain == gain_last and exposure == exposure_last: matches += 1 else: matches = 0 if matches >= 5: break df_last = df gain_last = gain exposure_last = exposure # Set the timeout, units are ms timeout = (camera.get_control_value(asi.ASI_EXPOSURE)[0] / 1000) * 2 + 500 camera.default_timeout = timeout if camera_info['IsColorCam']: print('Capturing a single color frame') filename = 'image_video_color.jpg' camera.set_image_type(asi.ASI_IMG_RGB24) camera.capture_video_frame(filename=filename) else: print('Capturing a single 8-bit mono frame') filename = 'image_video_mono.jpg' camera.set_image_type(asi.ASI_IMG_RAW8) camera.capture_video_frame(filename=filename) print('Saved to %s' % filename) save_control_values(filename, camera.get_control_values())
def initCamera(cam_width=320, cam_height=240): env_filename = os.getenv('ZWO_ASI_LIB') parser = argparse.ArgumentParser(description='Crescent moon detector') parser.add_argument('filename', nargs='?', help='SDK library filename') args = parser.parse_args() # Initialize zwoasi with the name of the SDK library if args.filename: asi.init(args.filename) elif env_filename: asi.init(env_filename) else: print( 'The filename of the SDK library is required (or set ZWO_ASI_LIB environment variable with the filename)' ) sys.exit(1) num_cameras = asi.get_num_cameras() if num_cameras == 0: print('No cameras found') sys.exit(0) cameras_found = asi.list_cameras() # Models names of the connected cameras if num_cameras == 1: camera_id = 0 camera_name = cameras_found[0] print('Found one camera: %s' % cameras_found[0]) else: print('Found %d cameras' % num_cameras) for n in range(num_cameras): print(' %d: %s' % (n, cameras_found[n])) # TO DO: allow user to select a camera camera_id = 0 print('Using #%d: %s' % (camera_id, cameras_found[camera_id])) camera = asi.Camera(camera_id) camera_info = camera.get_camera_property() # Get all of the camera controls controls = camera.get_controls() # Use minimum USB bandwidth permitted camera.set_control_value(asi.ASI_BANDWIDTHOVERLOAD, camera.get_controls()['BandWidth']['MinValue']) # Set some sensible defaults. They will need adjusting depending upon # the sensitivity, lens and lighting conditions used. camera.disable_dark_subtract() camera.set_control_value(asi.ASI_GAIN, 150) camera.set_control_value(asi.ASI_EXPOSURE, 49) camera.set_control_value(asi.ASI_WB_B, 99) camera.set_control_value(asi.ASI_WB_R, 75) camera.set_control_value(asi.ASI_GAMMA, 50) camera.set_control_value(asi.ASI_BRIGHTNESS, 50) camera.set_control_value(asi.ASI_FLIP, 0) # Restore all controls to default values except USB bandwidth for c in controls: if controls[c]['ControlType'] == asi.ASI_BANDWIDTHOVERLOAD: continue camera.set_control_value(controls[c]['ControlType'], controls[c]['DefaultValue']) # Can autoexposure be used? # k = 'Exposure' # if 'Exposure' in controls and controls['Exposure']['IsAutoSupported']: # print('Enabling auto-exposure mode') # camera.set_control_value(asi.ASI_EXPOSURE, # controls['Exposure']['DefaultValue'], # auto=True) if 'Gain' in controls and controls['Gain']['IsAutoSupported']: print('Enabling automatic gain setting') camera.set_control_value(asi.ASI_GAIN, controls['Gain']['DefaultValue'], auto=True) # Keep max gain to the default but allow exposure to be increased to its maximum value if necessary camera.set_control_value(controls['AutoExpMaxExpMS']['ControlType'], controls['AutoExpMaxExpMS']['MaxValue']) camera.set_image_type(asi.ASI_IMG_RAW8) camera.set_roi(width=cam_width, height=cam_height) return camera, camera_name
def open_camera(self, camera_id): self.camera = asi.Camera(camera_id) self.camera_info = self.camera.get_camera_property() self.controls = self.camera.get_controls()
sys.exit(0) cameras_found = asi.list_cameras() # Models names of the connected cameras if num_cameras == 1: camera_id = 0 print('Found one camera: %s' % cameras_found[0]) else: print('Found %d cameras' % num_cameras) for n in range(num_cameras): print(' %d: %s' % (n, cameras_found[n])) # TO DO: allow user to select a camera camera_id = 0 print('Using #%d: %s' % (camera_id, cameras_found[camera_id])) camera = asi.Camera(camera_id) camera_info = camera.get_camera_property() controls = camera.get_controls() camera.stop_video_capture() camera.stop_exposure() camera.set_image_type(asi.ASI_IMG_RAW16) img = camera.capture() width = int(img.shape[1]) height = int(img.shape[0]) # Use minimum USB bandwidth permitted camera.set_control_value(asi.ASI_BANDWIDTHOVERLOAD, camera.get_controls()['BandWidth']['MinValue']) # Set some sensible defaults. They will need adjusting depending upon
def __init__(self, index: int, image_type: int = asi.ASI_IMG_RAW8): self.image_type = image_type self._driver = asi.Camera(index) self._driver.set_image_type(image_type) self._controls = self._driver.get_controls() self._info = self._driver.get_camera_property()
def opencamera(self, cameraname=None): num_cameras = asi.get_num_cameras() if num_cameras == 0: print('No cameras found') sys.exit(0) cameras_found = asi.list_cameras( ) # Models names of the connected cameras if cameraname is not None: self.camera_id = -1 for n in range(num_cameras): if cameraname == cameras_found[n]: self.camera_id = n break if self.camera_id == -1: print('Unable to find camera "%s".' % (cameraname)) sys.exit(1) else: if num_cameras == 1: self.camera_id = 0 print('Found one camera: %s' % cameras_found[0]) else: print('Found %d cameras' % num_cameras) for n in range(num_cameras): print(' %d: %s' % (n, cameras_found[n])) # TO DO: allow user to select a camera self.camera_id = 0 print('Using #%d: %s' % (self.camera_id, cameras_found[self.camera_id])) self.camera = asi.Camera(self.camera_id) # e_per_adu depends on gain, so force it to zero before we start! self.camera.set_control_value(asi.ASI_GAIN, 0, False) self.camera_info = self.camera.get_camera_property() self.controls = self.camera.get_controls() # Use minimum USB bandwidth permitted self.camera.set_control_value( asi.ASI_BANDWIDTHOVERLOAD, self.camera.get_controls()['BandWidth']['MinValue']) # Set some sensible defaults. They will need adjusting depending upon # the sensitivity, lens and lighting conditions used. self.camera.disable_dark_subtract() self.offset_highest_DR, self.offset_unity_gain, self.gain_lowest_RN, self.offset_lowest_RN = asi._get_gain_offset( self.camera_id) print("offset_highest_DR %d" % self.offset_highest_DR) print("offset_unity_gain %d" % self.offset_unity_gain) print("gain_lowest_RN %d" % self.gain_lowest_RN) print("offset_lowest_RN %d" % self.offset_lowest_RN) print("ElecPerADU %f" % self.camera_info['ElecPerADU']) print("BitDepth %d" % self.camera_info['BitDepth']) unitygain = 10 * 20 * math.log10(self.camera_info['ElecPerADU']) fullwell0 = ( 2**self.camera_info['BitDepth']) * self.camera_info['ElecPerADU'] print("unitygain %f" % unitygain) print("fullwell %f" % fullwell0) g = 10**(self.gain_lowest_RN / 200.0) print("g %f" % g) print("gfw %f" % (fullwell0 / g)) g = 10**(unitygain / 200.0) print("g %f" % g) print("gfw %f" % (fullwell0 / g)) print("Max DR") apigain = 0 gain = 10**(apigain / 200.0) fullwell = fullwell0 / gain print("api-gain %3d gain %2.2f fw %6d" % (apigain, gain, fullwell)) print("Unity Gain") apigain = unitygain gain = 10**(apigain / 200.0) fullwell = fullwell0 / gain print("api-gain %3d gain %2.2f fw %6d" % (apigain, gain, fullwell)) print("Lowest RN") apigain = self.gain_lowest_RN gain = 10**(apigain / 200.0) fullwell = fullwell0 / gain print("api-gain %3d gain %2.2f fw %6d" % (apigain, gain, fullwell)) self.camera.set_control_value(asi.ASI_WB_B, 95) self.camera.set_control_value(asi.ASI_WB_R, 52) self.camera.set_control_value(asi.ASI_GAMMA, 50) self.camera.set_control_value(asi.ASI_OFFSET, 50) self.camera.set_control_value(asi.ASI_FLIP, 0) #Reset Camera try: # Force any single exposure to be halted self.camera.stop_video_capture() self.camera.stop_exposure() except (KeyboardInterrupt, SystemExit): raise except: pass
asi.init(args.zwolib) else: print('The path to the ZWO ASI SDK library is required (ASICamera2.dll)') sys.exit(1) num_cameras = asi.get_num_cameras() if num_cameras == 0: print('No cameras found') sys.exit(0) if (args.camera_id is not None): if (args.camera_id > num_cameras - 1): print('Invalid camera selected') sys.exit(0) camera = asi.Camera(args.camera_id) camera_info = camera.get_camera_property() cameras_found = asi.list_cameras() # Models names of the connected cameras # We pull 'controls' into main() so we can re-map (due to bad camera data) # and use in overloaded get_control_values() controls = camera.get_controls() controls = remap_control_type(controls) # Set some sensible defaults. They will need adjusting depending upon # the sensitivity, lens and lighting conditions used. # These have yet to be implemented in argument form camera.disable_dark_subtract()
def capture_asi(image_queue, z1, t1, z2, t2, nx, ny, nz, tend, device_id, live, cfg): first = True # Array flag slow_CPU = False # Performance issue flag camera_type = "ASI" gain = cfg.getint(camera_type, 'gain') maxgain = cfg.getint(camera_type, 'maxgain') autogain = cfg.getboolean(camera_type, 'autogain') exposure = cfg.getint(camera_type, 'exposure') binning = cfg.getint(camera_type, 'bin') brightness = cfg.getint(camera_type, 'brightness') bandwidth = cfg.getint(camera_type, 'bandwidth') high_speed = cfg.getint(camera_type, 'high_speed') hardware_bin = cfg.getint(camera_type, 'hardware_bin') sdk = cfg.get(camera_type, 'sdk') # Initialize device asi.init(sdk) num_cameras = asi.get_num_cameras() if num_cameras == 0: logger.error("No ZWOASI cameras found") raise ValueError sys.exit() cameras_found = asi.list_cameras() # Models names of the connected cameras if num_cameras == 1: device_id = 0 logger.info("Found one camera: %s" % cameras_found[0]) else: logger.info("Found %d ZWOASI cameras" % num_cameras) for n in range(num_cameras): logger.info(" %d: %s" % (n, cameras_found[n])) logger.info("Using #%d: %s" % (device_id, cameras_found[device_id])) camera = asi.Camera(device_id) camera_info = camera.get_camera_property() logger.debug("ASI Camera info:") for (key, value) in camera_info.items(): logger.debug(" %s : %s" % (key, value)) camera.set_control_value(asi.ASI_BANDWIDTHOVERLOAD, bandwidth) camera.disable_dark_subtract() camera.set_control_value(asi.ASI_GAIN, gain, auto=autogain) camera.set_control_value(asi.ASI_EXPOSURE, exposure, auto=False) camera.set_control_value(asi.ASI_AUTO_MAX_GAIN, maxgain) camera.set_control_value(asi.ASI_AUTO_MAX_BRIGHTNESS, 20) camera.set_control_value(asi.ASI_WB_B, 99) camera.set_control_value(asi.ASI_WB_R, 75) camera.set_control_value(asi.ASI_GAMMA, 50) camera.set_control_value(asi.ASI_BRIGHTNESS, brightness) camera.set_control_value(asi.ASI_FLIP, 0) camera.set_control_value(asi.ASI_HIGH_SPEED_MODE, high_speed) camera.set_control_value(asi.ASI_HARDWARE_BIN, hardware_bin) camera.set_roi(bins=binning) camera.start_video_capture() camera.set_image_type(asi.ASI_IMG_RAW8) try: # Fix autogain if autogain: while True: # Get frame z = camera.capture_video_frame() # Break on no change in gain settings = camera.get_control_values() if gain == settings["Gain"]: break gain = settings["Gain"] camera.set_control_value(asi.ASI_GAIN, gain, auto=autogain) # Loop until reaching end time while float(time.time()) < tend: # Wait for available capture buffer to become available if (image_queue.qsize() > 1): logger.warning( "Acquiring data faster than your CPU can process") slow_CPU = True while (image_queue.qsize() > 1): time.sleep(0.1) if slow_CPU: lost_video = time.time() - t logger.info("Waited %.3fs for available capture buffer" % lost_video) slow_CPU = False # Get settings settings = camera.get_control_values() gain = settings["Gain"] temp = settings["Temperature"] / 10.0 logger.info("Capturing frame with gain %d, temperature %.1f" % (gain, temp)) # Set gain if autogain: camera.set_control_value(asi.ASI_GAIN, gain, auto=autogain) # Get frames for i in range(nz): # Store start time t0 = float(time.time()) # Get frame z = camera.capture_video_frame() # Compute mid time t = (float(time.time()) + t0) / 2.0 # Display Frame if live is True: cv2.imshow("Capture", z) cv2.waitKey(1) # Store results if first: z1[i] = z t1[i] = t else: z2[i] = z t2[i] = t if first: buf = 1 else: buf = 2 image_queue.put(buf) logger.debug("Captured buffer %d" % buf) # Swap flag first = not first reason = "Session complete" except KeyboardInterrupt: print() reason = "Keyboard interrupt" except ValueError as e: logger.error("%s" % e) reason = "Wrong image dimensions? Fix nx, ny in config." except MemoryError as e: logger.error("Capture: Memory error %s" % e) finally: # End capture logger.info("Capture: %s - Exiting" % reason) camera.stop_video_capture() camera.close()
raise except: pass return self.camera.capture() if __name__ == "__main__": syslog(LOG_INFO, 'Start server') libasi_path = '/opt/ASI_SDK/lib/armv7/libASICamera2.so' asi.init(libasi_path) try: camera0 = asi.Camera(0) ccd = CameraHandler(camera0) syslog(LOG_INFO, 'Camera found') except: syslog(LOG_ERR, 'Camera not found') sys.exit(EC_CAMERA_NOT_FOUND) try: sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) sock.setsockopt(socket.SOL_TCP, socket.TCP_NODELAY, 1) sock.bind((HOST_ADDRESS, HOST_PORT)) sock.listen(2) syslog(LOG_INFO, 'Waiting connections...')
except Exception as e: print(e) sys.exit(1) # Find cameras ncam = asi.get_num_cameras() if ncam == 0: print("No ZWO ASI cameras found") sys.exit(1) # Decode settings texp_us = 1000 * int(settings["exposure"]) gain = int(settings["gain"]) # Initialize camera 0 camera = asi.Camera(0) camera_info = camera.get_camera_property() # Set control values camera.set_control_value(asi.ASI_BANDWIDTHOVERLOAD, int(settings["usb"])) camera.set_control_value(asi.ASI_EXPOSURE, texp_us, auto=False) camera.set_control_value(asi.ASI_GAIN, gain, auto=False) camera.set_control_value(asi.ASI_WB_B, int(settings["wbb"])) camera.set_control_value(asi.ASI_WB_R, int(settings["wbr"])) camera.set_control_value(asi.ASI_GAMMA, int(settings["gamma"])) camera.set_control_value(asi.ASI_BRIGHTNESS, int(settings["brightness"])) camera.set_control_value(asi.ASI_FLIP, int(settings["flip"])) camera.set_control_value(asi.ASI_AUTO_MAX_BRIGHTNESS, 80) camera.disable_dark_subtract() camera.set_roi(bins=int(settings["bin"]))
def __init__(self): env_filename = os.getenv('ZWO_ASI_LIB') parser = argparse.ArgumentParser( description='Process and save images from a camera') parser.add_argument('filename', nargs='?', help='SDK library filename') args = parser.parse_args() args.filename = '../ZWO_ASI_Library/lib/armv7/libASICamera2.so' #args.filename = '../ZWO_ASI_Library/lib/mac/libASICamera2.dylib'; # mac case # Initialize zwoasi with the name of the SDK library if args.filename: asi.init(args.filename) elif env_filename: asi.init(env_filename) else: print( 'The filename of the SDK library is required (or set ZWO_ASI_LIB environment variable with the filename)' ) sys.exit(1) num_cameras = asi.get_num_cameras() if num_cameras == 0: print('No cameras found') sys.exit(0) cameras_found = asi.list_cameras( ) # Models names of the connected cameras if num_cameras == 1: camera_id = 0 print('Found one camera: %s' % cameras_found[0]) else: print('Found %d cameras' % num_cameras) for n in range(num_cameras): print(' %d: %s' % (n, cameras_found[n])) # TO DO: allow user to select a camera camera_id = 0 print('Using #%d: %s' % (camera_id, cameras_found[camera_id])) camera = asi.Camera(camera_id) camera_info = camera.get_camera_property() # Get all of the camera controls print('') print('Camera controls:') controls = camera.get_controls() for cn in sorted(controls.keys()): print(' %s:' % cn) for k in sorted(controls[cn].keys()): print(' %s: %s' % (k, repr(controls[cn][k]))) # Use maximum USB bandwidth permitted camera.set_control_value( asi.ASI_BANDWIDTHOVERLOAD, camera.get_controls()['BandWidth']['MaxValue']) # Set some sensible defaults. They will need adjusting depending upon # the sensitivity, lens and lighting conditions used. camera.disable_dark_subtract() camera.set_control_value(asi.ASI_GAIN, 0) camera.set_control_value(asi.ASI_EXPOSURE, 10000) camera.set_control_value(asi.ASI_WB_B, 99) camera.set_control_value(asi.ASI_WB_R, 75) camera.set_control_value(asi.ASI_GAMMA, 50) camera.set_control_value(asi.ASI_BRIGHTNESS, 50) camera.set_control_value(asi.ASI_FLIP, 0) camera.set_image_type(asi.ASI_IMG_Y8) self.camera = camera