Example #1
0
 def __init__(self,name):
     GigE_camera.__init__(self)
     self.name = name
     self.frame_counts = []
     self.images = []
     self.monitoring = False
     self.last_frame_count = -1
     self.acquisition_requested = False
     self.start_monitoring()
     self.filenames = {}
Example #2
0
def get_image():
    """Acquire a single image from the camera and return as PIL image.
    This function is *NOT SAFE* to use for Python applications using network
    communication ("Interrupted system call"), because loads the Prosilica
    library."""
    from time import time
    import Image  # Python Imaging Library

    camera = GigE_camera(IP_address)
    # Under Linux use_multicast requires administrative priviledges.
    # Program needs to be registered in sudoers data base.
    camera.use_multicast = use_multicast
    camera.last_timestamp = 0

    camera.start()
    t = time()
    while not camera.has_image or camera.timestamp == 0:
        if time() - t > 2.0 and not "started" in camera.state:
            log("Prosilica image unreadable (%s)" % camera.state)
            break
        if time() - t > 5.0:
            log("Prosilica image acquistion timed out (%s)" % camera.state)
            break
        sleep(0.1)

    camera.stop()

    log("Info: read image image with %dx%d pixels, %d bytes" %
        (camera.width, camera.height, len(camera.rgb_data)))
    image = Image.new('RGB', (camera.width, camera.height))
    image.fromstring(camera.rgb_data)

    return image
Example #3
0
def test_direct():
    print "Running test ..."
    camera = GigE_camera("id14b-prosilica3.cars.aps.anl.gov",
                         use_multicast=False)
    camera.start()
    print "Camera started..."
    sleep(2)
    print camera.state
    print "has_image", camera.has_image
    print "pixel_format", camera.pixel_format
    print "width*height", camera.width * camera.height
    image = camera.rgb_array
    from numpy import average, sum
    I = float(sum(image)) / image.size
    print "average intensity", I
Example #4
0
def get_image_size():
    """Image width and height, without rotation applied.
    This function is *NOT SAFE* to use for Python applications using network
    communication ("Interrupted system call"), because loads the Prosilica
    library."""
    camera = GigE_camera(IP_address)
    return camera.width, camera.height
Example #5
0
def get_center():
    """Beam center pixel occordinates, without rotation applied.
    This function is *NOT SAFE* to use for Python applications using network
    communication ("Interrupted system call"), because loads the Prosilica
    library."""
    camera = GigE_camera(IP_address)
    return camera.center
def camera_acquire_image():
    """Acquire a single image from the camera and return as PIL image.
    This function is *NOT SAFE* to use for Python applications using network
    communication ("Interrupted system call"), because loads the Prosilica
    library."""
    from time import time
    from PIL import Image  # Python Imaging Library

    camera = GigE_camera(parameter("camera.IP_addr"),
                         use_multicast=use_multicast)
    camera.last_timestamp = 0

    camera.start()
    t = time()
    while not camera.has_image or camera.timestamp == 0:
        if time() - t > 2.0 and not "started" in camera.state:
            log("camera_acquire_image: image unreadable (%s)" % camera.state)
            break
        if time() - t > 5.0:
            log("camera_acquire_image: image acquistion timed out (%s)" %
                camera.state)
            break
        sleep(0.1)

    camera.stop()

    debug("get_image: read image with %dx%d pixels, %d bytes" %
          (camera.width, camera.height, len(camera.rgb_data)))
    image = Image.new('RGB', (camera.width, camera.height))
    image.fromstring(camera.rgb_data)
    image = rotated_image(image)
    return image
def camera_image_size():
    """Image width and height, without rotation applied.
    This function is *NOT SAFE* to use for Python applications using network
    communication ("Interrupted system call"), because loads the Prosilica
    library."""
    camera = GigE_camera(parameter("camera.IP_addr"))
    width, height = camera.width, camera.height
    orientation = parameter('Orientation', 90)  # in degrees counter-clockwise
    if orientation == None: orienation = 0
    orientation %= 360
    if orientation == 90 or orientation == 270: width, height = height, width
    return width, height
Example #8
0
def test_single_image():
    from time import time
    from numpy import average, sum

    global camera, image, I

    camera = GigE_camera("id14b-prosilica4.cars.aps.anl.gov",
                         use_multicast=False)
    camera.start()
    t = time()
    while not camera.has_image:
        if time() - t > 2.0 and not "started" in camera.state:
            print("Prosilica image unreadable (%s)" % camera.state)
            break
        if time() - t > 5.0:
            print("image acquistion timed out (%s)" % camera.state)
            break
        sleep(0.1)
    print "acquisition time %.3fs" % (time() - t)
    image = camera.rgb_array
    I = float(sum(image)) / image.size
    print "average: %g counts/pixel" % I
    print "fraction of pixels >0: %g" % average(image != 0)
 def __init__(self, name):
     GigE_camera.__init__(self)
     self.name = name
     self.filenames = {}
def SNR(data):
    """Calculate the signal-to-noise ratio of a beam profile.
    It is defined as the ratio the peak height relative to the baseline and the
    RMS of the base line.
    The base line is the outer 20% of the profile on either end."""
    from numpy import rint, std, mean, mean, nan
    y = yvals(data)
    n = len(data)
    # Assume that the base line is the outer 20% of the data.
    n1 = int(rint(n * 0.2))
    n2 = int(rint(n * 0.8))
    baseline = y[0:n1] + y[n2:-1]
    signal = max(y) - mean(baseline)
    noise = std(baseline)
    if noise != 0: return signal / noise
    else: return nan


# The following is only executed when run as stand-alone application.
if __name__ == '__main__':
    wx.app = wx.App(redirect=False)
    camera = GigE_camera("id14b-prosilica5.cars.aps.anl.gov")
    ##camera = GigE_camera("id14b-prosilica5.biocarsvideo.net")
    # Direct imaging: pixel size is same as CCD pixel, 4.65 um
    viewer = LaserBeamPosition(
        camera,
        "Laser Beam Position (in beam conditioning box)",
        name="LaserBeamPosition",
        pixelsize=0.00465)
    wx.app.MainLoop()
from GigE_camera import GigE_camera, sleep
from time import time
from numpy import average, sum

# id14b-prosilica1 - Microscope camera
# id14b-prosilica2 - Wide-field camera
# id14b-prosilica3 - Laser beam profile at sample
# id14b-prosilica4 - Laser beam profile in beam conditioning box

camera = GigE_camera("id14b-prosilica1.cars.aps.anl.gov", use_multicast=False)
camera.pixel_format = "Rgb24"
camera.start()
t = time()
while not camera.has_image:
    print camera.state
    if time() - t > 2.0 and not "started" in camera.state:
        print("Prosilica image unreadable (%s)" % camera.state)
        break
    if time() - t > 5.0:
        print("image acquistion timed out (%s)" % camera.state)
        break
    sleep(0.1)
print "acquisition time %.3fs" % (time() - t)
R, G, B = image = camera.rgb_array
camera.stop()
I = float(sum(image)) / image.size
print "average: %g counts/pixel" % I
print "fraction of pixels >0: %g" % average(image != 0)


def rotate(image, angle):