Beispiel #1
0
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
Beispiel #2
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
Beispiel #3
0
 def refresh_asi_list(self):
     self.asi_combobox.clear()
     list_cam = asi.list_cameras()
     self.asi_combobox.addItems(list_cam)
     if len(list_cam) == 0:
         self.asi_connect_button.setDisabled(True)
         self.asi_combobox.setDisabled(True)
     else:
         self.asi_connect_button.setEnabled(True)
         self.asi_combobox.setEnabled(True)
Beispiel #4
0
    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()
Beispiel #5
0
    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 initialize_zwoasi():
    env_filename = '/usr/local/lib/libASICamera2.so'

    asi.init(env_filename)
    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]))

    return camera_id
Beispiel #7
0
    def __init__(self):

        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:
            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.open_camera(self.camera_id)
        self.set_type(color=False)
Beispiel #8
0
                        width=12,
                        relief="raised",
                        command=toggle_play)
toggle_play.pack()
toggle_stream = tk.Button(text="Stream",
                          width=12,
                          relief="raised",
                          command=toggle_stream)
toggle_stream.pack()

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()
controls = camera.get_controls()
Beispiel #9
0
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()
Beispiel #10
0
    def connect_asi(self):
        self.accept()

        asi_camera = self.asi_combobox.currentText()
        self.result = zwo.ZwoCamera(asi.list_cameras().index(asi_camera))
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())
Beispiel #12
0
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
Beispiel #13
0
    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
Beispiel #14
0
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)

# Get the number of attached cameras (bc Daddy Marple told me to)
num_cameras = asi.get_num_cameras()
if num_cameras == 0:
    print('No cameras found')
    sys.exit(0)

# Get the list of model names for cameras connected (bc Daddy Marple told me to)
cameras_found = asi.list_cameras()

if num_cameras == 1:
    camera_id = 0
    print('Found one camera: %s' % cameras_found[0])
else:
    print('You got too many cameras homie')

camera = asi.Camera(camera_id)
camera_info = camera.get_camera_property()

# Get all of the camera controls (bc Daddy Marple told me to)
print('')
print('Camera controls:')
controls = camera.get_controls()
for cn in sorted(controls.keys()):
Beispiel #15
0
    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