-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
start making multicamera recording a class
- Loading branch information
Lab Computer 19716
committed
Sep 11, 2024
1 parent
b68520d
commit 9b9c873
Showing
1 changed file
with
51 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,76 @@ | ||
from typing import List, Tuple | ||
import pypylon.pylon as pylon | ||
import cv2 | ||
import numpy as np | ||
import matplotlib as mpl | ||
|
||
tlf = pylon.TlFactory.GetInstance() | ||
|
||
devices = tlf.EnumerateDevices() | ||
class MultiCameraRecording: | ||
def __init__(self): | ||
self.tlf = pylon.TlFactory.GetInstance() | ||
|
||
self.all_devices = self.get_devices() | ||
|
||
def get_devices(self) -> List[pylon.DeviceInfo]: | ||
return list(self.tlf.EnumerateDevices()) | ||
|
||
def get_nir_devices(self) -> List[pylon.DeviceInfo]: | ||
return [device for device in self.all_devices if "NIR" in device.GetModelName()] | ||
|
||
def get_rgb_device(self) -> pylon.DeviceInfo: | ||
return [device for device in self.all_devices if "150uc" in device.GetModelName()][0] | ||
|
||
def get_nir_camera_array(self) | ||
|
||
if __name__=="__main__": | ||
print(MultiCameraRecording().get_rgb_device().GetModelName()) | ||
|
||
# for device in devices: | ||
# print(f"Model name: {device.GetModelName()} Serial Number: {device.GetSerialNumber()}") | ||
|
||
nir_devices = [device for device in devices if "NIR" in device.GetModelName()] | ||
# nir_devices = [device for device in devices if "NIR" in device.GetModelName()] | ||
|
||
cam_array = pylon.InstantCameraArray(len(nir_devices)) | ||
# cam_array = pylon.InstantCameraArray(len(nir_devices)) | ||
|
||
for index, cam in enumerate(cam_array): | ||
cam.Attach(tlf.CreateDevice(nir_devices[index])) | ||
# for index, cam in enumerate(cam_array): | ||
# cam.Attach(tlf.CreateDevice(nir_devices[index])) | ||
|
||
cam_array.Open() | ||
# cam_array.Open() | ||
|
||
# store a unique number for each camera to identify the incoming images | ||
for index, cam in enumerate(cam_array): | ||
camera_serial = cam.DeviceInfo.GetSerialNumber() | ||
print(f"set context {index} for camera {camera_serial}") | ||
cam.SetCameraContext(index) | ||
|
||
# set the exposure time for each camera | ||
# for idx, cam in enumerate(cam_array): | ||
# # store a unique number for each camera to identify the incoming images | ||
# for index, cam in enumerate(cam_array): | ||
# camera_serial = cam.DeviceInfo.GetSerialNumber() | ||
# print(f"set Exposuretime {idx} for camera {camera_serial}") | ||
# cam.ExposureTimeRaw = 10000 | ||
# print(f"set context {index} for camera {camera_serial}") | ||
# cam.SetCameraContext(index) | ||
|
||
# # set the exposure time for each camera | ||
# # for idx, cam in enumerate(cam_array): | ||
# # camera_serial = cam.DeviceInfo.GetSerialNumber() | ||
# # print(f"set Exposuretime {idx} for camera {camera_serial}") | ||
# # cam.ExposureTimeRaw = 10000 | ||
|
||
frames_to_grab = 10 | ||
# frames_to_grab = 10 | ||
|
||
frame_counts = [0] * len(nir_devices) | ||
# frame_counts = [0] * len(nir_devices) | ||
|
||
cam_array.StartGrabbing() | ||
while True: | ||
with cam_array.RetrieveResult(1000) as result: | ||
if result.GrabSucceeded(): | ||
image_number = result.ImageNumber | ||
cam_id = result.GetCameraContext() | ||
frame_counts[cam_id] = image_number | ||
print(f"cam #{cam_id} image #{image_number}") | ||
# cam_array.StartGrabbing() | ||
# while True: | ||
# with cam_array.RetrieveResult(1000) as result: | ||
# if result.GrabSucceeded(): | ||
# image_number = result.ImageNumber | ||
# cam_id = result.GetCameraContext() | ||
# frame_counts[cam_id] = image_number | ||
# print(f"cam #{cam_id} image #{image_number}") | ||
|
||
# do something with the image .... | ||
# # do something with the image .... | ||
|
||
if min(frame_counts) >= frames_to_grab: | ||
print( f"all cameras have acquired {frames_to_grab} frames") | ||
break | ||
# if min(frame_counts) >= frames_to_grab: | ||
# print( f"all cameras have acquired {frames_to_grab} frames") | ||
# break | ||
|
||
|
||
cam_array.StopGrabbing() | ||
# cam_array.StopGrabbing() | ||
|
||
print(frame_counts) | ||
# print(frame_counts) | ||
|
||
|