Imatest IT:直接讀取模式

使用直接讀取模式將影像傳遞給 IT 部門

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 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 選項欄位。標記為「可選通過/失敗輸出」的字段,其值將複製到 JSON 輸出的「passfail」部分。標記為「INI 覆蓋」的欄位將覆蓋 Imatest INI 檔案中的對應值。

JSON 元素名稱

筆記

必需的高度影像數組中的行數。
寬度影像數組的列數。
ncolors顏色通道數。如果分析的是拜耳RAW影像或灰階影像,請設定為1。
擴大

對於原始影像數組,請使用 Imatest Master 的「讀取原始資料」設定對話方塊中定義的擴充。否則,請使用

  • "row_major_interleaved" 或 "row_major_interleaved_rgb":資料以 RGB 三元組的形式排列,形式為 [R 11 G 11 B 11 R 12 G 12 B 12 ... R 1m G 1m B 1m ... R n1 G nm G nm 1]
  • "row_major_interleaved_bgr": 資料以 BGR 三元組的形式排列,形式為 [B 11 G 11 R 11 B 12 G 12 R 12 ... B 1m G 1m R 1m ... B n1 G n1 Rn1 ... B nm G nm R nm]
  • "row_major_interleaved_rgba": 資料以 RGBA 四元組的形式排列,形式為 [R 11 G 11 B 11 A 11 R 12 G 12 B 12 A 12 ... R 1m G 1m B 1m A 1m ... R n1 G1 B nm
  • "row_major_interleaved_bgra": 資料以BGRA四元組的形式排列,形式為 [B 11 G 11 R 11 A 11 B 12 G 12 R 12 A 12 ... B 1m G 1m R 1m A 1m ... B n1
  • "row_major_planar": 資料依 R、G、B 平面排列,形式為 [R 11 R 12 ... R 1m R 21 ... R nm G 11 ... G nm B 11 ... B nm ]
  • "column_major_planar": 資料依 R、G、B 平面排列,形式為 [R 11 R 21 ... R n1 R 12 ... R nm G 11 ... G nm B 11 ... B nm ]

注意:行優先格式較常見,所以如果拿不準,請先嘗試這種格式。

注意:對於單色、行優先的數據,請使用「row_major_planar」。

檔案根目錄儲存結果的完整影像路徑(例如 *.csv、*.png)。
可選的通過/失敗輸出零件編號包含設備部件號的字串。預設為“未輸入”。
序號包含設備序號的字串。預設為“未輸入”。
車站生產站。預設為空字串。
操作員站點操作員。預設為空字串。
姓名僅當提供了值時,此欄位才會出現在「通過/失敗」輸出中。
手術僅當提供了值時,此欄位才會出現在「通過/失敗」輸出中。
地位僅當提供了值時,此欄位才會出現在「通過/失敗」輸出中。
選購 INI 覆蓋 [僅限 SFRplus]裁切邊框一個整數數組,用於定義要排除的影像邊界(以像素為單位)([左,右,上,下])
鏡頭到圖表的距離(公分)標量雙精度浮點數,表示鏡頭到視力表的距離,單位為公分。
圖表高度(公分)一個標量雙精度浮點數,表示圖表高度(以公分為單位)。
可選的 INI 覆蓋設定 [僅限瑕疵]熱像素類型一個標量整數,表示熱像素閾值類型。設定為 1 表示無閾值,設定為 2 表示絕對閾值,設定為 3 表示百分比閾值。
死像素類型一個標量整數,表示死像素閾值類型。設定為 1 表示無閾值,設定為 2 表示絕對閾值,設定為 3 表示百分比閾值。
熱像素閾值一個包含熱像素閾值的雙元素數組,形式為:[絕對閾值,百分比閾值]。
死像素閾值一個包含死像素閾值的雙元素數組,形式為:[絕對閾值,百分比閾值]。
瑕疵分析用於切換瑕疵分析的布林標誌。設定為 1 啟用瑕疵分析,設定為 0 停用瑕疵分析。
均勻性分析用於切換均勻性分析的布林標誌。設定為 1 啟用瑕疵分析,設定為 0 停用。
可選診斷字段顯示影像一個布林標誌,如果設定為 true(或 1),則會在讀取並解碼(如果需要)後顯示提供的圖像。