目錄簡介源碼函數說明arv_camera_newarv_camera_acquisitionarv_camera_get_model_namearv_buffer_get_image_widtharv_buffer_get_image_height 簡介 本文針對官方常式中的第一個常式:single ...
目錄
簡介
本文針對官方常式中的第一個常式:single-acquisition做簡單的講解,並簡單分析其中調用的arv_camera_new
,arv_camera_acquisition
,arv_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_IMAGE
、ARV_BUFFER_PAYLOAD_TYPE_EXTENDED_CHUNK_DATA
或ARV_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_IMAGE
、ARV_BUFFER_PAYLOAD_TYPE_EXTENDED_CHUNK_DATA
或ARV_BUFFER_PAYLOAD_TYPE_MULTIPART
時使用
gint arv_buffer_get_image_height(ArvBuffer* buffer)
Available since: 0.4.0