Пример #1
0
def run_single_camera(cam, uid):
    print('Connecting to Camera...')
    cam.connect(uid)
    print_camera_info(cam.getCameraInfo())
    for i in range(cam.getNumStreamChannels()):
        print_stream_channel_info(cam.getGigEStreamChannelInfo(i))
    print('Querying GigE image setting information...')
    image_settings_info = cam.getGigEImageSettingsInfo()
    image_settings = PyCapture2.GigEImageSettings()

    image_settings.offsetX = 0
    image_settings.offsetY = 0
    image_settings.height = image_settings_info.maxHeight
    image_settings.width = image_settings_info.maxWidth
    image_settings.pixelFormat = PyCapture2.PIXEL_FORMAT.MONO8

    print('Setting GigE image settings...')
    cam.setGigEImageSettings(image_settings)
    enable_embedded_timestamp(cam, True)

    print('Starting image capture...')
    cam.startCapture()
    prev_ts = None
    num_images_to_grab = 10
    for i in range(num_images_to_grab):
        try:
            image = cam.retrieveBuffer()
        except PyCapture2.Fc2error as fc2Err:
            print('Error retrieving buffer : ', fc2Err)
            continue

        ts = image.getTimeStamp()
        if prev_ts:
            diff = (ts.cycleSeconds - prev_ts.cycleSeconds) * 8000 + (
                ts.cycleCount - prev_ts.cycleCount)
            print('Timestamp [ %d %d ] - %d' %
                  (ts.cycleSeconds, ts.cycleCount, diff))
        prev_ts = ts

    newimg = image.convert(PyCapture2.PIXEL_FORMAT.BGR)
    print('Saving the last image to GigEGrabEx.png')
    newimg.save('GigEGrabEx.png'.encode('utf-8'),
                PyCapture2.IMAGE_FILE_FORMAT.PNG)
    cam.stopCapture()
    enable_embedded_timestamp(cam, False)
    cam.disconnect()
Пример #2
0
    def __init__(self, width=720, height=480):

        self.width = width
        self.height = height

        #Connect to Camera
        bus = PyCapture2.BusManager()
        camInfo = bus.discoverGigECameras()
        self.cam = PyCapture2.GigECamera()
        uID = bus.getCameraFromIndex(0)
        self.cam.connect(uID)

        #Set Up Camera Parameters
        imgSetInfo = self.cam.getGigEImageSettingsInfo()
        imgSet = PyCapture2.GigEImageSettings()
        imgSet.offsetX = (2048 - self.width) / 2
        imgSet.offsetY = (2448 - self.height) / 2
        imgSet.height = self.height
        imgSet.width = self.width
        imgSet.pixelFormat = PyCapture2.PIXEL_FORMAT.RGB
        self.cam.setGigEImageSettings(imgSet)