我们提供安全,免费的手游软件下载!
本文将对官方例程中的04-camera-features进行简要解读,并介绍其中调用的arv_camera_get_integer 和 arv_camera_get_string。
aravis版本:0.8.31
操作系统:ubuntu-20.04
gcc版本:9.4.0
以下代码使用Aravis的API,获取相机的一些基本设置,如图像的宽度、高度和像素格式,主要操作步骤如下:
/* SPDX-License-Identifier:Unlicense */
/* Aravis header */
#include
/* Standard headers */
#include
#include
// Connect to the first available camera, then display the current settings for image width and height, as well as the pixel format, using the more generic ArvCamera feature API.
int main (int argc, char **argv)
{
ArvCamera *camera;
GError *error = NULL;
//连接相机
camera = arv_camera_new (NULL, &error);
if (ARV_IS_CAMERA (camera)) {
int width;
int height;
const char *pixel_format;
printf ("Found camera '%s'\n", arv_camera_get_model_name (camera, NULL));
/* Retrieve generally mandatory features for transmitters */
if (!error) width = arv_camera_get_integer (camera, "Width", &error);
if (!error) height = arv_camera_get_integer (camera, "Height", &error);
if (!error) pixel_format = arv_camera_get_string (camera, "PixelFormat", &error);
if (error == NULL) {
printf ("Width = %d\n", width);
printf ("Height = %d\n", height);
printf ("Pixel format = %s\n", pixel_format);
}
g_clear_object (&camera);
}
if (error != NULL) {
/* En error happened, display the correspdonding message */
printf ("Error: %s\n", error->message);
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
这个例程与03-camera-api实现的功能相似,但不同之处在于本文的代码使用的是更为通用的API(arv_camera_get_integer 和 arv_camera_get_string)来获取相机的参数。
我们查看03-camera-api中的 arv_camera_get_region 和 arv_camera_get_pixel_format_as_string 的函数定义可以发现,他们的底层实际上是通过调用 arv_camera_get_integer 和 arv_camera_get_string 来实现相关功能:
//file: arvcamera.c
void arv_camera_get_region (ArvCamera *camera, gint *x, gint *y, gint *width, gint *height, GError **error)
{
ArvCameraPrivate *priv = arv_camera_get_instance_private (camera);
GError *local_error = NULL;
g_return_if_fail (ARV_IS_CAMERA (camera));
if (x != NULL)
*x = priv->has_region_offset ? arv_camera_get_integer (camera, "OffsetX", &local_error) : 0;
if (y != NULL && local_error == NULL)
*y = priv->has_region_offset ? arv_camera_get_integer (camera, "OffsetY", &local_error) : 0;
if (width != NULL && local_error == NULL)
*width = arv_camera_get_integer (camera, "Width", &local_error);
if (height != NULL && local_error == NULL)
*height = arv_camera_get_integer (camera, "Height", &local_error);
if (local_error != NULL)
g_propagate_error (error, local_error);
}
const char * arv_camera_get_pixel_format_as_string (ArvCamera *camera, GError **error)
{
return arv_camera_get_string (camera, "PixelFormat", error);
}
运行结果:
简介:获取已连接相机的一个整数型特性的值
gint64 arv_camera_get_integer (
ArvCamera* camera,
const char* feature,
GError** error
)
Available since: 0.8.0
简介:获取已连接相机的一个字符串型特性的值
const char* arv_camera_get_string (
ArvCamera* camera,
const char* feature,
GError** error
)
Available since: 0.8.0
热门资讯