开源相机管理库Aravis例程学习(六)——camera-features

开源相机管理库Aravis例程学习(六)——camera-features

简介

本文针对官方例程中的:04-camera-features做简单的讲解。并介绍其中调用的arv_camera_get_integerarv_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_integerarv_camera_get_string)来获取的相机的参数。

我们查看03-camera-api中的arv_camera_get_regionarv_camera_get_pixel_format_as_string的函数定义可以发现,他们的底层其实就是通过调用arv_camera_get_integerarv_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

  • 5
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值