FG Camera Library  1.7.1.0 (2025-08-27)
Loading...
Searching...
No Matches
Basic example source code

First Steps example source code.

/opt/ImagoTechnologies/SDK/examples/FGExample_Linux/src/main.c

1#include <stdio.h>
2#include <signal.h>
3
5
6#define NUM_BUFFERS 4 // number of image buffers used for the acquisition queue
7
8int isRunning = 1;
9
10// Signal handler for stopping the program
11static void sigint_handler(int signo)
12{
13 if (signo == SIGINT)
14 isRunning = 0;
15}
16
17int main()
18{
19 FG_IMAGE imageList[NUM_BUFFERS];
20 UINT32 fgResult;
21 char ErrText[512];
22 UINT32 x1, y1, x2, y2;
23 UINT32 width, height;
24 enum eFG_PIXEL_TYPE pixel_type;
25
26 // register signal handler for CTRL-C:
27 signal(SIGINT, sigint_handler);
28
29
31 // initialize the camera using automatic type detection
33 if (fgResult != FG_ERROR_CODE_NoError)
34 {
35 FG_get_last_error(ErrText, sizeof(ErrText));
36 printf("FG_install_camera() failed! \n - ErrorCode: %d \n - ErrorText '%s'", fgResult, ErrText);
37 return -1;
38 }
40
41
43 // set trigger mode to free-run:
45
46 // get default AOI and pixel type:
47 FG_get_aoi(&x1, &y1, &x2, &y2, &pixel_type);
48 // set new pixel type:
49 FG_set_aoi(x1, y1, x2, y2, FG_PIXEL_TYPE_Y_8);
50
51 // Set the exposure time:
52 FG_set_shutter_time(1000); // 1000 microseconds
54
55 width = x2 - x1 + 1;
56 height = y2 - y1 + 1;
57 printf("Sensor size: %u x %u\n", width, height);
58
60 // allocate image buffers and them to the queue
61 for (UINT32 i = 0; i < NUM_BUFFERS; i++)
62 {
63 FG_alloc_image(&imageList[i]);
64 FG_append_image(&imageList[i]);
65 }
67
68 printf("Starting acquisition loop, press CTRL-C to stop the program.\n");
69
71 while (isRunning)
72 {
73 FG_IMAGE currentImage;
74
75 // wait for the image
76 fgResult = FG_get_image(&currentImage, 1000); // 1000 ms timeout
77 if (fgResult == FG_ERROR_CODE_NoError)
78 {
79 if ((currentImage.image_number % 100) == 0)
80 printf("100 frames received, current frame number: %u\n", currentImage.image_number);
81
82 // todo: work with the image data => currentImage.pixel_ptr[x + y * width];
83
84 // add the buffer again to the free queue again
85 FG_append_image(&currentImage);
86 }
87 else if (fgResult == FG_ERROR_CODE_BrokenImage)
88 {
89 // the image is valid, but the contents are broken or incomplete, add the buffer again or release it
90 printf("FG_get_image() returned a broken image\n");
91 FG_append_image(&currentImage);
92 }
93 else if (fgResult == FG_ERROR_CODE_GrabTimeOut)
94 {
95 // timout occurred, the image is invalid
96 printf("FG_get_image() timeout occurred\n");
97 }
98 else
99 {
100 // other error occured, the image is invalid
101 FG_get_last_error(ErrText, sizeof(ErrText));
102 printf("FG_get_image() failed! \n - ErrorCode: %d \n - ErrorText '%s'", fgResult, ErrText);
103 break;
104 }
105 }
107
108 printf("Closing the program...\n");
109
111 // abort image acquisition
113
114 // free buffers
115 for (UINT32 i = 0; i < NUM_BUFFERS; i++)
116 {
117 FG_free_image(&imageList[i]);
118 }
119
120 // close the camera
123
124 return 0;
125}
Header file for this libraray.
@ FG_CAMERA_TYPE_X_X_IMAGO_Vxx_AUTO
IMAGO VisionCam/Sensor (automatic)
Definition FG_CameraInterface.h:54
eFG_PIXEL_TYPE
The data format for storing images in memory, see FG_set_scan_param() and FG_set_aoi()
Definition FG_CameraInterface.h:125
@ FG_PIXEL_TYPE_Y_8
1 byte per pixel, can be monochrome or raw bayer values (depending on the sensor)
Definition FG_CameraInterface.h:126
@ FG_TRIGGER_MODE_FREERUN
Free-run triggered mode.
Definition FG_CameraInterface.h:160
@ FG_ERROR_CODE_NoError
The function was successful.
Definition FG_CameraInterface.h:146
@ FG_ERROR_CODE_BrokenImage
Only valid for FG_get_image(): the returned image contents are invalid.
Definition FG_CameraInterface.h:151
@ FG_ERROR_CODE_GrabTimeOut
Only valid for FG_get_image(): acquisition timeout.
Definition FG_CameraInterface.h:150
UINT32 DLL_FG_API FG_alloc_image(FG_IMAGE *img)
Allocates a new image buffer for storing sensor frames.
Definition FG_CameraInterface.cpp:640
UINT32 DLL_FG_API FG_get_image(FG_IMAGE *img, UINT32 TimeOut_ms)
Returns captured images to the user.
Definition FG_CameraInterface.cpp:679
UINT32 DLL_FG_API FG_free_image(FG_IMAGE *img)
Releases an image buffer.
Definition FG_CameraInterface.cpp:653
UINT32 DLL_FG_API FG_append_image(FG_IMAGE *img)
Puts an image buffer into the aquisition queue.
Definition FG_CameraInterface.cpp:666
UINT32 DLL_FG_API FG_stop_image(void)
Forces the camera to stop grabbing and using any buffers.
Definition FG_CameraInterface.cpp:716
UINT32 DLL_FG_API FG_get_last_error(char *error_sting, UINT32 max_string_size)
Returns an error description for the last failed library call.
Definition FG_CameraInterface.cpp:595
UINT32 DLL_FG_API FG_install_camera(enum eFG_CAMERA_TYPE camera_type,...)
Opens and initializes the camera.
Definition FG_CameraInterface.cpp:278
UINT32 DLL_FG_API FG_uninstall_camera(void)
Closes the camera.
Definition FG_CameraInterface.cpp:551
UINT32 DLL_FG_API FG_set_trigger_mode(enum eFG_TRIGGER_MODE trigger_mode)
Sets the trigger mode.
Definition FG_CameraInterface.cpp:844
UINT32 DLL_FG_API FG_set_aoi(UINT32 x1, UINT32 y1, UINT32 x2, UINT32 y2, enum eFG_PIXEL_TYPE pixel_type)
Sets the area of interest and the output format.
Definition FG_CameraInterface.cpp:745
UINT32 DLL_FG_API FG_set_shutter_time(UINT32 shutter_time_us)
Sets the exposure time in µs.
Definition FG_CameraInterface.cpp:949
UINT32 DLL_FG_API FG_get_aoi(UINT32 *x1, UINT32 *y1, UINT32 *x2, UINT32 *y2, enum eFG_PIXEL_TYPE *pixel_type)
Returns the area of interest and the output format.
Definition FG_CameraInterface.cpp:757
This structure stores information associated with image buffers.
Definition FG_CameraInterface.h:168
const UINT32 image_number
Image number, increments with every new image.
Definition FG_CameraInterface.h:174