開源相機管理庫Aravis例程學習(一)——單幀採集single-acquisition

paw5zx發表於2024-04-10

目錄
  • 簡介
  • 原始碼
  • 函式說明
    • arv_camera_new
    • arv_camera_acquisition
    • arv_camera_get_model_name
    • arv_buffer_get_image_width
    • arv_buffer_get_image_height

簡介

本文針對官方例程中的第一個例程:single-acquisition做簡單的講解,並簡單分析其中呼叫的arv_camera_new arv_camera_acquisitionarv_camera_get_model_name arv_buffer_get_image_width arv_buffer_get_image_height 函式。

aravis版本:0.8.31
作業系統:ubuntu-20.04
gcc版本:9.4.0

原始碼

/* SPDX-License-Identifier:Unlicense */

/* Aravis header */

#include <arv.h>

/* Standard headers */

#include <stdlib.h>
#include <stdio.h>

/*
 * Connect to the first available camera, then acquire a single buffer.
 */

int main (int argc, char **argv)
{
	ArvCamera *camera;
	ArvBuffer *buffer;
	GError *error = NULL;

	/* Connect to the first available camera */
	camera = arv_camera_new (NULL, &error);
    //camera = arv_camera_new ("192.168.6.23", &error);

	if (ARV_IS_CAMERA (camera)) {
		printf ("Found camera '%s'\n", arv_camera_get_model_name (camera, NULL));

		/* Acquire a single buffer */
		buffer = arv_camera_acquisition (camera, 0, &error);

		if (ARV_IS_BUFFER (buffer)) {
			/* Display some informations about the retrieved buffer */
			printf ("Acquired %d×%d buffer\n",
				arv_buffer_get_image_width (buffer),
				arv_buffer_get_image_height (buffer));
			/* Destroy the buffer */
			g_clear_object (&buffer);
		}

		/* Destroy the camera instance */
		g_clear_object (&camera);
	}

	if (error != NULL) {
		/* An error happened, display the correspdonding message */
		printf ("Error: %s\n", error->message);
		return EXIT_FAILURE;
	}

	return EXIT_SUCCESS;
}

此例程較為簡單,每一步的細節檢視註釋即可,此處不過多講解。
執行結果:

函式說明

arv_camera_new

簡介:建立一個ArvCamera物件,如果name是NULL,則連線第一個可用的相機。

ArvCamera* arv_camera_new (const char* name, GError** error)

如果是Gige相機,name的格式可以是:

  • <vendor>-<model>-<serial>
  • <vendor_alias>-<serial>
  • <vendor>-<serial>
  • <user_id>
  • <ip_address>
  • <mac_address>

例如:

  • The Imaging Source Europe GmbH-DFK 33GX265-39020369
  • The Imaging Source Europe GmbH-39020369
  • TIS-39020369
  • 192.168.0.2
  • 00:07:48:af:a2:61

Available since 0.8.0

arv_camera_acquisition

簡介:獲取一幀影像。
注意:①本函式會將相機設定為單幀採集模式②返回的buffer最終必須要透過g_object_unref()釋放

ArvBuffer* arv_camera_acquisition(
	ArvCamera* camera,         
	guint64 timeout,     //採集超時時間,單位µs
	GError** error)

Available since: 0.8.0

arv_camera_get_model_name

簡介:獲取相機型號名稱

const char* arv_camera_get_model_name (ArvCamera* camera, GError** error)

Available since 0.8.0

arv_buffer_get_image_width

簡介:獲取圖片的width
注意:此函式只能在buffer payload為ARV_BUFFER_PAYLOAD_TYPE_IMAGEARV_BUFFER_PAYLOAD_TYPE_EXTENDED_CHUNK_DATAARV_BUFFER_PAYLOAD_TYPE_MULTIPART時使用

gint arv_buffer_get_image_width(ArvBuffer* buffer)

Available since: 0.4.0

arv_buffer_get_image_height

簡介:獲取圖片的height
注意:此函式只能在buffer payload為ARV_BUFFER_PAYLOAD_TYPE_IMAGEARV_BUFFER_PAYLOAD_TYPE_EXTENDED_CHUNK_DATAARV_BUFFER_PAYLOAD_TYPE_MULTIPART時使用

gint arv_buffer_get_image_height(ArvBuffer* buffer)

Available since: 0.4.0

相關文章