Skip to content

Commit f8ec1d1

Browse files
authored
Merge pull request #11 from shaliulab/basler
Support Basler camera a2A2590-60umBAS (and other Basler cameras, untested)
2 parents e402517 + 38ed6b8 commit f8ec1d1

2 files changed

Lines changed: 89 additions & 12 deletions

File tree

dlclivegui/camera/basler.py

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,36 @@
55
Licensed under GNU Lesser General Public License v3.0
66
"""
77

8-
import pypylon as pylon
8+
#import pypylon as pylon
9+
from pypylon import pylon
910
from imutils import rotate_bound
1011
import time
1112

1213
from dlclivegui.camera import Camera, CameraError
14+
TIMEOUT = 100
1315

16+
def get_devices():
17+
tlFactory = pylon.TlFactory.GetInstance()
18+
devices = tlFactory.EnumerateDevices()
19+
return devices
1420

1521
class BaslerCam(Camera):
1622
@staticmethod
1723
def arg_restrictions():
1824
""" Returns a dictionary of arguments restrictions for DLCLiveGUI
1925
"""
20-
21-
tlFactory = pylon.TlFactory.GetInstance()
22-
devices = tlFactory.EnumerateDevices()
23-
24-
return {"device": devices, "display": [True, False]}
26+
devices = get_devices()
27+
device_ids = list(range(len(devices)))
28+
return {"device": device_ids, "display": [True, False]}
2529

2630
def __init__(
2731
self,
28-
device="",
32+
device=0,
2933
resolution=[640, 480],
30-
exposure=0,
34+
exposure=15000,
3135
rotate=0,
3236
crop=None,
37+
gain=0.0,
3338
fps=30,
3439
display=True,
3540
display_resize=1.0,
@@ -41,6 +46,7 @@ def __init__(
4146
exposure=exposure,
4247
rotate=rotate,
4348
crop=crop,
49+
gain=gain,
4450
fps=fps,
4551
use_tk_display=display,
4652
display_resize=display_resize,
@@ -50,12 +56,14 @@ def __init__(
5056

5157
def set_capture_device(self):
5258

59+
devices = get_devices()
5360
self.cam = pylon.InstantCamera(
54-
pylon.TlFactory.GetInstance().CreateDevice(self.id))
61+
pylon.TlFactory.GetInstance().CreateDevice(devices[self.id])
62+
)
5563
self.cam.Open()
5664

5765
self.cam.Gain.SetValue(self.gain)
58-
self.cam.Exposure.SetValue(self.exposure)
66+
self.cam.ExposureTime.SetValue(self.exposure)
5967
self.cam.Width.SetValue(self.im_size[0])
6068
self.cam.Height.SetValue(self.im_size[1])
6169

@@ -67,9 +75,8 @@ def set_capture_device(self):
6775
return True
6876

6977
def get_image(self):
70-
7178
grabResult = self.cam.RetrieveResult(
72-
1, pylon.TimeoutHandling_ThrowException)
79+
TIMEOUT, pylon.TimeoutHandling_ThrowException)
7380

7481
frame = None
7582

docs/camera_support.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,73 @@ If you're camera has built in methods to ensure the correct frame rate (e.g. whe
6363
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`).
6464

6565
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).
66+
67+
### Camera Specific Tips for Installation & Use:
68+
69+
#### Basler cameras
70+
71+
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.
72+
73+
* **Pylon viewer**: https://www.baslerweb.com/en/sales-support/downloads/software-downloads/#type=pylonsoftware;language=all;version=all
74+
* `pypylon`: https://github.com/basler/pypylon/releases
75+
76+
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:
77+
78+
**Install Pylon viewer**
79+
80+
1. Download .deb file
81+
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**.
82+
83+
84+
2. Install .deb file
85+
86+
```
87+
sudo dpkg -i pylon_6.2.0.21487-deb0_amd64.deb
88+
```
89+
90+
**Install swig**
91+
92+
Required for compilation of non python code within pypylon
93+
94+
1. Install swig dependencies
95+
96+
You may have to install these in a fresh Ubuntu 20.04 install
97+
98+
```
99+
sudo apt install gcc g++
100+
sudo apt install libpcre3-dev
101+
sudo apt install make
102+
```
103+
104+
2. Download swig
105+
106+
Go to http://prdownloads.sourceforge.net/swig/swig-4.0.2.tar.gz and download the tar gz
107+
108+
3. Install swig
109+
```
110+
tar -zxvf swig-4.0.2.tar.gz
111+
cd swig-4.0.2
112+
./configure
113+
make
114+
sudo make install
115+
```
116+
117+
**Install pypylon**
118+
119+
1. Download pypylon
120+
121+
```
122+
wget https://github.com/basler/pypylon/archive/refs/tags/1.7.2.tar.gz
123+
```
124+
125+
or go to https://github.com/basler/pypylon/releases and get the version you want!
126+
127+
2. Install pypylon
128+
129+
```
130+
tar -zxvf 1.7.2.tar.gz
131+
cd pypylon-1.7.2
132+
python setup.py install
133+
```
134+
135+
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")

0 commit comments

Comments
 (0)