Skip to content
Snippets Groups Projects
Commit f90264ad authored by Markus Höschle's avatar Markus Höschle
Browse files

Signed-off-by: mhoeschle <markus.hoeschle@tuebingen.mpg.de>

parent 13a598a5
No related branches found
No related tags found
No related merge requests found
...@@ -4,66 +4,216 @@ import numpy as np ...@@ -4,66 +4,216 @@ import numpy as np
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import time import time
#
# Variable:
#
# Generates a list of the cameras connected to our computer, like what we see with the PylonViewer program camera = pylon.InstantCamera(pylon.TlFactory.GetInstance().CreateFirstDevice())
tl_factory = pylon.TlFactory.GetInstance()
#print(tl_factory)
devices = tl_factory.EnumerateDevices()
#print(devices)
for device in devices:
print("Device Input (Camera Type & (Serialnumber)):")
print("-", device.GetFriendlyName(), "\n") # Model name + Serial number
#print("-", device.GetModelName())
#print("-", device.GetSerialNumber(), "\n")
"""
Function
"""
#
# First step is to list all the connected cameras at the system:
#
def listcam():
"""
schows all connected Basler cameras
"""
# Generates a list of the cameras connected to our computer, like what we see with the PylonViewer program
tl_factory = pylon.TlFactory.GetInstance()
#print(tl_factory)
devices = tl_factory.EnumerateDevices()
#print(devices)
for device in devices:
print("Device Input (Camera Type & (Serialnumber)):")
print("-", device.GetFriendlyName(), "\n") # Model name + Serial number
#print("-", device.GetModelName())
#print("-", device.GetSerialNumber(), "\n")
listcam()
#
# Second step is open camara device
#
def opencam():
"""
opens interface to camera
"""
# Create an instant camera object with the camera device found first.
## camera = pylon.InstantCamera(pylon.TlFactory.GetInstance().CreateFirstDevice())
# open camera, crate a device!
print("openDevice:", "\n")
return camera.Open()
#opencam()
def readcam():
"""
read out current settings from camera via interface
"""
# open camera interface:
opencam()
# Read Gain value in Camera:
print("Gain in (dB):")
# Gain value
print(camera.Gain.Value, "\n")
# Read Trigger Delay value in Camera:
print("Delay in (microseconds):")
# TriggerDelay value
print(camera.TriggerDelay.Value, "\n")
# for chaning the value uncomment the comment in the next line (camera.TriggerDelay.Value = YourValue)
#camera.TriggerDelay.Value = 0
# Gamma value:
print("Camera gamma value: ")
print(camera.Gamma.GetValue(), "\n")
closecam()
#
# close camera interface
#
def closecam():
"""
close interface to camera
"""
# close camera
## camera = pylon.InstantCamera(pylon.TlFactory.GetInstance().CreateFirstDevice())
print("closeDevice:", "\n")
return camera.Close()
#closecam()
#
# Funktion for changing the value (uncomment the comment in the next line (camera.Gain = YourValue))
#
def gaincam():
"""
changes the gain in (dB)
"""
opencam()
gainvalue = input("Please enter the new gain in (dB): ")
camera.Gain = float(gainvalue)
# Read Gain value in Camera:
print("New Gain in (dB):")
# Gain value
print(camera.Gain.Value, "\n")
closecam()
#cameragain()
#
# Funktion for changing the exposure time in microseconds (e.g. 1000 ms):
#
def exosurecam():
"""
changes the exposure time in microseconds (ms)
"""
opencam()
oldexposure = camera.ExposureTime.GetValue()
print(f'old exposure: {oldexposure}')
newexposure = input("Please enter new exposure value (microseconds): ")
newexposure = float(newexposure)
camera.ExposureTime.SetValue(newexposure)
# Read new exosure value in Camera:
print("New exposure in (ms):")
# print new exposure value
print(camera.ExposureTime.GetValue(), "\n")
closecam()
#exosurecam()
#
# Funktion for changing the aquisation frame rate in fps (e.g. 30 fps):
#
def aquisationfps():
"""
enable / dissable auto or manual fps and
changes the fps (frame per seconds)
"""
opencam()
status = camera.AcquisitionFrameRateEnable.GetValue()
print(f'fps enable? {status}')
statusenable = str(input("Do you want to change fps, (y/n)? "))
if statusenable.lower() == 'y':
camera.AcquisitionFrameRateEnable.SetValue(True)
oldfps = camera.AcquisitionFrameRate.GetValue()
print(f'Old fps: {oldfps}')
newfps = input("Choose your fps: ")
camera.AcquisitionFrameRate.SetValue(float(newfps))
print(f"New fps is: {newfps}",'\n')
else:
print("disabled Aquisation Frame rate!")
camera.AcquisitionFrameRateEnable.SetValue(False)
closecam()
#aquisationfps()
#
# Funktion for changing the trigger delay in microseconds (e.g. 2000 ms ):
#
def triggerdelaycam():
"""
changes the trigger delay in microseconds (ms)
"""
opencam()
print(f'trigger delay is: {camera.TriggerDelay.GetValue()}')
newtriggerdelay = input("Please enter new trigger delay in (microseconds): ")
camera.TriggerDelay.SetValue(float(newtriggerdelay))
print(f'New trigger delay is: {camera.TriggerDelay.GetValue()}')
closecam()
#triggerdelaycam()
# open camera, crate a device!
print("openDevice:", "\n")
# Create an instant camera object with the camera device found first.
camera = pylon.InstantCamera(pylon.TlFactory.GetInstance().CreateFirstDevice())
camera.Open()
# Read Gain value in Camera:
print("Gain in (dB):")
# Gain value
print(camera.Gain.Value, "\n")
# for chaning the value uncomment the comment in the next line (camera.Gain = YourValue)
#camera.Gain = 10.1
# Read Trigger Delay value in Camera:
print("Delay in (microseconds):")
# TriggerDelay value
print(camera.TriggerDelay.Value, "\n")
# for chaning the value uncomment the comment in the next line (camera.TriggerDelay.Value = YourValue)
#camera.TriggerDelay.Value = 0
# Gamma value:
print("Camera gamma value: ")
print(camera.Gamma.GetValue(), "\n")
# camera start free run mode: VIDEO 37:32
camera.StartGrabbing(pylon.GrabStrategy_OneByOne)
i = 0
print('Starting to acquire')
t0 = time.time()
while camera.IsGrabbing():
grab = camera.RetrieveResult(100, pylon.TimeoutHandling_ThrowException)
if grab.GrabSucceeded():
i += 1
if i == 100:
break
print(f'Acquired {i} frames in {time.time()-t0:.0f} seconds')
# How to show the images ? # How to show the images ?
# Next step # Next step
# start canera in free run mode:
def freeruncam():
# camera start free run mode: VIDEO 37:32
camera.StartGrabbing(pylon.GrabStrategy_OneByOne)
i = 0
print('Starting to acquire')
t0 = time.time()
while camera.IsGrabbing():
grab = camera.RetrieveResult(100, pylon.TimeoutHandling_ThrowException)
if grab.GrabSucceeded():
i += 1
if i == 100:
break
print(f'Acquired {i} frames in {time.time()-t0:.0f} seconds')
# ---> ongoing, not yet in usage.
# close camera
camera.Close()
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment