Pharma-Code Reading
This sample illustrates the following
- One pharma code is read per image using the function F_VN_ReadPharmaCodeExp
- The execution time of the function is monitored via a watchdog.
Explanation
- The function F_VN_ReadPharmaCodeExp searches for pharma codes in the specified image and reads them. In contrast to the function F_VN_ReadPharmaCode, the code position is also returned.
- Code-like structures have a negative effect on the execution time. To prevent cycle time overruns, in the sample the function F_VN_ReadPharmaCodeExp is monitored via a watchdog. The sample Blob Detection with watchdog monitoring explains how to use a watchdog.
Variables
hr : HRESULT;
ipImageIn : ITcVnImage;
ipImageInDisp : ITcVnDisplayableImage;
ipImageRes : ITcVnImage;
ipImageResDisp : ITcVnDisplayableImage;
// Pharma-Code
ipCodeDecodedList : ITcVnContainer;
ipCodeContourList : ITcVnContainer;
sCodeAsString : STRING(255);
aCodeContour : ARRAY[0..3] OF TcVnPoint2_DINT;
// Watchdog
hrWD : HRESULT;
tStop : DINT := 5000;
tRest : DINT;
// Output
sText : STRING;
// Color
aColorRed : TcVnVector4_LREAL := [255, 0, 0];
Code
// Execute the Pharma-Code Reading Function monitored by the Watchdog-Function
// ---------------------------------------------------------------
hrWD := F_VN_StartRelWatchdog(tStop, S_OK);
hr := F_VN_ReadPharmaCodeExp(
ipSrcImage := ipImageIn,
ipDecodedData := ipCodeDecodedList,
ipContours := ipCodeContourList,
nCodeNumber := 1,
nMinBarNumber := 4,
hrPrev := hr);
hrWD := F_VN_StopWatchdog(hrWD, tRest => tRest);
// Check if the function was executed successfully
IF hr = S_OK THEN
// Export Code into String
hr := F_VN_ExportSubContainer_String(ipCodeDecodedList, 0, sCodeAsString, 255, hr);
// Write Code into Result Image
sText := CONCAT('Code: ', sCodeAsString);
hr := F_VN_PutTextExp(sText, ipImageRes, 25, 50, ETcVnFontType.TCVN_FT_HERSHEY_PLAIN, 3, aColorRed, 2, TCVN_LT_4_CONNECTED, FALSE, hr);
// Draw Code Contour into Result Image
hr := F_VN_DrawContours(ipCodeContourList, 0, ipImageRes, aColorRed, 3, hr);
ELSE
// Write HRESULT into Result Image
sText := CONCAT('Returncode ', DINT_TO_STRING(hr));
hr := F_VN_PutTextExp(sText, ipImageRes, 25, 50, ETcVnFontType.TCVN_FT_HERSHEY_PLAIN, 3, aColorRed,2, TCVN_LT_4_CONNECTED, FALSE, hr);
END_IF
// Write Code Reading proceeded time into Result Image
sText := CONCAT(CONCAT('Time: ', DINT_TO_STRING(tStop - tRest)), 'us');
hr := F_VN_PutTextExp(sText, ipImageRes, 25, 100, ETcVnFontType.TCVN_FT_HERSHEY_PLAIN, 3, aColorRed,2, TCVN_LT_4_CONNECTED, FALSE, hr);