diff options
author | Matthias Vogelgesang <matthias.vogelgesang@gmail.com> | 2013-03-20 10:13:42 +0100 |
---|---|---|
committer | Matthias Vogelgesang <matthias.vogelgesang@gmail.com> | 2013-03-20 10:13:42 +0100 |
commit | 89789d228937bd57bdaaef55f60b7ba8f1e272f6 (patch) | |
tree | 602f29ac1b2f490c51f798574c2dbff42c0fd10a /docs | |
parent | ff7f3216fe76e0a4598bdf737671a5e25a780ded (diff) | |
download | libuca-89789d228937bd57bdaaef55f60b7ba8f1e272f6.tar.gz libuca-89789d228937bd57bdaaef55f60b7ba8f1e272f6.tar.bz2 libuca-89789d228937bd57bdaaef55f60b7ba8f1e272f6.tar.xz libuca-89789d228937bd57bdaaef55f60b7ba8f1e272f6.zip |
Add Numpy integration documentation
Diffstat (limited to 'docs')
-rw-r--r-- | docs/manual.md | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/docs/manual.md b/docs/manual.md index 0b81bdb..85584df 100644 --- a/docs/manual.md +++ b/docs/manual.md @@ -401,7 +401,7 @@ pm = Uca.PluginManager() print(pm.get_available_cameras()) # Load a camera -cam = pm.get_camera('pco') +cam = pm.get_camerav('pco', []) # You can read and write properties in two ways cam.set_properties(exposure_time=0.05) @@ -413,6 +413,32 @@ of the target language. For example with Python, the namespace prefix `uca_` becomes the module name `Uca` and dashes separating property names become underscores. +Integration with Numpy is relatively straightforward. The most important thing +is to get the data pointer from a Numpy array to pass it to `uca_camera_grab`: + +~~~ {.python} +import numpy as np + +def create_array_from(camera): + """Create a suitably sized Numpy array and return it together with the + arrays data pointer""" + bits = camera.props.sensor_bitdepth + dtype = np.uint16 if bits > 8 else np.uint8 + a = np.zeros((cam.props.roi_height, cam.props.roi_width), dtype=dtype) + return a, a.__array_interface__['data'][0] + +# Suppose 'camera' is a already available, you would get the camera data like +# this: +a, buf = create_array_from(camera) +camera.start_recording() +camera.grab(buf) + +# Now data is in 'a' and we can use Numpy functions on it +print(np.mean(a)) + +camera.stop_recording() +~~~ + # Integrating new cameras |