开源相机管理库Aravis例程学习(六)——camera-features
1.开源相机管理库Aravis学习——安装2.开源相机管理库Aravis例程学习(一)——单帧采集single-acquisition3.开源相机管理库Aravis例程学习(二)——连续采集multiple-acquisition-main-thread4.开源相机管理库Aravis例程学习(三)——注册回调multiple-acquisition-callback5.开源相机管理库Aravis例程学习(四)——multiple-acquisition-signal6.开源相机管理库Aravis例程学习(五)——camera-api7.开源相机管理库Aravis学习——PixelFormat编码规则
8.开源相机管理库Aravis例程学习(六)——camera-features
9.开源相机管理库Aravis例程学习(七)——chunk-parser简介
本文针对官方例程中的: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
合集:
Aravis
分类:
工业相机 / Aravis
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)