首页 > 其他分享 >开源相机管理库Aravis例程学习(五)——camera-api

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

时间:2024-04-28 12:22:35浏览次数:14  
标签:arv api 例程 format Aravis camera error get pixel

目录

简介

本文针对官方例程中的: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,获取相机的一些基本设置,如图像的宽度、高度和像素格式,主要操作步骤如下:

  • 连接相机
  • 获取图像宽度,高度,像素格式等信息
  • 释放资源
/* 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)通过指针返回,并记录错误信息。

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

简介:从连接的相机中获取当前设置的像素格式,以字符串形式返回。

const char* arv_camera_get_pixel_format_as_string (
  ArvCamera* camera
  GError** error
)

Available since: 0.8.0

arv_camera_get_pixel_format

简介:从连接的相机中获取当前设置的像素格式,返回其编码。

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)。

#define ARV_PIXEL_FORMAT_BIT_PER_PIXEL(pixel_format) (((pixel_format) >> 16) & 0xff)

标签:arv,api,例程,format,Aravis,camera,error,get,pixel
From: https://www.cnblogs.com/paw5zx/p/18163483

相关文章

  • idea插件之apifox自动化测试
    /***测试apifox插件自动化读取*/@RestController@RequestMapping("/api")publicclassSwaggerApiFoxController{/***这是一个测试方法*@return*/@RequestMapping("/test")publicStringtest(){return"test";}}1......
  • Spring Boot 编写 API 的 10条最佳实践
    10个最佳实践,让您像专业人士一样编写SpringBootAPI,并结合编码示例和解释:1.RESTfulAPI设计原则:清晰一致的资源命名:使用准确反映API管理的资源的名词(例如,/products、/users)。@GetMapping("/products/{id}")publicResponseEntity<Product>getProductById(@PathVaria......
  • blender python api 将指定的顶点组(water)转换为颜色属性water_colors
    1.选中物体,进入权重绘制模式2.代码:importbpy#获取当前活动的物体obj=bpy.context.object#确保物体是网格类型ifobj.type!='MESH':print("当前激活的对象不是网格类型。")#exit()#使用exit()来提前退出脚本#获取名为“water”的顶点组vertex_gro......
  • blender python api 获取所有顶点组并将各自的顶点组转换为对应的颜色属性
    1.选中物体,进入权重绘制模式2.代码importbpy#获取当前活动的物体obj=bpy.context.object#确保物体是网格类型ifobj.type!='MESH':print("当前激活的对象不是网格类型。")#exit()#遍历所有顶点组forvg_nameinobj.vertex_groups.keys():#获......
  • 大小写相关API(tolower, toupper, islower, isupper)
    1.定义位于头文件中1.1tolowertolower函数用于将字符转换为小写形式,如果参数ch是大写字母,则返回对应的小写字母;否则返回原始字符。inttolower(intch);1.2touppertoupper函数用于将字符转换为大写形式,如果参数ch是小写字母,则返回对应的大写字母;否则返回原始......
  • Go的Gin框架中使用Cgo调用Python的CApi调用Python代码
    在Gin项目中定义Services用以唤起Python,值得注意的是需要在引入Python.h前使用#cgo声明依赖库packagecpython//#cgoCFLAGS:-I"Q:/Sill-/anaconda/envs/poetry/include"//#cgoLDFLAGS:-L"Q:/Sill-/anaconda/envs/poetry/libs"-lpython311//#include<Python.h>imp......
  • 界面控件DevExpress Office File API中文教程 - 如何实现PDF转换?
    DevExpressOfficeFileAPI是一个专为C#,VB.NET和ASP.NET等开发人员提供的非可视化.NET库。有了这个库,不用安装MicrosoftOffice,就可以完全自动处理Excel、Word等文档。开发人员使用一个非常易于操作的API就可以生成XLS,XLSx,DOC,DOCx,RTF,CSV和SnapReport等企业级文......
  • MinIO 常用 API 快速入门
    快速入门minio中文网minio官网minio有开源版和收费版,使用开源版时,若修改了minio的源代码,需要将修改后的源代码完全公开。启动miniominio文档提供了多个运行环境的安装流程,此处以windows为例,其它运行环境文档上都有介绍。相关文档下载minio.exe:https://dl.minio......
  • blender python api 使用脚本进行动画渲染
    1.摄像机“Camera”在一个名叫“渲染”的集合中2.代码:importbpy#设置输出路径和文件名output_path="/path/to/output/"#替换为你的输出路径filename="rendered_animation"#输出文件的前缀#获取名为“渲染”的集合render_collection_name="渲染"render_c......
  • 开源相机管理库Aravis例程学习(四)——multiple-acquisition-signal
    目录简介例程代码函数说明g_main_loop_newg_main_loop_rung_main_loop_quitg_signal_connectarv_stream_set_emit_signalsQ&A回调函数的同步调用与异步调用帧丢失问题简介本文针对官方例程中的:02-multiple-acquisition-signal做简单的讲解。并简单介绍其中调用的g_main_loop_new......