C# inheritance, abstraction, interface, generic constraints, extension methods

Article directory Preface Simulation requirements Scenario simulation Highly repetitive needs Initial class structure Inheritance optimization abstract class Requirement 1: Print CreateTime Method 1: Use overloading Method 2: Base class function Method 3: Generic constraints Method 3.1: Ordinary generic methods Method 3.2: Advanced generic constraints, extension methods Summarize Extra: Generic methods and interfaces Generic constraint abstract […]

Matlab implementation: image edge extraction

1. Edge extraction algorithm Method 1: First-order differential operator Sobel operator The Sobel operator detection method has a better processing effect on images with grayscale gradients and more noise. The Sobel operator is not very accurate in edge positioning, and the edge of the image is more than one pixel. Roberts operator The Roberts operator […]

vins-mono front end (1) – image optical flow tracking

Table of Contents Preface feature_tracker_node detailed explanation Preparation img_callback() detailed explanation Foreword The vins front-end mainly includes two parts: image optical flow tracking and imu pre-integration. Optical flow tracking is mainly used to track the same map point information of two adjacent frames of images, so that the back-end can solve the pose transformation between […]

Android implements addition and subtraction custom controls

About the author: Xiaobei Programming (focusing on HarmonyOS, Android, Java, Web, TCP/IP and other technical directions) Blog homepage: Open Source China, Rare Earth Nuggets, 51cto Blog, Blog Park, Zhihu, Jianshu, MOOC, CSDN If the article is helpful to you, please follow, like, collect, and comment. If you need to reprint, please refer to [Reprint Instructions] […]

[Fault Diagnosis Analysis] Rolling bearing fault diagnosis feature extraction with Matlab code

?About the author: A Matlab simulation developer who loves scientific research. He cultivates his mind and improves his technology simultaneously. For code acquisition, paper reproduction and scientific research simulation cooperation, please send a private message. Personal homepage: Matlab Research Studio Personal credo: Investigate things to gain knowledge. For more complete Matlab code and simulation customization […]

[Record] PDF|Chinese and English PDF scanned version directory extraction (1, QQ+GPT)

