diff options
Diffstat (limited to 'docs/manual.md')
-rw-r--r-- | docs/manual.md | 46 |
1 files changed, 34 insertions, 12 deletions
diff --git a/docs/manual.md b/docs/manual.md index 0dd9c66..85584df 100644 --- a/docs/manual.md +++ b/docs/manual.md @@ -185,22 +185,18 @@ To synchronously grab frames, first start the camera: g_assert_no_error (error); ~~~ -Now you have two options with regard to memory buffers. If you already have a -suitable sized buffer, just pass it to `uca_camera_grab`. Otherwise pass a -pointer pointing to `NULL` (this is different from a `NULL` pointer!). In this -case memory will be allocated for you: +Now, you have to allocate a suitably sized buffer and pass it to +`uca_camera_grab`. ~~~ {.c} - gpointer buffer_1 = NULL; /* A pointer pointing to NULL */ - gpointer buffer_2 = g_malloc0 (640 * 480 * 2); + gpointer buffer = g_malloc0 (640 * 480 * 2); - /* Memory will be allocated. Remember to free it! */ - uca_camera_grab (camera, &buffer_1, &error); - - /* Memory buffer will be used */ - uca_camera_grab (camera, &buffer_2, &error); + uca_camera_grab (camera, buffer, &error); ~~~ +You have to make sure that the buffer is large enough by querying the size of +the region of interest and the number of bits that are transferred. + ### Getting and setting camera parameters @@ -405,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) @@ -417,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 |