#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_UseX64=y #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** ;https://docs.opencv.org/4.5.1/dd/d49/tutorial_py_contour_features.html ;https://docs.opencv.org/4.5.3/d9/d61/tutorial_py_morphological_ops.html Opt("MustDeclareVars", 1) #include #include #include #include #include #include #include #include #include #include #include #include #include "emgucv-autoit-bindings\cve_extra.au3" ;#include _GDIPlus_Startup() _OpenCV_DLLOpen(_OpenCV_FindDLL()) ;For CVE error message Local $hHandle = DllCallbackRegister("onError", "none", "int;ptr;ptr;ptr;int;ptr") _cveRedirectError(DllCallbackGetPtr($hHandle), Null, Null) Global $gray, $Gaus, $sSource = "", $sObject, $img, $CurrentArea Global $ErosionNumber = 0, $DilationNumber = 0, $OpeningNumber = 0, $ClosingNumber = 0, $GradientNumber = 0 #Region GUI Local $FormGUI = GUICreate("Draw contour", 1060, 600, 200, 90) Local $InputSource = GUICtrlCreateInput("", 120, 16, 450, 21) Local $BtnSource = GUICtrlCreateButton("Source", 580, 14, 75, 25) Local $BtnExec = GUICtrlCreateButton("Execute", 750, 14, 75, 25) Local $LabelThreshold = GUICtrlCreateLabel("Threshold: 180", 120, 70, 110, 20) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") Local $SliderThreshold = GUICtrlCreateSlider(240, 70, 334, 45) GUICtrlSetLimit(-1, 255, 0) ; change min/max value GUICtrlSetData($SliderThreshold, 180) ; set cursor _GUICtrlSlider_SetTicFreq($SliderThreshold, 1) Local $Invert = GUICtrlCreateCheckbox("Invert Gaussian Blur (the object must be white)", 580, 70, 250, 21) GUICtrlCreateLabel("Do not show areas with square less than:", 120, 115, 290, 25) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") Local $MinArea = GUICtrlCreateInput("1000", 415, 115, 50, 21) Local $LabelSource = GUICtrlCreateLabel("Source image and Contour", 130, 150, 200, 20) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") Local $GroupSource = GUICtrlCreateGroup("", 20, 170, 400, 410) Local $PicSource = GUICtrlCreatePic("", 25, 185, 380, 380) GUICtrlCreateGroup("", -99, -99, 1, 1) Local $LabelMatchTemplate = GUICtrlCreateLabel("Gaussian Blur", 580, 150, 100, 20) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") Local $GroupMatchTemplate = GUICtrlCreateGroup("", 455, 170, 400, 410) Local $PicMatchTemplate = GUICtrlCreatePic("", 460, 185, 380, 380) GUICtrlCreateGroup("", -99, -99, 1, 1) Local $Concave = GUICtrlCreateCheckbox("", 880, 15, 20, 21) GUICtrlCreateLabel("View Concave contour", 900, 18, 140, 21) GUICtrlSetColor(-1, 0x358856) ; Green Local $ConcaveCenter = GUICtrlCreateCheckbox("", 880, 45, 20, 21) GUICtrlSetState($ConcaveCenter, $GUI_DISABLE) GUICtrlCreateLabel("Draw Concave center", 900, 48, 140, 21) GUICtrlSetColor(-1, 0x358856) ; Green Local $Convex = GUICtrlCreateCheckbox("", 880, 75, 20, 21) GUICtrlCreateLabel("View Convex contour", 900, 78, 140, 21) GUICtrlSetColor(-1, 0xFF0000) ; Red Local $ConvexCenter = GUICtrlCreateCheckbox("", 880, 105, 20, 21) GUICtrlSetState($ConvexCenter, $GUI_DISABLE) GUICtrlCreateLabel("Draw Convex center", 900, 108, 140, 21) GUICtrlSetColor(-1, 0xFF0000) ; Red Local $BoundingRectangle = GUICtrlCreateCheckbox("", 880, 135, 20, 21) GUICtrlCreateLabel("Straight Bounding Rectangle", 900, 138, 140, 21) GUICtrlSetColor(-1, 0x0000FF) ; Blue Local $RotatedRectangle = GUICtrlCreateCheckbox("", 880, 165, 20, 21) GUICtrlCreateLabel("Rotated Rectangle", 900, 168, 140, 21) GUICtrlSetColor(-1, 0xFFA701) ; Yellow Local $EnclosingCircle = GUICtrlCreateCheckbox("", 880, 195, 20, 21) GUICtrlCreateLabel("Minimum Enclosing Circle", 900, 198, 140, 21) GUICtrlSetColor(-1, 0xbf3eff) ; Purple Local $FittingEllipse = GUICtrlCreateCheckbox("", 880, 225, 20, 21) GUICtrlCreateLabel("Fitting an Ellipse", 900, 228, 140, 21) GUICtrlSetColor(-1, 0xff00c0) ; Pink Local $Erosion = GUICtrlCreateButton("Reduce Line Thickness (Erosion)", 870, 300, 180, 25) Local $Dilation = GUICtrlCreateButton("Increase Line Thickness (Dilation)", 870, 330, 180, 25) Local $Opening = GUICtrlCreateButton("Removing noise (Opening)", 870, 360, 180, 25) Local $Closing = GUICtrlCreateButton("Closing small holes inside (Closing)", 870, 390, 180, 25) Local $Gradient = GUICtrlCreateButton("Outline of the object (Gradient)", 870, 420, 180, 25) Local $SaveImg = GUICtrlCreateButton("Save image", 910, 500, 100, 25) #EndRegion GUI GUISetState(@SW_SHOW) Local $nMsg While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE _Clean() Exit Case $BtnSource $sObject = FileOpenDialog("Select an image", @ScriptDir, "Image files (*.bmp;*.jpg;*.jpeg;*.png;*.gif;*.webp)", $FD_FILEMUSTEXIST, $sObject) If @error Then $sObject = "" Else $ErosionNumber = 0 $DilationNumber = 0 ControlSetText($FormGUI, "", $InputSource, $sObject) _ReadImg() EndIf Case $SliderThreshold $ErosionNumber = 0 $DilationNumber = 0 Local $current_threshold = GUICtrlRead($SliderThreshold) GUICtrlSetData($LabelThreshold, "Threshold: " & $current_threshold) _Clean() _ReadImg() Case $BtnExec If FileExists(GUICtrlRead($InputSource)) <> 1 Then MsgBox(0, "Warning", "Not found image") Else _Clean() _ReadImg() _Contour() EndIf Case $Invert If $sObject <> "" Then $ErosionNumber = 0 $DilationNumber = 0 _Clean() _ReadImg() EndIf Case $Concave If GUICtrlRead($Concave) = $GUI_CHECKED Then GUICtrlSetState($ConcaveCenter, $GUI_ENABLE) Else GUICtrlSetState($ConcaveCenter, $GUI_DISABLE) GUICtrlSetState($ConcaveCenter, $GUI_UNCHECKED) EndIf Case $Convex If GUICtrlRead($Convex) = $GUI_CHECKED Then GUICtrlSetState($ConvexCenter, $GUI_ENABLE) Else GUICtrlSetState($ConvexCenter, $GUI_DISABLE) GUICtrlSetState($ConvexCenter, $GUI_UNCHECKED) EndIf Case $Erosion If $sObject <> "" Then $ErosionNumber += 1 _Erosion() EndIf Case $Dilation If $sObject <> "" Then $DilationNumber += 1 _Dilation() EndIf Case $Opening If $sObject <> "" Then $OpeningNumber += 1 _Opening() EndIf Case $Closing If $sObject <> "" Then $ClosingNumber += 1 _Closing() EndIf Case $Gradient If $sObject <> "" Then $GradientNumber += 1 _Gradient() EndIf Case $SaveImg _SaveImg() EndSwitch WEnd _Clean() _Opencv_DLLClose() _GDIPlus_Shutdown() Func _SaveImg() ;save to file _cveImwriteMat(@ScriptDir & "\Result.png", $img) EndFunc Func _Clean() If $sSource == "" Then Return _cveMatRelease($img) $sSource = "" _cveMatRelease($gray) _cveMatRelease($Gaus) EndFunc ;==>Clean Func _ViewThreshold() $Gaus = _cveMatCreate() _cveGaussianBlurMat($img, $Gaus, _cvSize(5, 5), 0, 0) $gray = _cveMatCreate() _cveCvtColorMat($Gaus, $gray, $CV_COLOR_BGR2GRAY) Local $threshold = GUICtrlRead($SliderThreshold) If GUICtrlRead($Invert) = $GUI_CHECKED Then _cveThresholdMat($gray, $gray, $threshold, 255, $CV_THRESH_BINARY_INV) Else _cveThresholdMat($gray, $gray, $threshold, 255, $CV_THRESH_BINARY) EndIf _cveImshowControlPic($gray, $FormGUI, $PicMatchTemplate) EndFunc ;==>_ViewThreshold Func _ReadImg() $sSource = ControlGetText($FormGUI, "", $InputSource) $img = _cveImreadAndCheck($sSource, $CV_IMREAD_COLOR) If @error Then $sSource = "" Return EndIf _cveImshowControlPic($img, $FormGUI, $PicSource) _ViewThreshold() EndFunc ;==>_ReadImg Func _Erosion() Local $kernel = _cveMatCreate() ;Func _cveErodeTyped($typeOfSrc, $src, $typeOfDst, $dst, $typeOfKernel, $kernel, $anchor = _cvPoint(-1,-1), $iterations = 1, $borderType = $CV_BORDER_CONSTANT, $borderValue = _cveMorphologyDefaultBorderValue()) _cveErodeTyped("Mat", $gray, "Mat", $gray, "Mat", $kernel) _cveImshowControlPic($gray, $FormGUI, $PicMatchTemplate) EndFunc Func _Dilation() Local $kernel2 = _cveMatCreate() ;Func _cveDilateTyped($typeOfSrc, $src, $typeOfDst, $dst, $typeOfKernel, $kernel, $anchor = _cvPoint(-1,-1), $iterations = 1, $borderType = $CV_BORDER_CONSTANT, $borderValue = _cveMorphologyDefaultBorderValue()) _cveDilateTyped("Mat", $gray, "Mat", $gray, "Mat", $kernel2) _cveImshowControlPic($gray, $FormGUI, $PicMatchTemplate) EndFunc Func _Opening() Local $kernel3 = _cveMatCreate() ;Func _cveMorphologyExTyped($typeOfSrc, $src, $typeOfDst, $dst, $op, $typeOfKernel, $kernel, $anchor = _cvPoint(-1,-1), $iterations = 1, $borderType = $CV_BORDER_CONSTANT, $borderValue = _cveMorphologyDefaultBorderValue()) _cveMorphologyExTyped("Mat", $gray, "Mat", $gray, $CV_MORPH_OPEN, "Mat", $kernel3) _cveImshowControlPic($gray, $FormGUI, $PicMatchTemplate) EndFunc Func _Closing() Local $kernel4 = _cveMatCreate() ;Func _cveMorphologyExTyped($typeOfSrc, $src, $typeOfDst, $dst, $op, $typeOfKernel, $kernel, $anchor = _cvPoint(-1,-1), $iterations = 1, $borderType = $CV_BORDER_CONSTANT, $borderValue = _cveMorphologyDefaultBorderValue()) _cveMorphologyExTyped("Mat", $gray, "Mat", $gray, $CV_MORPH_CLOSE, "Mat", $kernel4) _cveImshowControlPic($gray, $FormGUI, $PicMatchTemplate) EndFunc Func _Gradient() Local $kernel5 = _cveMatCreate() ;Func _cveMorphologyExTyped($typeOfSrc, $src, $typeOfDst, $dst, $op, $typeOfKernel, $kernel, $anchor = _cvPoint(-1,-1), $iterations = 1, $borderType = $CV_BORDER_CONSTANT, $borderValue = _cveMorphologyDefaultBorderValue()) _cveMorphologyExTyped("Mat", $gray, "Mat", $gray, $CV_MORPH_GRADIENT, "Mat", $kernel5) _cveImshowControlPic($gray, $FormGUI, $PicMatchTemplate) EndFunc Func _Contour() If $ErosionNumber > 0 Then Local $kernel = _cveMatCreate() ;Func _cveErodeTyped($typeOfSrc, $src, $typeOfDst, $dst, $typeOfKernel, $kernel, $anchor = _cvPoint(-1,-1), $iterations = 1, $borderType = $CV_BORDER_CONSTANT, $borderValue = _cveMorphologyDefaultBorderValue()) _cveErodeTyped("Mat", $gray, "Mat", $gray, "Mat", $kernel, _cvPoint(-1,-1), $ErosionNumber) _cveImshowControlPic($gray, $FormGUI, $PicMatchTemplate) EndIf If $DilationNumber > 0 Then Local $kernel2 = _cveMatCreate() ;Func _cveErodeTyped($typeOfSrc, $src, $typeOfDst, $dst, $typeOfKernel, $kernel, $anchor = _cvPoint(-1,-1), $iterations = 1, $borderType = $CV_BORDER_CONSTANT, $borderValue = _cveMorphologyDefaultBorderValue()) _cveDilateTyped("Mat", $gray, "Mat", $gray, "Mat", $kernel2, _cvPoint(-1,-1), $DilationNumber) _cveImshowControlPic($gray, $FormGUI, $PicMatchTemplate) EndIf If $OpeningNumber > 0 Then Local $kernel3 = _cveMatCreate() ;Func _cveMorphologyExTyped($typeOfSrc, $src, $typeOfDst, $dst, $op, $typeOfKernel, $kernel, $anchor = _cvPoint(-1,-1), $iterations = 1, $borderType = $CV_BORDER_CONSTANT, $borderValue = _cveMorphologyDefaultBorderValue()) _cveMorphologyExTyped("Mat", $gray, "Mat", $gray, $CV_MORPH_OPEN, "Mat", $kernel3) _cveImshowControlPic($gray, $FormGUI, $PicMatchTemplate) EndIf If $ClosingNumber > 0 Then Local $kernel4 = _cveMatCreate() ;Func _cveMorphologyExTyped($typeOfSrc, $src, $typeOfDst, $dst, $op, $typeOfKernel, $kernel, $anchor = _cvPoint(-1,-1), $iterations = 1, $borderType = $CV_BORDER_CONSTANT, $borderValue = _cveMorphologyDefaultBorderValue()) _cveMorphologyExTyped("Mat", $gray, "Mat", $gray, $CV_MORPH_CLOSE, "Mat", $kernel4) _cveImshowControlPic($gray, $FormGUI, $PicMatchTemplate) EndIf If $GradientNumber > 0 Then Local $kernel5 = _cveMatCreate() ;Func _cveMorphologyExTyped($typeOfSrc, $src, $typeOfDst, $dst, $op, $typeOfKernel, $kernel, $anchor = _cvPoint(-1,-1), $iterations = 1, $borderType = $CV_BORDER_CONSTANT, $borderValue = _cveMorphologyDefaultBorderValue()) _cveMorphologyExTyped("Mat", $gray, "Mat", $gray, $CV_MORPH_GRADIENT, "Mat", $kernel5) _cveImshowControlPic($gray, $FormGUI, $PicMatchTemplate) EndIf $CurrentArea = GUICtrlRead($MinArea) If $CurrentArea = "" Then $CurrentArea = 1000 ; Find contours Local $contours = _VectorOfVectorOfPointCreate() Local $good_contours = _VectorOfVectorOfPointCreate() Local $hierarchy = _cveMatCreate() ;Func _cveFindContoursTyped($typeOfImage, $image, $typeOfContours, $contours, $typeOfHierarchy, $hierarchy, $mode, $method, _cveFindContoursTyped("Mat", $gray, "VectorOfVectorOfPoint", $contours, "Mat", $hierarchy, $CV_RETR_EXTERNAL, $CV_CHAIN_APPROX_SIMPLE) ; $CV_RETR_LIST, $CV_RETR_EXTERNAL, $CV_RETR_TREE Local $cnts = _VectorOfVectorOfPointGetSize($contours) ConsoleWrite("Found " & $cnts & " contours" & @CRLF & @CRLF) Local $tVectorPointPtr = DllStructCreate("ptr value") For $i = 0 To _VectorOfVectorOfPointGetSize($contours) - 1 _VectorOfVectorOfPointGetItemPtr($contours, $i, $tVectorPointPtr) Local $Area = _cveContourAreaTyped("VectorOfPoint", $tVectorPointPtr.value) If $Area < $CurrentArea Then ContinueLoop Else _VectorOfVectorOfPointPush($good_contours, $tVectorPointPtr.value) EndIf Next Local $cnts2 = _VectorOfVectorOfPointGetSize($good_contours) ConsoleWrite("Found " & $cnts2 & " good_contours" & @CRLF & @CRLF) ; Concave draw If GUICtrlRead($Concave) = $GUI_CHECKED Then Local $moments2 = _cveMomentsCreate() Local $tVectorPointPtr2 = DllStructCreate("ptr value") For $i = 0 To _VectorOfVectorOfPointGetSize($good_contours) - 1 _VectorOfVectorOfPointGetItemPtr($good_contours, $i, $tVectorPointPtr2) ;Func _cveDrawContoursTyped($typeOfImage, $image, $typeOfContours, $contours, $contourIdx, $color _cveDrawContoursTyped("Mat", $img, "VectorOfVectorOfPoint", $good_contours, $i, _cvRGB(0, 255, 0), 3) ; -1 for all contours If GUICtrlRead($ConcaveCenter) = $GUI_CHECKED Then ;Draw circle in center of Concave ;Func _cveMomentsTyped($typeOfArr, $arr, $binaryImage, $moments) _cveMomentsTyped("VectorOfPoint", $tVectorPointPtr2.value, False, $moments2) Local $cx1 = _cveMomentsGetM10($moments2) / _cveMomentsGetM00($moments2) Local $cy1 = _cveMomentsGetM01($moments2) / _cveMomentsGetM00($moments2) _cveCircleMat($img, _cvPoint($cx1, $cy1), 15, _cvScalar(0, 255, 0), $CV_FILLED) EndIf Next EndIf ; Convex draw If GUICtrlRead($Convex) = $GUI_CHECKED Then ;Find and draw Convex contour Local $hull = _VectorOfVectorOfPointCreate() Local $hull_i = _VectorOfPointCreate() Local $tVectorPointPtr = DllStructCreate("ptr value") Local $moments = _cveMomentsCreate() For $i = 0 To _VectorOfVectorOfPointGetSize($good_contours) - 1 _VectorOfVectorOfPointGetItemPtr($good_contours, $i, $tVectorPointPtr) ;_cveConvexHullTyped($typeOfPoints, $points, $typeOfHull, $hull, $clockwise = false, $returnPoints = true) _cveConvexHullTyped("VectorOfPoint", $tVectorPointPtr.value, "VectorOfPoint", $hull_i) _VectorOfVectorOfPointPush($hull, $hull_i) If GUICtrlRead($ConvexCenter) = $GUI_CHECKED Then ;Draw circle in center of Convex ;Func _cveMomentsTyped($typeOfArr, $arr, $binaryImage, $moments) _cveMomentsTyped("VectorOfPoint", $hull_i, False, $moments) Local $cx = _cveMomentsGetM10($moments) / _cveMomentsGetM00($moments) Local $cy = _cveMomentsGetM01($moments) / _cveMomentsGetM00($moments) _cveCircleMat($img, _cvPoint($cx, $cy), 10, _cvScalar(0, 0, 255), $CV_FILLED) EndIf Next ;Func _cveDrawContoursTyped($typeOfImage, $image, $typeOfContours, $contours, $contourIdx, $color, ... _cveDrawContoursTyped("Mat", $img, "VectorOfVectorOfPoint", $hull, -1, _cvRGB(255, 0, 0), 3) EndIf If GUICtrlRead($BoundingRectangle) = $GUI_CHECKED Then Local $x = 0, $y = 0, $w = 0, $h = 0 Local $boundingRect = _cvRect() Local $tVectorPointPtr3 = DllStructCreate("ptr value") For $i = 0 To _VectorOfVectorOfPointGetSize($good_contours) - 1 _VectorOfVectorOfPointGetItemPtr($good_contours, $i, $tVectorPointPtr3) Local $contour = _cveInputArrayFromVectorOfPoint($tVectorPointPtr3.value) _cveBoundingRectangle($contour, $boundingRect) $x = $boundingRect.x $y = $boundingRect.y $w = $boundingRect.width $h = $boundingRect.height Local $tMatchRect = _cvRect($x, $y, $w, $h) _cveRectangleMat($img, $tMatchRect, _cvRGB(0, 0, 255), 3, $CV_LINE_8, 0) Next EndIf If GUICtrlRead($RotatedRectangle) = $GUI_CHECKED Then Local $tVectorPointPtr4 = DllStructCreate("ptr value") Local $countours2 = _VectorOfVectorOfPointCreate() Local $coutour = _VectorOfPointCreate() Local $rect = DllStructCreate($tagCvBox2D) Local $box = _cveMatCreate() For $i = 0 To _VectorOfVectorOfPointGetSize($good_contours) - 1 _VectorOfVectorOfPointGetItemPtr($good_contours, $i, $tVectorPointPtr4) _cveMinAreaRectTyped("VectorOfPoint", $tVectorPointPtr4.value, $rect) _cveBoxPointsTyped($rect, "Mat", $box) _VectorOfPointClear($coutour) For $xi = 0 To 3 Local $x = _cveMatGetAt("float", $box, _cvPoint(0, $xi)) Local $y = _cveMatGetAt("float", $box, _cvPoint(1, $xi)) _VectorOfPointPush($coutour, _cvPoint($x, $y)) Next _VectorOfVectorOfPointClear($countours2) _VectorOfVectorOfPointPush($countours2, $coutour) _cveDrawContoursTyped("Mat", $img, "VectorOfVectorOfPoint", $countours2, 0, _cvRGB(255, 255, 0), 3) Next EndIf If GUICtrlRead($EnclosingCircle) = $GUI_CHECKED Then Local $tVectorPointPtr5 = DllStructCreate("ptr value") For $i = 0 To _VectorOfVectorOfPointGetSize($good_contours) - 1 _VectorOfVectorOfPointGetItemPtr($good_contours, $i, $tVectorPointPtr5) ; CVAPI(void) cveMinEnclosingCircle(cv::_InputArray* points, CvPoint2D32f* center, float* radius); Local $center = _cvPoint2f() ; equivalent of DllStructCreate($tagCvPoint2D32f) Local $radius = DllStructCreate("float value") _cveMinEnclosingCircleTyped("VectorOfPoint", $tVectorPointPtr5.value, $center, $radius) $center = _cvPoint($center.x, $center.y) _cveCircleMat($img, $center, $radius.value, _cvScalar(128,0,128), 2) Next EndIf If GUICtrlRead($FittingEllipse) = $GUI_CHECKED Then Local $Less5 = 0 Local $cvBox2D = DllStructCreate($tagCvBox2D) Local $tVectorPointPtr6 = DllStructCreate("ptr value") For $i = 0 To _VectorOfVectorOfPointGetSize($good_contours) - 1 _VectorOfVectorOfPointGetItemPtr($good_contours, $i, $tVectorPointPtr6) If _VectorOfPointGetSize($tVectorPointPtr6.value) >= 5 Then ; CVAPI(void) cveFitEllipse(cv::_InputArray* points, CvBox2D* box); _cveFitEllipseTyped("VectorOfPoint", $tVectorPointPtr6.value, $cvBox2D) ; CVAPI(void) cveEllipse(cv::_InputOutputArray* img, CvPoint* center, CvSize* axes, double angle, double startAngle, double endAngle, const CvScalar* color, int thickness, int lineType, int shift); _cveEllipseMat($img, _cvPoint($cvBox2D.x, $cvBox2D.y), _cvSize($cvBox2D.width / 2, $cvBox2D.height / 2), $cvBox2D.angle, 0, 360, _cvRGB(255,20,147), 2) Else Local $Less5 = 1 EndIf Next If $Less5 = 1 Then MsgBox(0,"Warning", "Not all ellipse drawn:" & @CRLF & "The ellipse protruding from the frame was not drawn") EndIf ; View result _cveImshowControlPic($img, $FormGUI, $PicSource) ; Free Resourse If IsDeclared("contours") Then _VectorOfVectorOfPointRelease($contours) If IsDeclared("good_contours") Then _VectorOfVectorOfPointRelease($good_contours) If IsDeclared("hull") Then _VectorOfVectorOfPointRelease($hull) ;If IsDeclared("contour") Then _VectorOfPointRelease($contour) ; crached with use BoundingRectangle If IsDeclared("hull_i") Then _VectorOfPointRelease($hull_i) If IsDeclared("kernel") Then _cveMatRelease($kernel) If IsDeclared("kernel2") Then _cveMatRelease($kernel2) If IsDeclared("kernel3") Then _cveMatRelease($kernel3) If IsDeclared("kernel4") Then _cveMatRelease($kernel4) If IsDeclared("kernel5") Then _cveMatRelease($kernel5) If IsDeclared("box") Then _cveMatRelease($box) If IsDeclared("hierarchy") Then _cveMatRelease($hierarchy) If IsDeclared("moments2") Then _cveMomentsRelease($moments2) If IsDeclared("moments") Then _cveMomentsRelease($moments) EndFunc ;==>_Contour ;For CVE error message Func onError($status, $func_name, $err_msg, $file_name, $line, $user_data) Local $errorStr = CStringToString(_cveErrorStr($status)) $func_name = CStringToString($func_name) $err_msg = CStringToString($err_msg) $file_name = CStringToString($file_name) If $func_name == "" Then $func_name = "unknown function" EndIf ConsoleWrite("OpenCV Error: " & $errorStr & " (" & $err_msg & ") in " & $func_name & ", file " & $file_name & ", line " & $line & "" & @CRLF) MsgBox(0,"Error", "OpenCV Error: " & @CRLF & $errorStr & " (" & $err_msg & ") in " & $func_name & @CRLF & "File " & $file_name & ", line " & $line & "" & @CRLF) EndFunc ;For CVE error message Func CStringToString($src) Local $sSrcDllType If IsDllStruct($src) Then $sSrcDllType = "struct*" Else $sSrcDllType = "ptr" EndIf Local $strlen = CVEDllCallResult(DllCall("msvcrt.dll", "int:cdecl", "strlen", $sSrcDllType, $src), "strlen", @error) Local $tStr = DllStructCreate("char value[" & $strlen & "]", $src) return $tStr.value EndFunc ;==>CStringToString