need: 1) Quickly extract table of contents from PDF; 2) Don’t want to download any software. Article directory 1. Directly export the directory using existing commonly used software 1 (recommendation index☆) QQ OCR text recognition 2 (recommendation index 0 stars) GPT4 image recognition 3 (recommended index 0 stars) GPT4 AI PDF plug-in 4 (recommended index […]

This article teaches you how to use SpireCV for pod control and target detection and tracking.

Function Overview SpireCV-SDK is an edge real-time sensing SDK library specially built for intelligent unmanned systems. It can realize pod control functions and control the drone’s camera and pod, including taking pictures, recording, streaming and other functions, and can save videos. and push streaming, as well as complete target detection, identification and tracking functions. This […]

Target detection (2) Feature extraction of traditional target detection and recognition – Viola Jones detection principle based on Haar-like features

TableofContents Introduction integralplot Trainoptimalweakclassifier Trainastrongclassifier strongclassifier Cascadeclassifier Introduction TheViolaJonesdetectorconsistsofthreecoresteps,namelyHaar-likefeatureandintegralmap,Adaboostclassifierandcascadeclassifier.Supposethatduringtargetdetection,suchasub-windowisneededtocontinuouslyslideandmoveintheimagetobedetected.Everytimethesub-windowreachesaposition,thecharacteristicsoftheareawillbecalculated,andthenthetrainedcascadeclassifierwillbeusedtoFeaturesarefiltered,andaslongasthefeaturepassesthescreeningofallstrongclassifiers,theareaisdeterminedtobethetargetarea. AsshowninFigure9.3,thereare5differentHaar-likefeatureoperators.Assumethatthetotalgrayvalueoftheblackareaineachpictureis?,andthetotalgrayvalueofthewhiteareais.Theresultobtainedis:Haar-likeeigenvaluesofthesub-windowarea. Figure9.3haarfeatures Therectangularfeaturecanbelocatedatanypositionintheimagewindow,anditssizecanalsobechangedatwill.Therefore,therectangularfeaturevalueisdeterminedbythethreefactorsofhaarfeatureoperatorcategory,rectangularpositionandrectangularsize.Therefore,changesincategory,size,andposition,sothatsmallerpictureswillalsocontainmanyrectangularfeatures. Takinga24×24windowasanexample,fivedifferentHaar-likefeatureoperatorsareusedforcalculationinFigure9.3.ThenumberofeigenvaluesofthefiveHaar-likefeatureoperatorsare:43200,43200,27600,27600,20736,atotalof160381.Theimagewindowof24×24sizealonehasmorethan160,000featurevalues.Now,wearefacedwithtwoproblems: Facedwithsomanyeigenvalues,howtooptimizecalculationsandreducetheamountofcalculations? Therearetoomanyeigenvalues.Theremustbesomeeigenvaluesthatarebetteratidentifyingpositivesamplesandnegativesamples,andsomethatarenotgoodatdistinguishingpositivesamplesfromnegativesamples.Sample.Sohowtofindthesegood,excellentfeatures,thatis,theoptimalweakclassifier. IntegralChart First,tosolvethefirstproblem,youneedtousetheintegralmap.Foragrayscaleimage,thevalueofanypointintheintegralmapisthegrayscaleofallpointsintherectangularareaformedbythispointfromtheupperleftcorneroftheoriginalimage.Thesumofthevalues,asshowninFigure9.4:theleftpictureistheoriginalimage,therightpictureistheintegralimage,the3rdrowand4thcolumnintheintegralimagearethepixelsumoftheyellowboxareaintheoriginalimage,the5thintheintegralimageThesecondcolumnoftherowisthepixelsumofthepurpleboxareaintheoriginalimage. Figure9.4Integralplot TheformulashowninFigure9.4canconstructanintegralgraph,butgenerallythefollowingformulaisusedtoconstructanintegralgraph: representsthecumulativesumofthepixelvaluesofthefirstjrowoftheimagei,initialized Userepresentsanintegralimage,initialized Scantheimagelinebylineandcalculatetheaccumulationofeachpixelii,jand,thecalculationmethodsareasfollows: Scantheimageonce.Whenthepixelinthelowerrightcorneroftheimageisreached,theintegralmapii(i,j)iscompleted.Howtocalculatethesumofpixelsinacertainrectangularareaoftheimagethroughtheintegralmap? AsshowninFigure9.5:Intheoriginalimage,therearefourareasA,B,C,andD,wherea,b,c,anddrepresentthefourverticesoftheDarea.HowtocalculatetheintegraldiagramofareaD? Figure9.5Imagearea Use,,,representa,binFigure9.5,respectively.Theintegralvaluesofthefourpointscandd.Usethefollowingequation9.3tocalculatethetotalgrayvalueofthepixelsinareaD: Accordingtotheabovetheory,itcanbefoundthataftertheintroductionofintegralmaptechnology,theHaar-likerectangularfeaturevalueofanimageisonlyaffectedbythevalueofitscorrespondingintegralmap,andthechangeofthecoordinatesoftheimage’spositionhasnocorrelationwithitsvalue.Inthisway,thetimetakentocalculatefeaturevaluescanbeshortenedwhencalculatingrectangularfeatures. Traintheoptimalweakclassifier Nowlet’ssolvethesecondproblem.Therearetoomanyfeatures,soweneedtoscreenthefeaturesandselecttheoptimalweakclassifier.TheinitialweakclassifiermaybejustabasicHaar-likefeature.ItcalculatestheHaar-likefeaturevalueoftheinputimageandcomparesitwiththefeaturevalueoftheinitialweakclassifiertodeterminewhethertheinputimageisaface.However,thisweakclassifierItistoocrudeandmaynotbebetterthanrandomjudgment.Theincubationofweakclassifiersistotrainweakclassifierstobetheoptimalclassifier.Notethattheoptimalclassifierisnotastrongclassifier,butaweakclassifierwitharelativelylowerror.,trainingaweakclassifierisactuallytheprocessofsettinguptheclassifier.Asforhowtosetuptheclassifierandwhattoset,let’sfirstlookatthemathematicalstructureoftheweakclassifierasshowninEquation9.4: Theparameterxisthecharacteristicwindow,prepresentsthedifferentdirectionsoftheinequality,withvaluesof1and-1,andgistherectangularwindow.ThecorrespondingHaar-likefeaturevalue,θ,isthejudgmentthresholdoftheweakclassifier. ThemostbasicweakclassifieronlycontainsoneHaar-likefeature,whichmeansthatthedecisiontreehasonlyonelayer,calledastump.Tocomparethefeaturevaluesoftheinputimageandtheweakclassifierfeatures,athresholdisneeded.Whenthefeaturevalueoftheinputimageisgreaterthanthethreshold,itisdeterminedtobeaface.Theprocessoftrainingtheoptimalweakclassifierisactuallytofindasuitableclassifierthresholdsothattheclassifierhasthelowestjudgmenterrorforallsamples.Thespecificoperationprocessisasfollows: Findtheoptimalthresholdthatminimizestheclassificationerror.Withthisthreshold,thefirstoptimalweakclassifierisborn,ThebirthofthefirstoptimalweakclassifiermeansthatthebestHaar-likefeaturevaluehasbeenscreenedout. Trainstrongclassifier Weakclassificationisonlyaclassifierwithacertainclassificationability,anditsratiocannotmeetthebasicrequirementsforaclassifier,soitneedstobefurtherstrengthenedtobuildastrongclassifierbasedontheweakclassifier.Thespecifictrainingstepsareasfollows: Initializethesampletrainingset Trainingsampleset(x1,y1),…,(xn,yn),whereyi∈0,1,yiisthepositiveandnegativesampleidentifier,1ispositive,otherwiseitisnegative. Initializesampleweightsbasedonthenumberofpositiveandnegativesamples Theinitialweightofthepositivesampleis,theinitialweightofthenegativesampleis,wherem,listhetotalnumberoffacesamplesandthetotalnumberofnon-facesamples,andthetotalnumberofallsamplesisnem>,andsatisfytheconditionofn=m+l,isusedtorepresenttheweight,wheretreferstothetthalgorithmiteration,jreferstothejthoneinthetrainingsample Iterativetrainingofweakclassifiers StrongClassifier Thefinalstrongclassifierisrecordedas: Amongthem,indicatesthemaximumnumberoftrainingtimes. CascadeClassifier AstrongclassifiercanbeconstructedthroughthetrainingoftheaboveAdaBoostalgorithm,buttheaccuracyofsuchaclassifierstillneedstobeimproved,sothestrongclassifierisnotthefinalstructureoftheclassifier.Inordertomaketheaccuracyanddetectionefficiencyoftheclassifierbetter,youcanUsethecascademethodtocombinestrongclassifiersintoacascadeclassifier. Figure9.6Cascadeclassifier Infact,thepurposeoftrainingacascadeclassifieristomakedetectionmoreaccurate.ThedetectionsystemoftheHaarclassifiertakesanimageinrealityasinput,andthenperformsmulti-regionandmulti-scaledetectionontheimage.Theso-calledmulti-Regionistodividetheimageintomultipleblocksanddetecteachblock. Sincethephotosusedfortrainingareonlysmallimagesofabout20*20,multi-scaledetectionisrequiredforlargefaces.Multi-scaledetectionmechanismsgenerallyhavetwostrategies.Oneisnottochangethesizeofthesearchwindow.However,bycontinuouslyscalingtheimage,thismethodrequiresthecalculationofregionalfeaturevaluesforeachscaledimage,whichisnotefficient. Anothermethodistocontinuouslyinitializethesearchwindowsizetotheimagesizeduringtraining,continuouslyexpandthesearchwindow,andperformsearches,whichsolvesthedisadvantagesofthefirstmethod.Duringtheprocessofareaenlargement,thesamefacewillbedetectedmultipletimes,whichrequiresthemergingofareas.Nomatterwhichsearchmethodisused,alargenumberofsub-windowswillbeoutputfortheinputimage.Thesesub-windowswillbecontinuouslyfiltered,discardedorpassedbythefirstnodethroughthefilteringcascadeclassifier,asshowninFigure9.6. UsetheViolaJonesclassifierprovidedbyopencvtodetectfacesandeyes.Theimplementationcodeisasfollows: importcv2 #Loadclassifier eye_cascade=cv2.CascadeClassifier(cv2.data.haarcascades,’haarcascade_eye.xml’) img=cv2.imread(‘image/lenna.bmp’)#Loaddetectionimages gray=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) #Performtargetdetectiononimagesthroughtheclassifier […]