// Convert Images into the necessary color space
hr := F_VN_GetPixelFormat(ipImageIn, PixelFormat, hr);
IF PixelFormat.nChannels = 3 THEN
hr := F_VN_CopyImage(ipImageIn, ipImageRes, hr);
hr := F_VN_ConvertColorSpace(ipImageRes,
ipImageIn,
TCVN_CST_RGB_TO_GRAY,
hr);
ELSE
hr := F_VN_ConvertColorSpace(ipImageIn,
ipImageRes,
TCVN_CST_Gray_TO_RGB,
hr);
END_IF
// Image Segementation
hr := F_VN_Threshold(ipImageIn,
ipImageWork,
_BlobParams.fMinThreshold,
255,
TCVN_TT_Binary,
hr);
// Start Watchdog - DetectBlobs - Stop Watchdog
hrWD := F_VN_StartRelWatchdog(tStop, S_OK);
hrFunc := F_VN_DetectBlobs(ipSrcImage := ipImageWork,
ipBlobContours := ipContourList,
stParams := _BlobParams,
hrPrev := hr);
hrWD := F_VN_StopWatchdog(hrWD, tRest => tRest, nFractionProcessed => nFraction);
//Clear Results and set new results-Number of Blobs
MEMSET(ADR(Results), 0, SIZEOF(Results));
ulint_ref REF= (NumberOfBlobs);
hr := F_VN_GetNumberOfElements(ipContainer := ipContourList, nNumberOfElements := ulint_ref, hrPrev := hr);
IF NumberOfBlobs > 0 THEN
FOR i := 0 TO (NumberOfBlobs - 1) BY 1 DO
hr := F_VN_GetAt_ITcVnContainer(ipSrcContainer := ipContourList,
ipDestContainer := ipResultContainer,
nIndex := i,
hrPrev := hr);
hr := F_VN_ContourArea(ipContour := ipResultContainer, fArea := Results[i + 1].Area, hrPrev := hr);
hr := F_VN_ContourCenterOfMass(ipContour := ipResultContainer, aCenterOfMass := Results[i+1].CenterOfMass, hrPrev := hr);
//More items
hr := F_VN_ContourCircularity(ipContour := ipResultContainer, fCircularity := Results[i + 1].Circularity, hrPrev := hr);
hr := F_VN_ContourConvexity(ipContour := ipResultContainer, fConvexity := Results[i + 1].Convexity, hrPrev := hr);
hr := F_VN_ContourEccentricity(ipContour := ipResultContainer, fEccentricity := Results[i + 1].Eccentricity, hrPrev := hr);
hr := F_VN_ContourInertiaRatio(ipContour := ipResultContainer, fInertiaRatio := Results[i + 1].InertiaRatio, hrPrev := hr);
hr := F_VN_ContourOrientation(ipContour := ipResultContainer, stOrientation := Results[i+1].Orientation, hrPrev := hr);
hr := F_VN_ContourPerimeter(ipContour := ipResultContainer,
fPerimeter := Results[i + 1].Perimeter,
bClosed := TRUE,
hrPrev := hr);
hr := F_VN_ContourRoundness(ipContour := ipResultContainer, fRoundness := Results[i + 1].Roundness, hrPrev := hr);
END_FOR
END_IF
(* Draw Result Image
// --------------------------------------------------------------*)
hr := F_VN_DrawContours(ipContourList,
-1,
ipImageRes,
GVL_VisionColor.ColorGreen,
3,
hr);
IF NumberOfBlobs > 0 THEN
FOR i := 0 TO (NumberOfBlobs - 1) DO
hr := F_VN_GetAt_ITcVnContainer(ipSrcContainer := ipContourList,
ipDestContainer := ipResultContainer,
nIndex := i,
hrPrev := hr);
//hr := F_VN_UprightBoundingRectangle(ipResultContainer, Rect, hr);
Text := TO_STRING(i + 1);
hr := F_VN_PutText(Text,
ipImageRes,
TO_UDINT(Results[i + 1].CenterOfMass[0]) - 20,
TO_UDINT(Results[i + 1].CenterOfMass[1]) + 20,
TCVN_FT_HERSHEY_DUPLEX,
2,
GVL_VisionColor.ColorMagenta,
hr);
END_FOR
END_IF
// Display Input Image
hr := F_VN_TransformIntoDisplayableImage(ipImageIn, ipImageInDisp, hr);
// Display Result Image
hr := F_VN_TransformIntoDisplayableImage(ipImageRes, ipImageResDisp, hr);
// Display Threshold Image
hr := F_VN_TransformIntoDisplayableImage(ipImageWork, ipImageThresholdDisp, hr);