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

目录

简介

本文针对官方例程中的:03-camera-api做简单的讲解。并介绍其中调用的arv_camera_get_regionarv_camera_get_pixel_format_as_stringarv_camera_get_pixel_formatARV_PIXEL_FORMAT_BIT_PER_PIXEL

aravis版本:0.8.31

操作系统:ubuntu-20.04

gcc版本:9.4.0

例程代码

这段代码使用Aravis的API,获取相机的一些基本设置,如图像的宽度、高度和像素格式,主要操作步骤如下:

  • 连接相机
  • 获取图像宽度,高度,像素格式等信息
  • 释放资源
c 复制代码
/* 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 ArvCamera 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;
		int format_number;
		int bit_per_pixel;

		printf ("Found camera '%s'\n", arv_camera_get_model_name (camera, NULL));
		//获取图像宽度和高度
		if (!error) arv_camera_get_region (camera, NULL, NULL, &width, &height, &error);
		//获取图像像素格式
		if (!error) pixel_format = arv_camera_get_pixel_format_as_string (camera, &error);
		if (!error) format_number = arv_camera_get_pixel_format (camera, &error);
		//获取图像像素位数
		if (!error) bit_per_pixel = ARV_PIXEL_FORMAT_BIT_PER_PIXEL (format_number);
		

		if (error == NULL) {
			printf ("Width = %d\n", width);
			printf ("Height = %d\n", height);
			printf ("Pixel format = %s\n", pixel_format);
			printf ("Pixel format number = %d\n", format_number);
			printf ("Bit per pixel = %d\n", bit_per_pixel);
		}

		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;
}

运行结果:

函数说明

arv_camera_get_region

简介:用于获取相机当前的感兴趣区域(ROI),此函数会将当前相机的ROI的位置坐标(x,y)和尺寸(width,height)通过指针返回,并记录错误信息。

c 复制代码
void arv_camera_get_region (
  ArvCamera* camera,
  gint* x,
  gint* y,
  gint* width,
  gint* height,
  GError** error
)

其中:

in\]camera:相机对象 \[out\]x:ROI起始x坐标 \[out\]y:ROI起始y坐标 \[out\]width:ROI宽度 \[out\]height:ROI高度 \[out\]error:错误信息 Available since: 0.8.0 ## arv_camera_get_pixel_format_as_string 简介:从连接的相机中获取当前设置的像素格式,以字符串形式返回。 ```c const char* arv_camera_get_pixel_format_as_string ( ArvCamera* camera GError** error ) ``` Available since: 0.8.0 ## arv_camera_get_pixel_format 简介:从连接的相机中获取当前设置的像素格式,返回其编码。 ```c ArvPixelFormat arv_camera_get_pixel_format( ArvCamera* camera GError** error ) ``` Available since: 0.8.0 ## ARV_PIXEL_FORMAT_BIT_PER_PIXEL 简介:宏定义,用于获取pixel_format的第17位到第24位的值,其表示的是像素格式的Bpp(bits per pixel)。 ```c #define ARV_PIXEL_FORMAT_BIT_PER_PIXEL(pixel_format) (((pixel_format) >> 16) & 0xff) ```

相关推荐
大江东去浪淘尽千古风流人物2 小时前
【cuVSLAM】GPU 加速、多相机、实时视觉/视觉惯性 SLAM设计优势
c++·人工智能·数码相机·ubuntu·计算机视觉·augmented reality
自信150413057598 小时前
重生之从0开始学习c++之模板初级
c++·学习
历程里程碑8 小时前
2. Git版本回退全攻略:轻松掌握代码时光机
大数据·c++·git·elasticsearch·搜索引擎·github·全文检索
极客智造8 小时前
深度解析 C++ 类继承与多态:面向对象编程的核心
c++
零号全栈寒江独钓11 小时前
基于c/c++实现linux/windows跨平台获取ntp网络时间戳
linux·c语言·c++·windows
CSCN新手听安11 小时前
【linux】高级IO,以ET模式运行的epoll版本的TCP服务器实现reactor反应堆
linux·运维·服务器·c++·高级io·epoll·reactor反应堆
松☆13 小时前
C++ 算法竞赛题解:P13569 [CCPC 2024 重庆站] osu!mania —— 浮点数精度陷阱与 `eps` 的深度解析
开发语言·c++·算法
(Charon)13 小时前
【C++/Qt】C++/Qt 实现 TCP Server:支持启动监听、消息收发、日志保存
c++·qt·tcp/ip
并不喜欢吃鱼14 小时前
从零开始C++----七.继承及相关模型和底层(上篇)
开发语言·c++
tankeven15 小时前
HJ182 画展布置
c++·算法