FG Camera Library  1.5.0.0 (2023-09-08)
Virtual File Camera

Overview

The virtual file camera uses BMP files in a directory as the data source.

The library function FG_save_image() is useful to create BMP files from real sensor images. They can then later be processes with the virtual camera.

The following steps describe how to use the virutal camera:

  • Initialize the virtual camera by using FG_install_camera() with the argument FG_CAMERA_TYPE_FILE_BMP.
  • Specify the directory containing the BMP files by using the special feature "FilePath:<directory>".
  • Optional: use the special feature "FileName:<prefix_regex>" to configure a regular expression which is used as a file name prefix filter. The default value is ".*" (all file name prefixes).
  • Configure the trigger mode to software or free-run by using FG_set_trigger_mode().
  • Allocate image buffers and start acquisition as usual, see Typical workflow.

Example:

UINT32 width, height;
enum eFG_PIXEL_TYPE pixel_type;
INT64 file_count;
// set directory containing the bitmap files
FG_set_special_option("FilePath:/tmp", 0);
// set regular expression for the file name prefixes:
FG_set_special_option("FileName:.*", 0);
FG_get_special_option("FileCount", &file_count);
printf("%u images found\n", file_count);
FG_get_scan_param(NULL, NULL, &width, &height, NULL, &pixel_type);
printf("Image size: %u x %u\n", width, height);
// use free run mode
// allocate image buffers and them to the queue
for (UINT32 i = 0; i < 4; i++)
{
FG_alloc_image(&imageList[i]);
FG_append_image(&imageList[i]);
}
// acquisition loop
while (isRunning)
{
FG_IMAGE currentImage;
// get the next image
FG_get_image(&currentImage, 1000); // 1000 ms timeout
...
}

Detailed description

  • BMP files with color depths of 8, 24 and 32 bits per pixel are supported. They are automatically mapped to the pixel types FG_PIXEL_TYPE_Y_8, FG_PIXEL_TYPE_RGB_24 and FG_PIXEL_TYPE_RGBX_32.
  • All BMP files have to use the same image size and pixel format as the first BMP file.
  • Setting the special feature "FilePath" or "FileName" will scan and filter the specified directory for BMP files. The directory can also be rescanned during image acquisition to read different images. But the format of the BMP files may only change until the first buffer is allocated (FG_alloc_image()).
  • The file loading order is defined by the GNU alphasort function.
  • A dedicated library thread is used to load the BMP files and complete all enqueued image buffers in the background. After all files in the specified directory are loaded, the thread continues with the first file again.
  • The pixel type for storing RGB images can be selected between FG_PIXEL_TYPE_RGB_24 and FG_PIXEL_TYPE_RGBX_32 by using FG_set_aoi() / FG_set_scan_param() before the first buffer is allocated.
  • FG_set_aoi() / FG_set_scan_param() can be used to load regions of the BMP files. The AOI position may also be changed after the first buffer is allocated.

Special features

The following special features are supported (used with FG_set_special_option() / FG_get_special_option()):

Special features
Property name Description
FilePath:<directory> Sets the directory containing the BMP files. The function will scan the specified directory and apply the FileName filter.
The argument is reserved and should be set to 0. This property can only be written.
FileName:<prefix_regex> Sets the regular expression for filtering the file name prefixes. The function will scan the specified directory and apply the filter. The extended regular expression syntax is used (ERE). The default value is ".*". The string "\.(bmp|BMP)$" is appended automatically to the expression in order to filter for files with .bmp or .BMP suffix.
The argument is reserved and should be set to 0. This property can only be written.
FileCount Returns the number of filtered BMP files
This property can only be read.
FG_get_image
UINT32 DLL_FG_API FG_get_image(FG_IMAGE *img, UINT32 TimeOut_ms)
Returns captured images to the user.
Definition: FG_CameraInterface.cpp:605
FG_install_camera
UINT32 DLL_FG_API FG_install_camera(enum eFG_CAMERA_TYPE camera_type)
Opens and initializes the camera.
Definition: FG_CameraInterface.cpp:282
FG_IMAGE
This structure stores information associated with image buffers
Definition: FG_CameraInterface.h:151
FG_get_scan_param
UINT32 DLL_FG_API FG_get_scan_param(UINT32 *scan_x, UINT32 *scan_y, UINT32 *scan_width, UINT32 *scan_height, UINT32 *image_height, enum eFG_PIXEL_TYPE *pixel_type)
Returns the area of interest and the output format.
Definition: FG_CameraInterface.cpp:709
FG_CAMERA_TYPE_FILE_BMP
@ FG_CAMERA_TYPE_FILE_BMP
Virtual file camera using the BMP format.
Definition: FG_CameraInterface.h:104
FG_TRIGGER_MODE_FREERUN
@ FG_TRIGGER_MODE_FREERUN
Free-run triggered mode.
Definition: FG_CameraInterface.h:143
eFG_PIXEL_TYPE
eFG_PIXEL_TYPE
Specifies the format to use for captured images (see FG_get_aoi() / FG_set_aoi()).
Definition: FG_CameraInterface.h:108
FG_append_image
UINT32 DLL_FG_API FG_append_image(FG_IMAGE *img)
Puts an image buffer into the aquisition queue.
Definition: FG_CameraInterface.cpp:592
FG_set_special_option
UINT32 DLL_FG_API FG_set_special_option(const char *option, INT64 arg)
Configures a special camera property.
Definition: FG_CameraInterface.cpp:893
FG_alloc_image
UINT32 DLL_FG_API FG_alloc_image(FG_IMAGE *img)
Allocates a new image buffer for storing sensor frames.
Definition: FG_CameraInterface.cpp:566
FG_get_special_option
UINT32 DLL_FG_API FG_get_special_option(const char *option, INT64 *result)
Returns a special camera property value.
Definition: FG_CameraInterface.cpp:905
FG_set_trigger_mode
UINT32 DLL_FG_API FG_set_trigger_mode(enum eFG_TRIGGER_MODE trigger_mode)
Sets the trigger mode.
Definition: FG_CameraInterface.cpp:770