Find Contour - Approximation Method

Dieses Beispiel beschäftigt sich mit den möglichen Annährungsmodi (eApproximationMethod vom Typ ETcVnContourApproximationMethod) bei der Konturensuche.

Erläuterung

Die Funktionen F_VN_FindContours, F_VN_FindContoursExp und F_VN_FindContourByHierarchy dienen zur Detektion von Konturen im Bild. Dabei werden die Konturen durch Punkte beschrieben. Je nach ausgewähltem Annäherungsmodus (eApproximationMethod vom Typ ETcVnContourApproximationMethod) werden alle Punkte je Kontur oder eine vereinfachte Punktmenge zurückgegeben:

Variablen

hr                   :   HRESULT;

ipImageIn            :   ITcVnImage;
ipImageInDisp        :   ITcVnDisplayableImage;

ipImageRes           :   ITcVnImage;
ipImageResDisp       :   ITcVnDisplayableImage;

// Sample Specific Variables
ipContourList        :   ITcVnContainer;
ipContour            :   ITcVnContainer;
ipIterator           :   ITcVnForwardIterator;
eRetrievalMode       :   ETcVnContourRetrievalMode := TCVN_CRM_LIST;
eApproximationMethod : ETcVnContourApproximationMethod := TCVN_CAM_SIMPLE;
aOffset              :   TcVnPoint;

// Colors
aColorRed            :   TcVnVector4_LREAL := [255, 0, 0];

Code

// Create Result Image
hr := F_VN_ConvertColorSpace(ipImageIn, ipImageRes, TCVN_CST_Gray_TO_RGB, hr);

// Find Contours and their Hierarchy
// -----------------------------------
hr := F_VN_FindContoursExp(
                 ipSrcImage             :=   ipImageIn,
                 ipContours             :=   ipContourList,
                 eRetrievalMode         :=   eRetrievalMode,
                 eApproximationMethod   :=   eApproximationMethod,
                 aOffset                :=   aOffset, 
                 hrPrev                 :=   hr);


// Draw the points of the contour
hr := F_VN_GetForwardIterator(ipContourList, ipIterator, hr);

WHILE SUCCEEDED(hr) AND_THEN ipIterator.CheckIfEnd() <> S_OK DO
   hr := F_VN_GetContainer(ipIterator, ipContour, hr);
   hr := F_VN_IncrementIterator(ipIterator, hr);
   hr := F_VN_DrawPoints(ipContour, ipImageRes, ETcVnDrawShape.TCVN_DS_CIRCLE, aColorRed, hr);
END_WHILE

Ergebnisse

Das Eingangsbild

Find Contour - Approximation Method 1:

 

Das Ergebnisbild mit allen eingezeichneten Punkten nach ETcVnContourApproximationMethod.TCVN_CAM_NONE

Find Contour - Approximation Method 2:

 

Das Ergebnisbild mit allen eingezeichneten Punkten nach ETcVnContourApproximationMethod.TCVN_CAM_TC89_L1

Find Contour - Approximation Method 3:

Ähnliche Beispiele