使用直接读取模式将图像传递给 IT 部门
For direct image passing, the varargin parameter includes two extra mxArrays, one containing the image data of the appropriate type (signed or unsigned 8, 16, or 32 bit integers), and the other a char* in JSON format containing the information needed to decode (or reconstruct) the image.
The rawFile parameter is created using the mxCreateNumericMatrix() function, passing in the number of rows (1), the size of the image array, a constant representing the data format (which can be mxINT8_CLASS, mxUINT8_CLASS, mxINT16_CLASS, mxUINT16_CLASS, mxINT32_CLASS, or mxUINT32_CLASS), and the constant mxReal. Next, use mxFree() to deallocate the original data, and call setData() to copy your image array into the mxArray parameter.
The varargin parameter is an mxArray of type Cell Array. Use the mxCreateCellMatrix() to create the array, and then mxSetCell() to add the extra arguments to it.
For RGB and RAW images, the JSON object must contain the image width, height, ncolors (number of colors), fileroot, and an extension. If it is a RAW image, then use the extension that has been configured in your INI file using the Read Raw utility, otherwise see the table below for options. The fileroot will be used to direct where to write output files, and what the output filenames will be. The following C code snippet passes an image array of type unsigned short and a JSON metadata string to the mlfBlemish_shell() function.
unsigned short *rawPixels;
unsigned int pixelCount;
mxArray *outputJSON = NULL, *inputFile = NULL, *rootDir = NULL, *inputKeys = NULL, *opMode = NULL, *varargin = NULL, *imageData = NULL, *jsonData = NULL;
inputFile = mxCreateString("");
rootDir = mxCreateString("C:\ImatestSamples\");
opMode = mxCreateString("-15");
inputKeys = mxCreateString( "JSON");
jsonData = mxCreateString("{ "height": 1296, "width": 808, "ncolors": 1, "extension": "raw", "fileroot": "C:\ImatestSamples\blemish.raw"}}");
/// Load the image data from your source ...
imageData = mxCreateNumericMatrix(1, pixelCount, mxUINT16_CLASS, mxREAL );
mxFree((mxArray*)mxGetData(imageData));
mxSetData(imageData, rawPixels);
varargin = mxCreateCellMatrix(1, 2);
mxSetCell(varargin, 0, imageData);
mxSetCell(varargin, 1, jsonData);
mlfBlemish_shell(1, &outputJSON, inputFile, rootDir, inputKeys, opMode, varargin);
Images (processed RGB or RAW) can be passed directly from the calling program to the Imatest IT C++ Library when opMode is set to -15 (using the default INI file) or -17 (passing in an INI file path). Passing images directly is generally much faster than reading them from files, and strongly recommended for speed-critical high-volume testing.
For direct image passing, the varargin parameter includes two extra mwArrays, one containing the image data of the appropriate type (signed or unsigned 8, 16, or 32 bit integers), and the other a string in JSON format containing the information needed to decode (or reconstruct) the image.
The rawFile parameter is created using the mwArray constructor, passing in the size of the image array, a 1 (for a single dimension array), a constant representing the data format (which can be mxINT8_CLASS, mxUINT8_CLASS, mxINT16_CLASS, mxUINT16_CLASS, mxINT32_CLASS, or mxUINT32_CLASS), and the constant mxReal. Then use the setData() function to copy your image array into the mwArray parameter.
The varargin parameter is an mwArray of type Cell Array. Use the Get() and Set() functions to add the extra arguments to it.
For RGB and RAW images, the JSON object must contain the image width, height, ncolors (number of colors), fileroot, and an extension indicator. If it is a RAW image, then use the extension that has been configured in your INI file using the Read Raw utility, otherwise see the table below for options. The fileroot will be used to direct where to write output files, and what the output filenames will be. The following C++ code snippet passes an image array of type unsigned short and a JSON metadata string to the blemish_shell() function.
unsigned short *rawPixels;
unsigned int pixelCount;
/// Load the image data from your source here ...
const char *jsonOptionsStr = "{ "jstr": {"width": 1296,"height": 808,"ncolors": 1,"extension": "raw", "fileroot": "C:\ImatestSamples\blemish.raw"}}";
mwArray jsonOutput;
mwArray inputFile = mwArray("");
mwArray rootDir = mwArray("C:\ImatestSamples\");
mwArray inputKeys = mwArray("JSON");
mwArray opMode = mwArray("-15");
mwArray rawFile = mwArray(pixelCount, 1, mxUINT16_CLASS, mxREAL);
rawFile.SetData(rawPixels, pixelCount);
mwArray jsonOptions = mwArray(1,jsonOptionsStr);
mwArray varargin = mwArray(1,2,mxCELL_CLASS);
varargin.Get(1,1).Set(rawFile);
varargin.Get(1,2).Set(jsonOptions);
blemish_shell(1, jsonOutput, inputFile, rootDir, inputKeys, opMode, varargin);
Images (processed RGB or RAW) can be passed directly from the calling program to IT Python when op_mode is set to ImatestLibrary.DIRECT_READ. Passing images directly is generally much faster than reading them from files, and strongly recommended for speed-critical high-volume testing.
For direct image passing, the raw_data parameter contains the image (passed as a binary string, 8, 16, or 32 bits per pixel), or as an array.array object, with a data type code of either 'B' (uint8), 'H' (uint16), or 'I' (uint32), and the json_args parameter contains a JSON object with information needed to decode (or reconstruct) the image.
For RGB and RAW images, the json_args object must contain the image width, height, ncolors (number of colors), filename, and an extension indicator. If it is a RAW image, then use the extension that has been configured in your INI file using the Read Raw utility, otherwise see the table below for options. The filename will be used to direct where to write output files, and what the output filenames will be. The following Python script creates the json_args string using the ImatestLibrary.build_json_args() function, and passes it and the raw_data to the blemish_json() function. Note that this example is somewhat contrived - you normally wouldn't read the image from disk, you would have the raw_data stream already read in from some other source.
raw_data = None
/// Load your image data here...
raw_image_path = r'C:ImatestSamplesblemish.raw'
json_args = imatestLib.build_json_args(width=1296,
height=808,
ncolors=1,
extension='raw',
filename=raw_image_path)
result = imatestLib.blemish_json(input_file=None,
root_dir=root_dir,
op_mode=ImatestLibrary.OP_MODE_DIRECT_READ,
ini_file=ini_file,
raw_data=raw_data,
json_args=json_args)
Images (processed RGB or RAW) can be passed directly from the calling program to the Imatest IT .NET Library. Passing images directly is generally much faster than reading them from files, and strongly recommended for speed-critical high-volume testing.
For direct image passing, use one of the following module method signatures:
string [module].JSON(string rootDir, byte[] inputBytes, DirectReadOptions directReadOptions)
string [module].JSON(string rootDir, byte[] inputBytes, DirectReadOptions directReadOptions, string iniFilePath)
string [module].JSON(string rootDir, ushort[] inputBytes, DirectReadOptions directReadOptions)
string [module].JSON(string rootDir, ushort[] inputBytes, DirectReadOptions directReadOptions, string iniFilePath)
string [module].JSON(string rootDir, uint[] inputBytes, DirectReadOptions directReadOptions)
string [module].JSON(string rootDir, uint[] inputBytes, DirectReadOptions directReadOptions, string iniFilePath)
[module].JSON(String rootDir, Byte() inputBytes, DirectReadOptions directReadOptions) As String
[module].JSON(String rootDir, Byte() inputBytes, DirectReadOptions directReadOptions, String iniFilePath) As String
[module].JSON(String rootDir, UInt16() inputBytes, DirectReadOptions directReadOptions) As String
[module].JSON(String rootDir, UInt16() inputBytes, DirectReadOptions directReadOptions, String iniFilePath) As String
[module].JSON(String rootDir, UInt32() inputBytes, DirectReadOptions directReadOptions) As String
[module].JSON(String rootDir, UInt32() inputBytes, DirectReadOptions directReadOptions, String iniFilePath) As String
The inputBytes parameter contains the image data of the appropriate type (unsigned 8, 16, or 32 bit integers), and the directReadOptions parameter is an object containing the information needed to decode (or reconstruct) the image.
For RGB and RAW images, the DirectReadOptions object must contain the image Width, Height, NumberOfColors, Filename, and Extension values. If it is a RAW image, then use the extension that has been configured in your INI file using the Read Raw utility, otherwise see the table below for options. The Filename property will be used to direct where to write output files, and what the output filenames will be. The following code snippet passes an image array of type byte and a DirectReadOptions object to the blemish_shell() function.
UInt16[] imageData;
// Load the image data from your source ...
DirectReadOptions directReadOptions = new DirectReadOptions();
directReadOptions.Width = 1296;
directReadOptions.Height = 808;
directReadOptions.Extension = "raw";
directReadOptions.Filename = "C:\ImatestSamples\blemish.raw";
directReadOptions.NumberOfColors = 1;
string rootDir = "C:\ImatestSamples\";
string resultJSON = itLib.Blemish.JSON(rootDir, imageData, directReadOptions);
Dim imageData As UInt16
' Load the image data from your source ...
Dim DirectReadOptions As DirectReadOptions
directReadOptions = New DirectReadOptions()
directReadOptions.Width = 1296
directReadOptions.Height = 808
directReadOptions.Extension = "raw"
directReadOptions.Filename = "C:\ImatestSamples\blemish.raw"
directReadOptions.NumberOfColors = 1
Dim rootDir = "C:\ImatestSamples\"
Dim resultJSON = itLib.Blemish.JSON(rootDir, imageData, directReadOptions)
JSON 元素名称 | 笔记 | |
| 必需的 | 高度 | 图像数组中的行数。 |
| 宽度 | 图像数组的列数。 | |
| ncolors | 颜色通道数。如果分析的是拜耳RAW图像或灰度图像,请设置为1。 | |
| 扩大 | 对于原始图像数组,请使用 Imatest Master 的“读取原始数据”设置对话框中定义的扩展。否则,请使用
注意:行优先格式更常见,所以如果拿不准,请先尝试这种格式。 注意:对于单色、行优先的数据,请使用“row_major_planar”。 | |
| 文件根目录 | 保存结果的完整图像路径(例如 *.csv、*.png)。 | |
| 可选的通过/失败输出 | 零件编号 | 包含设备部件号的字符串。默认为“未输入”。 |
| 序列号 | 包含设备序列号的字符串。默认为“未输入”。 | |
| 车站 | 生产站。默认为空字符串。 | |
| 操作员 | 站点操作员。默认为空字符串。 | |
| 姓名 | 仅当提供了值时,此字段才会出现在“通过/失败”输出中。 | |
| 手术 | 仅当提供了值时,此字段才会出现在“通过/失败”输出中。 | |
| 地位 | 仅当提供了值时,此字段才会出现在“通过/失败”输出中。 | |
| 可选 INI 覆盖 [仅限 SFRplus] | 裁剪边框 | 一个整数数组,用于定义要排除的图像边界(以像素为单位)([左,右,上,下]) |
| 镜头到图表的距离(厘米) | 标量双精度浮点数,表示镜头到视力表的距离,单位为厘米。 | |
| 图表高度(厘米) | 一个标量双精度浮点数,表示图表高度(以厘米为单位)。 | |
| 可选的 INI 覆盖设置 [仅限瑕疵] | 热像素类型 | 一个标量整数,表示热像素阈值类型。设置为 1 表示无阈值,设置为 2 表示绝对阈值,设置为 3 表示百分比阈值。 |
| 死像素类型 | 一个标量整数,表示死像素阈值类型。设置为 1 表示无阈值,设置为 2 表示绝对阈值,设置为 3 表示百分比阈值。 | |
| 热像素阈值 | 一个包含热像素阈值的双元素数组,形式为:[绝对阈值,百分比阈值]。 | |
| 死像素阈值 | 一个包含死像素阈值的双元素数组,形式为:[绝对阈值,百分比阈值]。 | |
| 瑕疵分析 | 用于切换瑕疵分析的布尔标志。设置为 1 启用瑕疵分析,设置为 0 禁用瑕疵分析。 | |
| 均匀性分析 | 用于切换均匀性分析的布尔标志。设置为 1 启用瑕疵分析,设置为 0 禁用。 | |
| 可选诊断字段 | 显示图像 | 一个布尔标志,如果设置为 true(或 1),则会在读取并解码(如果需要)后显示提供的图像。 |