经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » 程序设计 » C++ » 查看文章
开源相机管理库Aravis例程学习(五)——camera-api
来源:cnblogs  作者:paw5zx  时间:2024/4/29 9:29:19  对本文有异议

简介

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

  • 连接相机
  • 获取图像宽度,高度,像素格式等信息
  • 释放资源
  1. /* SPDX-License-Identifier:Unlicense */
  2. /* Aravis header */
  3. #include <arv.h>
  4. /* Standard headers */
  5. #include <stdlib.h>
  6. #include <stdio.h>
  7. /*
  8. * Connect to the first available camera, then display the current settings for image width and height, as well as the
  9. * pixel format, using the ArvCamera API.
  10. */
  11. int main (int argc, char **argv)
  12. {
  13. ArvCamera *camera;
  14. GError *error = NULL;
  15. //连接相机
  16. camera = arv_camera_new (NULL, &error);
  17. if (ARV_IS_CAMERA (camera)) {
  18. int width;
  19. int height;
  20. const char *pixel_format;
  21. int format_number;
  22. int bit_per_pixel;
  23. printf ("Found camera '%s'\n", arv_camera_get_model_name (camera, NULL));
  24. //获取图像宽度和高度
  25. if (!error) arv_camera_get_region (camera, NULL, NULL, &width, &height, &error);
  26. //获取图像像素格式
  27. if (!error) pixel_format = arv_camera_get_pixel_format_as_string (camera, &error);
  28. if (!error) format_number = arv_camera_get_pixel_format (camera, &error);
  29. //获取图像像素位数
  30. if (!error) bit_per_pixel = ARV_PIXEL_FORMAT_BIT_PER_PIXEL (format_number);
  31. if (error == NULL) {
  32. printf ("Width = %d\n", width);
  33. printf ("Height = %d\n", height);
  34. printf ("Pixel format = %s\n", pixel_format);
  35. printf ("Pixel format number = %d\n", format_number);
  36. printf ("Bit per pixel = %d\n", bit_per_pixel);
  37. }
  38. g_clear_object (&camera);
  39. }
  40. if (error != NULL) {
  41. /* En error happened, display the correspdonding message */
  42. printf ("Error: %s\n", error->message);
  43. return EXIT_FAILURE;
  44. }
  45. return EXIT_SUCCESS;
  46. }

运行结果:

函数说明

arv_camera_get_region

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

  1. void arv_camera_get_region (
  2. ArvCamera* camera,
  3. gint* x,
  4. gint* y,
  5. gint* width,
  6. gint* height,
  7. GError** error
  8. )

其中:
[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

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

  1. const char* arv_camera_get_pixel_format_as_string (
  2. ArvCamera* camera
  3. GError** error
  4. )

Available since: 0.8.0

arv_camera_get_pixel_format

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

  1. ArvPixelFormat arv_camera_get_pixel_format(
  2. ArvCamera* camera
  3. GError** error
  4. )

Available since: 0.8.0

ARV_PIXEL_FORMAT_BIT_PER_PIXEL

简介:宏定义,用于获取pixel_format的第17位到第24位的值,其表示的是像素格式的Bpp(bits per pixel)。

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

原文链接:https://www.cnblogs.com/paw5zx/p/18163483

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号