开源相机管理库Aravis例程学习(六)——camera-features
简介
本文针对官方例程中的: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 <arv.h>
/* Standard headers */
#include <stdlib.h>
#include <stdio.h>
/*
* 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);
}
运行结果:
函数说明
arv_camera_get_integer
简介:获取已连接相机的一个整数型特性的值
gint64 arv_camera_get_integer (
ArvCamera* camera,
const char* feature,
GError** error
)
Available since: 0.8.0
arv_camera_get_string
简介:获取已连接相机的一个字符串型特性的值
const char* arv_camera_get_string (
ArvCamera* camera,
const char* feature,
GError** error
)
Available since: 0.8.0