From 8b43fc82705ee8338b4e14a3b92efb8360deb877 Mon Sep 17 00:00:00 2001 From: antortjim Date: Tue, 25 May 2021 18:21:26 +0200 Subject: [PATCH 1/4] Support Basler camera a2A2590-60umBAS (and potentially other Basler cameras, untested) --- dlclivegui/camera/basler.py | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/dlclivegui/camera/basler.py b/dlclivegui/camera/basler.py index bec9d82..1706208 100644 --- a/dlclivegui/camera/basler.py +++ b/dlclivegui/camera/basler.py @@ -5,31 +5,36 @@ Licensed under GNU Lesser General Public License v3.0 """ -import pypylon as pylon +#import pypylon as pylon +from pypylon import pylon from imutils import rotate_bound import time from dlclivegui.camera import Camera, CameraError +TIMEOUT = 100 +def get_devices(): + tlFactory = pylon.TlFactory.GetInstance() + devices = tlFactory.EnumerateDevices() + return devices class BaslerCam(Camera): @staticmethod def arg_restrictions(): """ Returns a dictionary of arguments restrictions for DLCLiveGUI """ - - tlFactory = pylon.TlFactory.GetInstance() - devices = tlFactory.EnumerateDevices() - - return {"device": devices, "display": [True, False]} + devices = get_devices() + device_ids = list(range(len(devices))) + return {"device": device_ids, "display": [True, False]} def __init__( self, - device="", + device=0, resolution=[640, 480], - exposure=0, + exposure=15000, rotate=0, crop=None, + gain=0.0, fps=30, display=True, display_resize=1.0, @@ -41,6 +46,7 @@ def __init__( exposure=exposure, rotate=rotate, crop=crop, + gain=gain, fps=fps, use_tk_display=display, display_resize=display_resize, @@ -50,12 +56,14 @@ def __init__( def set_capture_device(self): + devices = get_devices() self.cam = pylon.InstantCamera( - pylon.TlFactory.GetInstance().CreateDevice(self.id)) + pylon.TlFactory.GetInstance().CreateDevice(devices[self.id]) + ) self.cam.Open() self.cam.Gain.SetValue(self.gain) - self.cam.Exposure.SetValue(self.exposure) + self.cam.ExposureTime.SetValue(self.exposure) self.cam.Width.SetValue(self.im_size[0]) self.cam.Height.SetValue(self.im_size[1]) @@ -67,9 +75,8 @@ def set_capture_device(self): return True def get_image(self): - grabResult = self.cam.RetrieveResult( - 1, pylon.TimeoutHandling_ThrowException) + TIMEOUT, pylon.TimeoutHandling_ThrowException) frame = None From 36319979e391568e7e834a9d214525fc1905b731 Mon Sep 17 00:00:00 2001 From: Mackenzie Mathis Date: Tue, 25 May 2021 22:02:03 +0200 Subject: [PATCH 2/4] Update camera_support.md --- docs/camera_support.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/docs/camera_support.md b/docs/camera_support.md index ee6d8a3..183402b 100644 --- a/docs/camera_support.md +++ b/docs/camera_support.md @@ -63,3 +63,15 @@ If you're camera has built in methods to ensure the correct frame rate (e.g. whe The `get_image` method has no input arguments, but must return an image as a numpy array. We also recommend converting images to 8-bit integers (data type `uint8`). The `get_image_on_time` method has no input arguments, but must return an image as a numpy array (as in `get_image`) and the timestamp at which the image is returned (using python's `time.time()` function). + +### Camera Specific Tips for Installation & Use: + +- For **Basler cameras**, `pylon viewer` need to be installed. It can be downloaded for many platforms on the Basler website. +As an example (tested on ubuntu 20.04, contributed by [@antortjim](https://github.com/antortjim)): +``` +wget https://github.com/basler/pypylon/archive/refs/tags/1.7.2.tar.gz +tar -zxvf 1.7.2.tar.gz +cd pypylon-1.7.2 +python setup.py install +# this installs pypylon version 6.1.1 +``` From d5edc3c960f959666b9c4882656ad7007c84b6bb Mon Sep 17 00:00:00 2001 From: antortjim Date: Thu, 27 May 2021 15:18:22 +0200 Subject: [PATCH 3/4] Expand basler tips in docs/ --- docs/camera_support.md | 64 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 61 insertions(+), 3 deletions(-) diff --git a/docs/camera_support.md b/docs/camera_support.md index 183402b..9951fce 100644 --- a/docs/camera_support.md +++ b/docs/camera_support.md @@ -66,12 +66,70 @@ The `get_image_on_time` method has no input arguments, but must return an image ### Camera Specific Tips for Installation & Use: -- For **Basler cameras**, `pylon viewer` need to be installed. It can be downloaded for many platforms on the Basler website. -As an example (tested on ubuntu 20.04, contributed by [@antortjim](https://github.com/antortjim)): +#### Basler cameras + +Basler USB3 cameras are compatible with Aravis. However, integration with DeepLabCut can also be obtained with `pypylon`, the python module to drive Basler cameras, and supported by the company. Please note using `pypylon` requires you to install Pylon viewer, a free of cost GUI also developed and supported by Basler and available on several platforms. + +* **Pylon viewer**: https://www.baslerweb.com/en/sales-support/downloads/software-downloads/#type=pylonsoftware;language=all;version=all +* `pypylon`: https://github.com/basler/pypylon/releases + +If you want to use DeepLabCut with a Basler USB3 camera via pypylon, see the folllowing instructions. Please note this is tested on Ubuntu 20.04. It may (or may not) work similarly in other platforms (contributed by [@antortjim](https://github.com/antortjim)). This procedure should take around 10 minutes: + +**Install Pylon viewer** + +1. Download .deb file +Download the .deb file in the downloads center of Basler. Last version as of writing this was **pylon 6.2.0 Camera Software Suite Linux x86 (64 Bit) - Debian Installer Package**. + + +2. Install .deb file + +``` +sudo dpkg -i pylon_6.2.0.21487-deb0_amd64.deb +``` + +**Install swig** + +Required for compilation of non python code within pypylon + +1. Install swig dependencies + +You may have to install these in a fresh Ubuntu 20.04 install + +``` +sudo apt install gcc g++ +sudo apt install libpcre3-dev +sudo apt install make +``` + +2. Download swig + +Go to http://prdownloads.sourceforge.net/swig/swig-4.0.2.tar.gz and download the tar gz + +3. Install swig +``` +tar -zxvf swig-4.0.2.tar.gz +cd swig-4.0.2 +./configure +make +sudo make install +``` + +**Install pypylon** + +1. Download pypylon + ``` wget https://github.com/basler/pypylon/archive/refs/tags/1.7.2.tar.gz +``` + +or go to https://github.com/basler/pypylon/releases and get the version you want! + +2. Install pypylon + +``` tar -zxvf 1.7.2.tar.gz cd pypylon-1.7.2 python setup.py install -# this installs pypylon version 6.1.1 ``` + +Once you have completed these steps, you should be able to call your Basler camera from DeepLabCut using the BaslerCam camera type that appears after clicking "Add camera") From 38ed6b8d16076b85bea1257cd38de9c230d9a49d Mon Sep 17 00:00:00 2001 From: antortjim Date: Thu, 27 May 2021 15:25:39 +0200 Subject: [PATCH 4/4] Correct DLC program name --- docs/camera_support.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/camera_support.md b/docs/camera_support.md index 9951fce..6e36e22 100644 --- a/docs/camera_support.md +++ b/docs/camera_support.md @@ -68,12 +68,12 @@ The `get_image_on_time` method has no input arguments, but must return an image #### Basler cameras -Basler USB3 cameras are compatible with Aravis. However, integration with DeepLabCut can also be obtained with `pypylon`, the python module to drive Basler cameras, and supported by the company. Please note using `pypylon` requires you to install Pylon viewer, a free of cost GUI also developed and supported by Basler and available on several platforms. +Basler USB3 cameras are compatible with Aravis. However, integration with DeepLabCut-live-GUI can also be obtained with `pypylon`, the python module to drive Basler cameras, and supported by the company. Please note using `pypylon` requires you to install Pylon viewer, a free of cost GUI also developed and supported by Basler and available on several platforms. * **Pylon viewer**: https://www.baslerweb.com/en/sales-support/downloads/software-downloads/#type=pylonsoftware;language=all;version=all * `pypylon`: https://github.com/basler/pypylon/releases -If you want to use DeepLabCut with a Basler USB3 camera via pypylon, see the folllowing instructions. Please note this is tested on Ubuntu 20.04. It may (or may not) work similarly in other platforms (contributed by [@antortjim](https://github.com/antortjim)). This procedure should take around 10 minutes: +If you want to use DeepLabCut-live-GUI with a Basler USB3 camera via pypylon, see the folllowing instructions. Please note this is tested on Ubuntu 20.04. It may (or may not) work similarly in other platforms (contributed by [@antortjim](https://github.com/antortjim)). This procedure should take around 10 minutes: **Install Pylon viewer** @@ -132,4 +132,4 @@ cd pypylon-1.7.2 python setup.py install ``` -Once you have completed these steps, you should be able to call your Basler camera from DeepLabCut using the BaslerCam camera type that appears after clicking "Add camera") +Once you have completed these steps, you should be able to call your Basler camera from DeepLabCut-live-GUI using the BaslerCam camera type that appears after clicking "Add camera")