<< 点击显示目录 >> 主页
mappVision帮助助手 > 机器视觉帮助 > mapp Vision > 编程 > 库 > 核心库 > ViBase > 功能块 功能说明 |
通过功能块 ViBaseGetImage,可以从摄像机中获取最后一次采集的图像,并将其存储在 PLC DRAM 存储器的数据缓冲区中。然后可在 mapp View HMI 应用程序中显示该图像,或使用 FileIO 库持久化该图像(请参阅用例:备份、显示或提供摄像机图像)。
视觉组件的引用(参见ViComponentType)设置在功能块的输入 MpLink 上。
此外,还必须预留一个合适的内存区域,以便功能块填充图像数据。数据缓冲区的起始地址和大小必须在输入 Buffer 和 BufferSize 中指定。
输入类型可用于确定图像是以未压缩的位图格式存储(viBASE_IMAGE_TYPE_BMP= 0),还是以有质量损失的压缩 JPG 格式存储(viBASE_IMAGE_TYPE_JPG= 1)。
压缩 JPG 图像的质量水平可通过输入的 QualityLevel(质量水平)进行调整,数值范围为 1 至 100。数值越低,压缩越严重,压缩损失越大,即图像质量越低。
默认情况下,图像压缩未激活。在这种情况下,输入 QualityLevel 的值无关紧要。
功能块的最长处理时间可以通过输入 Timeout 的正值以 TIME 格式定义。默认情况下(超时 = 0),无时间限制。超时后,功能块终止,错误状态编号为viBASE_ERR_EXECUTION_TIMEOUT。
输出 激活表示已开始从摄像机传输图像数据。在这种状态下,下一幅图像已经可以通过摄像机获取,而不会影响功能块的执行。
成功执行后,功能块会将图像数据写入数据缓冲区,在输出端 Done 上显示处理完成,并在输出端 StatusID 上返回值 0。此外,实际图像数据大小会显示在输出 BufferLen 上,摄像机获取所提供图像的净时间会显示在输出 Nettime 上。功能块不会修改数据缓冲区中的任何剩余区域。
功能块执行错误会在输出端 Error 上显示,并在输出端 StatusID 上显示相应的错误状态编号。发生错误时,功能块也可能会用临时元数据或图像数据写入内存区域的部分内容。
可能的错误是内存区域的大小不足以容纳所有图像数据。错误状态编号viBASE_ERR_IMG_TOO_BIG 表示这种情况。此时输出 BufferLen 和 Nettime 不会输出图像的数据大小和 NetTime。不过,日志中会记录一条包含此信息的错误信息。
有关确定数据缓冲区大小的信息
•
•对于未压缩的位图图像,以下经验法则适用于以字节为单位的内存需求:~10,000 + 像素数。
•像素数根据图像尺寸计算:
•图像宽度 * 图像高度。
•线宽 * 线高 * 每图像行数(对于线传感器获取的图像)。
•对于 JPG 压缩图像,这种大小的数据缓冲区可作为内存优化的起点:
•调用所需的 JPG 压缩功能块。
•从输出 BufferLen 或日志条目中读取压缩图像的实际图像数据大小。
•根据确定的实际图像数据大小加上一定的预留量调整内存分配。
质量级别 |
1 |
10 |
25 |
40 |
50 |
75 |
80 |
100 |
---|---|---|---|---|---|---|---|---|
数据缩减 |
98% |
97% |
93% |
90% |
87% |
74% |
69% |
38% |
图功能块 ViBaseGetImage
With function block ViBaseGetImage, the last acquired image can be retrieved from the camera and stored in a data buffer in DRAM memory on the PLC. This image can then be displayed in a mapp View HMI application or persisted using library FileIO (see Use cases: Backing up, displaying or providing the camera image).
The reference to the vision component (see ViComponentType) is set on input MpLink of the function block.
In addition, a suitable memory area must be reserved that the function block can fill with the image data. The starting address and size of this data buffer must be specified on inputs Buffer and BufferSize.
Input Type can be used to determine whether the image is stored in uncompressed bitmap format (viBASE_IMAGE_TYPE_BMP = 0) or in compressed JPG format with loss of quality (viBASE_IMAGE_TYPE_JPG = 1).
The quality level of the compressed JPG image can be adjusted via input QualityLevel in a range of values from 1 to 100. A low value causes heavy compression with high compression losses, i.e. low image quality.
By default, image compression is not active. In this case, the value on input QualityLevel is irrelevant.
The maximum processing time of the function block can be defined in TIME format with a positive value on input Timeout. By default (timeout = 0), no time limit is active. After a timeout, the function block aborts with error status number viBASE_ERR_EXECUTION_TIMEOUT.
Output Active indicates that data transfer of the image from the camera has started. In this state, the next image can already be acquired with the camera without influencing the function block.
When successfully executed, the function block writes the image data to the data buffer, indicates completion of the process on output Done and returns value 0 on output StatusID. In addition, the actual image data size appears on output BufferLen and the NetTime when the camera acquired the provided image appears on output Nettime. Any surplus area in the data buffer is not modified by the function block.
An execution error of the function block is indicated on output Error and with a corresponding error status number on output StatusID. The contents of the memory area may also have been partially written with temporary metadata or image data by the function block in the event of an error.
A possible error is that the size of the memory area is not sufficient for all image data. This is indicated by error status number viBASE_ERR_IMG_TOO_BIG. Outputs BufferLen and Nettime then do not output the data size and NetTime of the image. However, an error message is entered in the logbook with this information.
Information about determining the data buffer size
•
•For uncompressed bitmap images, the following rule of thumb applies for the memory requirement in bytes: ~10,000 + Number of pixels.
•The number of pixels is calculated from the image dimensions:
•ImageWidth * ImageHeight.
•LineWidth * LineHeight * LinesPerImage (for line sensor acquired images).
•For JPG compressed images, a data buffer of this size can serve as a starting point for memory optimization:
•Call the function block with the desired JPG compression.
•Read the actual image data size of the compressed image from output BufferLen or from the logbook entry.
•Adapt memory allocation to the actual image data size determined plus a certain amount in reserve.
QualityLevel |
1 |
10 |
25 |
40 |
50 |
75 |
80 |
100 |
---|---|---|---|---|---|---|---|---|
Data reduction |
98% |
97% |
93% |
90% |
87% |
74% |
69% |
38% |
Table: Data saved by JPG compression of a sample image
Fig.: Function block ViBaseGetImage