HUSKYLENS - An Easy-to-use AI Machine Vision Sensor

文章推薦指數: 80 %
投票人數:10人

HuskyLens is an easy-to-use AI machine vision sensor with 7 built-in functions: face recognition, object tracking, object recognition, line tracking, ... HOME COMMUNITY FORUM BLOG EDUCATION HOME FORUM BLOG 1.Introduction HuskyLensisaneasy-to-useAImachinevisionsensorwith7built-infunctions:facerecognition,objecttracking,objectrecognition,linetracking,colorrecognition,tagrecognitionandobjectclassification. ThroughtheUART/I2Cport,HuskyLenscanconnecttoArduinoandmicro:bittohelpyoumakeverycreativeprojectswithoutplayingwithcomplexalgorithms. 2.Specification Processor:KendryteK210 ImageSensor: SEN0305HuskyLens:OV2640(2.0MegapixelCamera) SEN0336HuskyLensPRO:OV5640(5.0MegaPixelCamera) SupplyVoltage:3.3~5.0V CurrentConsumption(TYP):[email protected],[email protected](facerecognitionmode;80%backlightbrightness;filllightoff) CommunicationPort:UART;I2C Display:2.0-inchIPSscreenwith320*240resolution Built-inAlgorithms:FaceRecognition,ObjectTracking,ObjectRecognition,LineTracking,ColorRecognition,TagRecognition,ObjectClassification Dimension:52mmx44.5mm(2.05*1.75inch) 3.BoardOverview 3.1Connectors USBConnector:powersupplyforHuskylens;connecttothecomputertoupgradethefirmware 4pinConnectorinUARTMode Num Label PinFunction Description 1 T TX TXpinofHuskyLens 2 R RX RXpinofHuskyLens 3 - GND Negative(0V) 4 + VCC Positive(3.3~5.0V) 4pinConnectorinI2CMode Num Label PinFunction Description 1 T SDA Serialclockline 2 R SCL Serialdataline 3 - GND Negative(0V) 4 + VCC Positive(3.3~5.0V) Tips: YoucanconnecteitherUSBportor4pinporttopowerHuskyLens. Duetotheonboardpowersupplyautomaticswitchingcircuit,theUSBportandthe4pinportcanbeconnectedtothepowersupplyatthesametime,andthepowersupplyontheUSBportisusedfirst. PleaseensurethatthesupplyvoltageandratearesufficienttopreventHuskyLensfromworkingabnormally. 3.2Buttons TherearetwobuttonsontheHuskyLens,thefunctionbuttonandthelearningbutton.Thebasicoperationsofthesetwobuttonsareshownasfollows: Dialthe"functionbutton"toleftorrighttoswitchdifferentfunctions. Shortpressthe"Learningbutton"tolearnthespecifiedobject;longpressthe"Learningbutton"tocontinuouslylearnthespecifiedobjectfromdifferentanglesanddistances;ifHuskyLenshaslearnedtheobjectbefore,shortpressthe"Learnbutton"tomakeitforget. Longpressthe"functionbutton"toenterintothesecond-levelmenu(parametersetting)inthecurrentfunction.Dialleft,rightorshortpressthe"functionbutton"tosetrelatedparameters. 4.UpgradeFirmware Beforeusingthisproduct,itisstronglyrecommendedtoupgradeHuskyLens'firmwaretothelatestversiontogetthelatestfunctionsandthemoststableexperience.IfyourHuskyLensalreadyhasthelatestfirmware,noupdateisrequired.Werecommandtouploadthefirmwareonwindows10usingtheHuskyLensUploadersinceitfeaturesaGUI,andeasy-to-use. ThefirmwareversionrequiredforthistutorialisnotlowerthanV0.5.1a.Thisversionintegratesallfunctions(includingobjectclassification). Howtocheckthefirmwareversion? Dialthefunctionbuttontotherightuntilthelastoption"GeneralSettings",shortpressthefunctionbuttontoenterthesecondarymenu. Dialthefunctionbuttontotherightuntilyoureachthe"version"option,youcanseetheversionnumber.Asshowninthefigurebelow,theversionnumberis:0.5.1Norm. 4.1InWindows Werecommandtouploadthefirmwareonwindows10usingtheHuskyLensUploader.Itiseasyandconvenient.Thestepsareshownbelow: DownloadtheHuskyLensUploader.Clickheretodownloadit. DownloadtheUSBtoUARTdriver,andinstallit.Clickheretodownloadit. HuskyLesnadoptstheCP2102NchiptoimplementtheUSBtoserialportfunction.Afterthedriverisinstalled,youcanusethemicroUSBcabletoconnecttheUSBportofHUSKYLENStothecomputer'sUSBport.Atthistime,openthedevicemanagerandthereshouldbeaCOMportwhosenamestartswith"SiliconLabsCP210x".Asshownbelow: Downloadthelatestfirmware.ClickheretodownloadtheV0.5.1a. Clickheretocheckthefirmwaresofallversions. RuntheHuskyLensUploader,asmallblackcmdwindowwillpopupfirst,andafterawhile,theinterfacewindowwillappear,thenclickthe"SelectFile"buttontoloadthefirmware. Clickthe"Upload"button.Waitabout5minutestocompletetheuploading.Thefirmwarefileislarge,soitmaytakealittlebittime.Aftertheuploadingiscompleted,theprompttext"Uploading"willdisappearandtheHuskyLensscreenwilllightup.Pleasedonotclosetheinterfacewindowandthesmallblackcmdwindowduringuploading. Tips: IfyouarepromptedtoenterHuskylens'COMportManually,youneedtomanuallyentertheHuskyLens'COMportmappedonyourcomputer.TheCOMportnumbercanbefoundinthedevicemanager. IfthefirmwareuploadingfailsortheHuskyLens'screendoesnotlightup,orotherstrangephenomenas,suchasinvalidbuttons,HuskyLenscannotlearn,etc.youcantrytoclickthe"ResetMemory"button.Afterawhile,thetwofilllightsofHUSKYLENSwilllightup,andHuskyLenshasbeenreset.Pleaserefertotheabovestepsandre-uploadthefirmware. 4.2InLinuxorMac Inthissection,wetakeubuntu18.04.4asanexampletoshowyouhowtoupgradeHuskylensfirmwareonLinuxorMac.Thesestepsareshownasfollows: DownloadtheUSBtoUARTdriver,andinstallit.Clickheretodownloadit. HuskyLesnadoptstheCP2102NchiptoimplementtheUSBtoserialportfunction. InUbuntu18.04.4,theUSBserialportofHuskyLenscanbedirectlyidentifiedwhenpluggedin,sothedriverisnotrequiredtobeinstalled. Downloadthelatestfirmwareandkflash.pyscript.Clickheretocheckthem. Youcanclonetheentirerepositoryof"HuskyLens/HUSKYLENSUploader"toyourcomputerbygitcommand. Installpip3firstifyoudonothaveitinyourOS. sudoaptinstallpython3-pip Installpip3onMAC /bin/bash-c"$(curl-fsSLhttps://raw.githubusercontent.com/Homebrew/install/master/install.sh)" brewinstallpython3 Runthefollowingscripttoinstallpyserial. sudopip3installpyserial GototheHUSKYLENSUploaderfolder. cdHUSKYLENSUploader Accordingtotheactualfirmwareversion,enterthefullnameofthefirmwareinthefollowingscript.TakeV0.5.1versionfirmwareasanexample,runthefollowingscripttouploadthefirmware: sudopython3kflash.py-b2000000HUSKYLENSWithModelV0.5.1Norm.kfpkg Waitabout5minutestocompletetheuploading. Upgradehasbeencompletednow.Enjoyit. 5.GeneralSettings 5.1BasicOperation Thebasicoperationisshownasfollows: Selectthegeneralsettings:Dialthefunctionbuttonrightuntilthewords“GeneralSettings”isdisplayedatthetopofthescreen,thenselectit. Enterthegeneralsettingmode:Shortpressthefunctionbuttontoenterit. Selectandadjusttheparameter:Dialthefunctionbuttonleftorrighttoselectdifferentparameter,thenshortpressthefunctionbuttontoentertheparameter.Dialthefunctionbuttonleftorrighttoadjusttheparameter.Thenshortpressthefunctionbuttonagaintoconfirmtheparameter. Savethesettings:Afteradjustingtheparameters,dialthefunctionbuttonlefttoselect"Save&Return",thenshortpressthefunctionbutton.Amessage“Doyousavedata?”willappear.Thedefaultseletionis"Yes".Atthistime,shortpressthefuntionbuttontosaveandexit. Tips: Theparametersinthegeneralsettingsareallselectedandadjustedbydialing"functionbutton"leftorright,andpressingthe"functionbutton". Aftersettingtheparameters,besuretoselect"saveandreturn"tosavethesetparameters. 5.2ParametersIntroduction Thereare10+differentparametersettingsinthegeneralsettings. ProtocolType HuskylenssupportsthreeUARTbaudrates(9600,115200,1000000),andI2Cprotocol.Inaddition,itsupportsauto-detectionoftheprotocols,thatis,HuskylenswillautomaticallyswitchbetweenUARTandI2C.Werecommendtousetheautodetectionprotocol,whichissimpleandconvenient.Thedefaultvalueisauto-detection. ScreenBrightness Thescreensupportsthebrightnessfrom1~100.Thedefaultvalueis80. MenuAuto-hide Whenyoudon'toperatetheHuskylensforaperiodoftime,themenuonthescreenwillautomaticallyhide.Thisdurationtimecanbeadjustedfrom1-100seconds.Thedefaultvalueis10seconds. LEDLight TherearetwoLEDlightsonthefrontoftheHuskylens.YoucansetitONorOFF.ThedefaultvalueisOFF. LEDBrightness ThebrightnessofthesetwoLEDlightsrangesfrom1to100.Thedefaultvalueis50. RGBLight ThereisalsoanRGBlightonthefrontoftheHuskylens.YoucansetitONorOFF.ThedefaultvalueisON. RGBBrightness ThebrightnessrangeofthisRGBlightis1to100.Thedefaultis20. FactoryReset Huskylenscanberesetedtofactorysettingsviathisfunction. Version Thecurrentversionofthebuilt-infirmware. Language HuskylenssupportsChineseandEnglish. 6.ColorandCoordinate 6.1ColorInstructions Ineachfunction,thecolordefinitionsoftheframeandthesymbol"+"inthecenterofthescreenareallthesame,whichhelpsyouknowthecurrentstatusofHuskyLens. Color Status Fromorangetoyellow,thenfromyellowtoorange Havenotlearnedtheobjectyetbutreadytolearn Yellow Learningthenewobject Blue Havelearnedtheobjectandrecognizedit TheRGBLEDindicatorisusedtoindicatethestatusofthefacerecognitionfunction.Itscolorsaredefinedasfollows. Color Status Blue Havenotlearnedthefaceyet,butdetectedtheface Yellow Learningthenewface Green Havelearnedthefaceandrecognizedit 6.2CoordinateSystem WhenHuskyLensisdetectingaobject,thetargetwillbeautomaticallyselectedbyacolorframeonthescreen.Thecoordinatesofthecolorframepositionxandyareassignedaccordingtothefollowingcoordinatesystem.AftergettingthecoordinatesfromtheUART/I2Cport,youcanknowthepositionoftheobject. Format:(x,y) 7.FunctionsIntroduction 7.1FaceRecognition Thisfunctioncandetectanyfacecontour,recognizeandtrackthelearnedface. 7.1.1.Recognizeoneface Thedefaultsettingistolearnandrecognizeasingleface. OperationandSetting Dialthefunctionbuttontotheleftuntiltheword"Facerecognition"isdisplayedatthetopofthescreen. LearningandDetection 1.FaceDetection: PointtheHuskyLensatanyfaces.Whenafaceisdetected,itwillbeautomaticallyselectedbyawhiteframewithwords"Face"onthescreen. Tips: IfyouwantHuskyLenstolearnorrecognizeyourface,thatis,takeaselfie,youcan'tseethescreenatthistime,youcandeterminethestatusaccordingtothedifferentcolorsoftheRGBindicator. 2.FaceLearning:Pointthe“+”symbolataface,shortpressthe"learningbutton"tolearntheface.IfthesamefaceisdetectedbyHuskyLens,ablueframewithwords"Face:ID1"willbedisplayedonthescreen,whichindicatesthatHuskyLenshaslearnedthefaceandcanrecognizeitnow. However,HuskyLensonlylearnedoneplane(one-dimensional)ofthefaceaftertheaboveoperation,whilehumanfaceisthree-dimensional.Iftheangleofthefacehasbeenchanged,HuskyLensmaynotrecognizeit.SoyouneedtoletHuskyLenslearnafacefromitsdifferentangles. Theoperationshowsasfollows:(BeforeHuskyLenslearningnewsthing,pleaseletitforgettheformerthingsfirst.) Keeppressingthe“learningbutton”,pointHuskyLens'"+"symbolatdifferentanglesoftheface.Duringthisprocess,ayellowframewithwords"Face:ID1"willbedisplayedonthescreen,whichindicatesHuskyLensislearningtheface.Pleasepointtheyellowframeatdifferentanglesofthesameperson'sface,suchasfrontfaceandsideface(ormultiplephotosofthesameperson),toenterallanglesofthisperson'sface. Thenyoucanreleasethe"learningbutton"tofinishthelearning.WhenHuskylensdetectedthelearnedface,ablueframewithwords"Face:ID1"willbedisplayed,nowHuskyLenscanrecognizethefacefromdifferentangles. Tips: Ifthereisno“+”symbolinthecenterofthescreen,itmeansthattheHuskyLenshasalreadylearnedthefaceinthecurrentfunction,nowHuskyLensisdetectingit.IfyouwanttoletHuskyLenslearnanewface,youhavetomakeitforgetthelearnedfacefirst. 3.FaceRecognition: Thelearnedfaceinformationwillbeautomaticallysaved.WhenHuskyLensdetectsthelearnedface,thisfacewillbeselectedbyablueframeandidentifiedasface:ID1.Thesizeoftheframewillchangewiththesizeoftheface,andthefacewillbetrackedautomatically. 4.ForgettheLearnedFace: Ifthereisno“+”symbolinthecenterofthescreen,itmeansthattheHuskyLenshasalreadylearnedthefaceinthecurrentfunction.Ifyouwanttorecognizeanotherface,orre-enterfaceinformation,youneedtodeletethecurrentfaceinformation. WhenHuskyLensisinthefacerecognitionmode,shortpressthe"learningbutton",thescreenwilldisplay"clickagaintoforget".Beforethecountdownends,shortpressthe"learningbutton"againtodeletethelearnedfaceinformation,thentheyellow"+"symbolisdisplayed.NowyoucanletHuskyLenslearnanewface. Theoperationofforgettingistotallythesameinotherfunctions.Therefore,thisoperationwillnotberepeatedinsubsequentchapters. 7.1.2.Recognizemultiplefaces Thedefaultsettingistolearnasingleface.Inordertolearnmultiplefaces,weneedtoenable"LearnMultiple"offacerecognition. OperationandSetting Dialthefunctionbuttontotheleftuntiltheword"Facerecognition"isdisplayedatthetopofthescreen. Longpressthefunctionbuttontoentertheparametersettingofthefacerecognitionfunction. Dialthefunctionbuttonuntil"LearnMultiple"isdisplayed,thenshortpressthefunctionbutton,anddialtotherighttoturnonthe"LearnMultiple"switch,thatis,progressbarturnsblueandthesquareiconontheprogressbarmovestotheright.Thenshortpressthefunctionbuttontoconfirmthisparameter. Dialthefunctionbuttontotheleftuntil"Save&Return"shows.Andthescreenprompts"Doyouwanttosavetheparameters?"Select"Yes"indefault,nowshort-pressthefunctionbuttontosavetheparametersandreturnautomatically. LearningandDetection 1.MultipleFacesLearning: Pointthe“+”symbolattheface,longpressthe"learningbutton"tolearnthefaceofthefirstperson.Thenreleasethe"learningbutton",ablueframewithwords"Face:ID1"willbedisplayedifHuskyLensdetectsthesameface,meanwhile,amessage"Clickagaintocontinue!Clickotherbuttontofinish"willbedisplayed.Pleaseshortpressthe"learningbutton"beforethecountdownendsifyouwanttolearnthefaceofotherperson.Ifnot,shortpressthe"functionbutton"beforethecountdownends,ordonotpressanybuttontoletthecountdownends. Inthischapter,wewilllearnthenextfacecontinuously.Soweneedtoshortpressthe"learningbutton"beforethecountdownends.ThenwecanletHuskyLenslearnthefaceofthesecondperson.Thesameasthestepstorecognizethefirstface,pointthe“+”symbolatthesecondface,longpressthe"learningbutton"tolearnthefaceofthesecondperson.Thenreleasethe"learningbutton",ablueframewithwords"Face:ID2"willbedisplayedifHuskyLensdetectsthesameface. ThefaceIDisthesameastheorderofenteringtheface,thatis:thelearnedfaceswillbemarkedas"face:ID1","face:ID2","face:ID3"inorder,anddifferentfaceIDscorrespondtodifferentcolorframes. Tips: Ifthereisno“+”symbolinthecenterofthescreenbeforelearning,itmeansthattheHuskyLenshasalreadylearned,nowHuskyLensisdetectingface.IfyouwanttoletHuskLenslearnnewface,youneedtoletHuskyLensforgetthelearnedfacefirst. Pleaseturntothe7.1.1.Learnonefacetocheckthewaytoforgetthelearnedface. 2.MultipleFacesRecognition: Thelearnedfaceinformationwillbesavedautomatically.WhenHuskyLensdetectsthelearnedfacefrommultiplefaces,thelearnedfacewillbeselectedwithaframeandidentifiedbythemessageface:IDx.Forexample,whenHuskyLensdetectsthelearnedfaceofthefirstperson,itwillbeselectedwithablueframeandidentifyface:ID1;whenHuskyLensdetectsthelearnedfaceofthesecondperson,itwillbeselectedwithayellowframeandidentifyface:ID2;andsoon. ThecoloroftheframecorrespondingtodifferentfaceIDsisalsodifferent,andtheframesizewillchangewiththesizeoftheface,andthefacewillbeautomaticallytracked. 7.2ObjectTracking Thisfunctioncanlearnandtrackaspecifiedobject.Onlyoneobjectcanbetracked,andmultipleobjectsarenotsupported. OperationandSetting Dialthefunctionbuttontotheleftorrightuntiltheword"ObjectTracking"isdisplayedatthetopofthescreen. Longpressthefunctionbuttontoentertheparametersettingoftheobjecttrackingfunction. Dialthefunctionbuttontotherighttoselect"LearnEnable",thenshortpressthefunctionbutton,anddialittotherighttoturnthe"LearnEnable"ON,thatis,thesquareiconontheprogressbaristurnedtotheright.Thenshortpressthefunctionbuttontoconfirmthisparameter. Themethodtoturnontheswitchofsavingmodelsautomaticallyisthesameasbefore.Accordingtothestepsabovetoswitch"AutoSave"ON. Youcanalsoadjustthesizeoftheframebysetting"FrameRatio"and"FrameSize"tomatchtheshapeoftheobject. Dialthefunctionbuttontothelefttoselect"Save&Return",andshortpressthefunctionbuttontosavetheparametersandreturnautomatically. LearningandDetection 1.ObjectLearning: PointHuskylenstothetargetobject,adjustingthedistanceanduntiltheobjectisincludedintheyellowframeofthecenterofthescreen.Thenlongpress"learningbutton"tolearntheobjectfromvariousanglesanddistances.Duringthelearningprocess,theyellowframewithwords"Learning:ID1"willbedisplayedonthescreen. WhenHuskyLenscantracktheobjectatdifferentanglesanddistances,youcanreleasethe"learningbutton"tocompletethelearning. 2.ObjectTracking: MovetheHuskyLensorthetarget,theframewilltrackthetargetautomatically. Whentrackingtheobject,theyellowwords“Learning:ID1”willbedisplayed,indicatingthatHuskyLensistrackingtheobjectwhilelearning.Thissettingimprovestheobjecttrackingability. Whentherecognitionresultmeetstherequirements,youcanturnoff"LearnEnable". Tips: Onlyoneobjectcanbetrackedatatime.Itcanbeanyobjectwithaclearoutline,evenvariousgestures. 7.3ObejctRecognition Thisfunctioncanrecognizewhatitis,andtrackit. HuskyLenscanrecognize20built-inobjects.Theyareaeroplane,bicycle,bird,boat,bottle,bus,car,cat,chair,cow,dining-able,dog,horse,motorbike,person,pottedlant,sheep,sofa,train,TV. Tips: Objectrecognitioncannotdistinguishthedifferencebetweenobjectsofthesametype.Forexample,itcanonlyrecognizethatthisisacat,butitcannotrecognizewhatkindofcatitis.Differentfromfacerecognition,peopleareonetype,butdifferentfacescanbedistinguished. Thedefaultsettingistorecognizeasingleobject.Thischapterusesmarkingandrecognizingmultipleobjectsasanexampletodemonstrate. OperationandSetting Dialthefunctionbuttontotheleftorrightuntiltheword"ObejctRecognition"isdisplayedatthetopofthescreen. Longpressthefunctionbuttontoentertheparametersettingoftheobjectrecognitionfunction. Dialthefunctionbuttonuntil"LearnMultiple"isdisplayed,thenshortpressthefunctionbutton,anddialtotherighttoturnonthe"LearnMultiple"switch,thatis,progressbarturnsblueandthesquareiconontheprogressbarmovestotheright.Thenshortpressthefunctionbuttontoconfirmthisparameter. Dialthefunctionbuttontotheleftuntil"Save&Return"shows.Andthescreenprompts"Doyouwanttosavetheparameters?"Select"Yes"indefault,nowshort-pressthefunctionbuttontosavetheparametersandreturnautomatically. LearningandDetection 1.ObjectDetection: Whendetectingobjects,HuskyLenswillautomaticallyrecognizeit,andtheobjectwillbedisplayedbythewhiteframewithitsnameonthescreen. Atpresent,only20built-inobjectscanberecognized,andtheremainingobjectscannotberecognizedtemporarily. 2.ObjectMark: Pointthe“+”symbolattheobject,thenshortpressthe“learningbutton”,thecoloroftheframechangesfromwhitetoblue,andthenameoftheobjectandit'sID1willappearonthescreen,meanwhile,amessage"Clickagaintocontinue!Clickotherbuttontofinish"willbedisplayed.Pleaseshortpressthe"learningbutton"beforethecountdownendsifyouwanttomarkthenextobject.Ifnot,shortpressthe"functionbutton"beforethecountdownends,ordonotpressanybuttontoletthecountdownends. 3.ObjectRecognition: Whenencounteringthelearnedobjects,theywillbeselectedbythecolorframe,andthenameandIDnumberwillbedisplayed.Whenencounteringnewones,theselectionframeiswhite. TheIDnumberisrelatedtotheorderofmarkingobjects.Forexample,ifadogismarkedforthefirsttimeandacatismarkedforthesecondtime,whenthedogisrecognized,thewords"dog:ID1"willbedisplayedonthescreen;andwhenthecatisrecognized,thewords"cat:ID2"willbedisplayedonthescreen. Thiscanbeusedasasimplefiltertofindoutwhatyouneedfromabunchofobjects. 7.4LineTracking Thisfunctioncantrackspecifiedcolorlinesandmakepathpredictions.Thedefaultsettingistotrackonlyonecolorline. Inthischapter,weusetrackingonecolorlineasanexampletodemonstrate. OperationandSetting Dialthefunctionbuttontotheleftorrightuntiltheword"LineTracking"isdisplayedatthetopofthescreen. Longpressthefunctionbuttontoentertheparametersettingofthelinetrackingfunction. Dialthefunctionbuttonrightorleftuntil"LearnMultiple"isselected,thenshortpressthefunctionbutton,anddialittothelefttoturnoffthe"LearnMultipe"switch,thatis,thesquareiconontheprogressbaristurnedtotheleft.Thenshortpressthefunctionbuttontocompletethisparameter. YoucanalsoturnontheLEDsbysetting"LEDSwitch".Thisisveryusefulinthedarkenvironment. Dialthefunctionbuttontotheleftuntil"Save&Return"isselected,andshortpressthefunctionbuttontosavetheparametersanditwillreturnautomatically. LearningandDetection 1.LineLearning: ItisrecommendedthatwithintheviewfieldofHuskyLens,justremainlinetolearnandnoanycrosslines.Pointthe"+"symbolattheline.ThenHuskyLenswillautomaticallydetectthelineandawhitearrowwillappearonthescreen. Atthattime,shortpressthe"learningbutton"tocompletethelearningprocess.Ablueroutedirectionarrowwillappearonthescreen. 2.LinePrediction: WhenHuskyLensdetectsthelinewhichhasbeenlearned,abluearrowwillappearautomaticallyonthescreen.Thedirectionofthearrowindicatesthepredicteddirectionoftheline. Tips: Whenlearningtheline,weneedtoadjustthepositionofHuskyLenstobeparalleltotheline. Huskylenscanlearnmultiplelinesaccordingtothecoloroflines,buttheselinesmustbemonochromelineswithobviouscolorthatdifferentfromthebackground. Inmostcases,thecoloroftrackinglineisonlyone.Therefore,inordertoensurestability,werecommendtotrackthesinglecolorline. Thecolorofthelineshasalottodowiththeambientlight,sopleasetrytokeeptheambientlightasstableaspossible. 7.5ColorRecognition Thisfunctioncanlearn,recognize,andtrackthespecifiedcolor. Thedefaultsettingistolearn,recognize,andtrackasinglecolor.Thischapteruseslearning,recognizing,andtrackingmultiplecolorsasanexampletodemonstrate. Tips: Colorrecognitionisgreatlyaffectedbyambientlight.SometimesHuskyLensmaymisidentifysimilarcolors.Pleasetrytokeeptheambientlightunchanged. OperationandSetting Dialthefunctionbuttontotherightorleftuntiltheword"ColorRecognition"isdisplayedatthetopofthescreen. Longpressthefunctionbuttontoentertheparametersettingofthecolorrecognitionfunction. Dialthefunctionbuttonuntil"LearnMultiple"isdisplayed,thenshortpressthefunctionbutton,anddialtotherighttoturnonthe"LearnMultiple"switch,thatis,progressbarturnsblueandthesquareiconontheprogressbarmovestotheright.Thenshortpressthefunctionbuttontoconfirmthisparameter. Dialthefunctionbuttontotheleftuntil"Save&Return"shows.Andthescreenprompts"Doyouwanttosavetheparameters?"Select"Yes"indefault,nowshort-pressthefunctionbuttontosavetheparametersandreturnautomatically. LearningandDetection 1.ColorDetection: Pointtheicon"+"inthecenteroftheHuskyLensscreentothetargetcolorblock,andawhiteframewillappearonthescreen,whichselectsthetargetcolorblockautomatically. AdjusttheangleanddistanceoftheHuskyLenstothecolorblocksothatthewhiteframecanincludetheentiretargetcolorblockasfaraspossible. 2.ColorLearning: Pointthe“+”symbolatthefirstcolorblock,andlongpressthe“learningbutton”.Ayellowframewillbedisplayedonthescreen,indicatingthatHuskyLensislearningthecolor.Atthistime,adjustthedistanceandanglebetweenHuskyLensandthecolorblock,toletHuskyLenslearnthecolorblockinvariousdistancesandangles.Then,releasethe"learningbutton"tocompletelearningthefirstcolorblock,meanwhile,amessage"Clickagaintocontinue!Clickotherbuttontofinish"willbedisplayed.Pleaseshortpressthe"learningbutton"beforethecountdownendsifyouwanttolearnothercolorblocks.Ifnot,shortpressthe"functionbutton"beforethecountdownends,ordonotpressanybuttontoletthecountdownends. 3.ColorRecognition: Whenencounteringthesameorsimilarcolorblocks,somecolorframeswithIDswillbeautomaticallydisplayedonthescreen,andthesizeoftheframesaresameasthesizeofthecolorblocks. TheIDnumberisrelatedtotheorderoflearnedcolor.Forexample,ifayellowblockismarkedforthefirsttimeandagreenblockismarkedforthesecondtime,whentheyellowblockisrecognized,thewords"Color:ID1"willbedisplayedonthescreen,andwhenthegreenblockisrecognized,thewords"Color:ID2"willbedisplayedonthescreen. InthefirmwarebelowV0.5.1,whentherearemultiplesameorsimilarcolorblocksappearatthesametime,theothercolorblockscannotbeselected,thatis,onlyonecolorblockcanberecognizedateachtime. InfirmwareversionV0.5.1andabove,thisfunctionisoptimized.whentherearemultiplesameorsimilarcolorblocksappearatthesametime,thesecolorblockscanberecognizedandselectedatthesametime.Thisfunctioncanbeusedtocountthecolorblocks. CountColorblocks InfirmwareV0.5.1andabove,HUSKYLENScancountthecolorblocksinthecolorrecognitionfunction,thatis,calculatethenumberofcolorblocksintheHUSKYLENSscreen.Thefollowingisanexampleofrecognizingmultipleballoonsofsimilarcolors. 1.LearnandRecognizeColors Pointthe"+"symbolatthetargetballoon,thenpressthe"learningbutton"tolearnthecoloroftheballoon,andthenreleasethe"learningbutton"tocompletethelearning.Youcanseethatthecoloroftheballooncanberecognized,butforballoonswithsimilarcolors,itmaynotbeabletoidentifythem. 2.AdjusttheThreshold Whenrecognizingcolorblocksofsimilarcolors,therecognitionaccuracycanbeadjustedbysettingthethreshold.Forexample,inthefigureabove,someyellowballoonswithsimilarcolorsarenotrecognized,andthethresholdmaybesethigher.Intheparametersettingofthecolorrecognitionfunction,thereisthe"BlockSizedThreshold"parameter.Thelowerthevalueofthisparameter,thelowertheaccuracy,butthemoresimilarcolorblockscanberecognized.Asshowninthefigurebelow,whenthethresholdis20,onlyoneyellowballcanberecognized,andwhenthethresholdis0,allthreeyellowballscanberecognized.Pleaseadjustthethresholdaccordingtotheactualeffect,sothattherecognitionaccuracyiswithinyouracceptablerange. Withthisfunction,youcaneasilyobtainthenumberofyellowballsonthescreeninrealtime. 7.6TagRecognition Thisfunctioncandetecttags,andlearn,recognize,trackspecifiedtags.ThesetagsarecalledAprilTags.ClickheretodownloadmoreAprilTags. Tips:OnlyAprilTagscanberegonized. Thedefaultsettingistolearnasingletag.Thischapteruseslearning,recognizing,andtrackingmultipletagsasanexampletodemonstrate. OperationandSetting Dialthefunctionbuttontotherightorleftuntilthewords"TagRecognition"isdisplayedatthetopofthescreen. Longpressthefunctionbuttontoentertheparametersettingofthetagrecognitionfunction. Dialthefunctionbuttonuntil"LearnMultiple"isdisplayed,thenshortpressthefunctionbutton,anddialtotherighttoturnonthe"LearnMultiple"switch,thatis,progressbarturnsblueandthesquareiconontheprogressbarmovestotheright.Thenshortpressthefunctionbuttontoconfirmthisparameter. Dialthefunctionbuttontotheleftuntil"Save&Return"shows.Andthescreenprompts"Doyouwanttosavetheparameters?"Select"Yes"indefault,nowshort-pressthefunctionbuttontosavetheparametersandreturnautomatically. LearningandDetection Youcanusethefollowingtagstotestthisfunction. 1.TagDetection: WhenHuskylensdetectsthetag,thetagwillbeautomaticallyselectedbythewhiteframeonthescreen. 2.TagLearning: Pointthe“+”symbolatthefirsttag,andpressthe“learningbutton”.Ayellowframewithwords"Tag:ID1"willbedisplayedonthescreen,indicatingthatHuskyLensislearningthetagnow.Then,releasethe"learningbutton"tocompletelearningthefirsttag,meanwhile,amessage"Clickagaintocontinue!Clickotherbuttontofinish"willbedisplayed.Pleaseshortpressthe"learningbutton"beforethecountdownendsifyouwanttolearnothertags.Ifnot,shortpressthe"functionbutton"beforethecountdownends,ordonotpressanybuttontoletthecountdownends. 3.TagRecognition Whenencounteringthelearnedtag,somecolorframeswithIDswillbeautomaticallydisplayedonthescreen.Thesizeoftheframeschangeswiththesizeofthetags,andtheframesautomaticallytrackthesetags. 7.7ObjectClassification Thisfunctioncanlearnmultiplephotosofdifferentobjects,andthenusethebuilt-inmachinelearningalgorithmfortraining.Afterthetrainingiscompleted,whenthelearnedobjectsappearagainintheHuskyLens'camera,HuskyLenscanrecognizethemanddisplaytheirIDnumbers.ThemoreHuskyLenslearnsthephotosofthesameobject,themoreaccuratetherecognitioncanbe. Thedefaultsettingistolearnmultipleobjects.Thischapterusesrecognizingwhetheraworkerwearsahelmetasanexampletodemonstrate. OperationandSetting Dialthefunctionbuttontotherightorleftuntilthewords"ObjectClassification"isdisplayedatthetopofthescreen. Longpressthefunctionbuttontoentertheparametersettingoftheobjectclassificationfunction. Dialthefunctionbuttonuntil"LearnMultiple"isdisplayed,thenshortpressthefunctionbutton,anddialtotherighttoturnonthe"LearnMultiple"switch,thatis,progressbarturnsblueandthesquareiconontheprogressbarmovestotheright.Thenshortpressthefunctionbuttontoconfirmthisparameter. Dialthefunctionbuttontotheleftuntil"Save&Return"shows.Andthescreenprompts"Doyouwanttosavetheparameters?"Select"Yes"indefault,nowshort-pressthefunctionbuttontosavetheparametersandreturnautomatically. LearningandDetection Youcanusethefollowingpicturetotest. 1.ObjectLearning: Pointthelargeframeatthefirsttargetobject(theworkerwithahelmetontheleftinthepictureabove),andlongpressthe“learningbutton”,ayellowframewithwords"LearningXX/30ID:1"willbedisplayedonthescreen,indicatingthatHuskyLensislearningtheobjectnow.Adjustthedistanceandangle,letHuskyLenslearntheobjectinvariousdistancesandangles.Then,releasethe"learningbutton"tocompletelearningthefirstobject,meanwhile,amessage"Clickagaintocontinue!Clickotherbuttontofinish"willbedisplayed.Pleaseshortpressthe"learningbutton"beforethecountdownendsifyouwanttolearnotherobjects.Ifnot,shortpressthe"functionbutton"beforethecountdownends,ordonotpressanybuttontoletthecountdownends. Inthischapter,youneedtocontinuetolearnthenextobject(theworkerwithoutahelmetontherightintheabovepicture),sopressthe"learningbutton"beforethecountdownends,andthenpointthelargeframeatthesecondtargetobject,longpressthe"learningbutton"tocompletethelearningofthesecondobject.Andsoon. TheorderoftheobjectIDandthelearnedobjectisthesame,thatis:thelearnedobjectswillbemarkedas"object:ID1","Object:ID2","Object:ID3",andsoon,andthecoloroftheframecorrespondingtotheobjectisalsodifferent. 2.ObjectRecognition: WhenHuskyLensencountersthelearnedobjectagain,itsIDnumberwillbedisplayedonthescreen.Asshowninthefigurebelow,whenHuskyLensrecognizesthattheworkeriswearingahelmet,thescreendisplaysID1,andifthereisnohelmet,itdisplaysID2. Moreinterestingideasbasedonobjectclassification:https://community.dfrobot.com/makelog-308212.html FAQ Cantheobjectclassificationfunctiongivetherelativepositionoftheobject? Answer:No.Intheobjectclassificationfunction,thepositionoftheframeisfixed,anditsxandycentercoordinatesonthescreenremainunchanged,soitcannotgivetherelativepositionoftheobjectonthescreen.ButyoucanlearndifferentpositionsofobjectsasdifferentIDs,andjudgethepositionbyID.Forexample,inautomaticvehicles,learntheID1,2,and3asontheleft,middle,andrightsidesoftheroad.ByjudgingtheID,youcanknowthepositionoftheautomaticvehiclesrelativetotheroad. Howtoimprovetheaccuracyofrecognitionundertheobjectclassificationalgorithm? Answer:Longpressthe"learningbutton"withoutreleasingit,youcanletHuskyLenslearnthetargetphotosfrommultipleanglesanddistances,toimprovetherecognitionaccuracy. 7.8AuxiliaryFunction InfirmwareV0.5.1andabove,moreauxiliaryfunctionsareaddedtohelpyouuseHUSKYLENStosetupprojectsbetter. 7.8.1CustomizetheIDName YoucanchangethecorrespondingnameoftheID,forexample:change“Face:ID1”to“Jack:ID1”,and“Color:ID1”to“Red:ID1”.Thisfunctionisusedtonameapeopleorobject,andmaketheresultofrecognitionmorerecognizable.All6algorithmssupportcustomizingtheIDnameexceptlinetracking.AndonlyEnglishnamesaresupported. Demonstration:ChangethenameofID1toJackinfacerecognition Mind+SampleProgram: MakeCodeSampleProgram: ArduinoSampleProgram: #include"HUSKYLENS.h" HUSKYLENShuskylens; voidsetup() { Serial.begin(115200); Wire.begin(); while(!huskylens.begin(Wire)) { Serial.println(F("Beginfailed!")); delay(100); } while(!huskylens.setCustomName("Jack",1))//boolsetCustomName(Stringname,uint8_tid) { Serial.println(F("ID1customnamefailed!")); delay(100); } } voidloop() { }Result “Jack:ID1”willbeshownonscreenafterHUSKYLENSlearningthefirstfaceID1.Asshownbelow: 7.8.2DisplayingCustomizedTextontheScreen Theonboardscreencanbeusedtodisplaytextsanywhereonitself.ItsupportsEnglishcharacters,numbersandsymbols.Therecognitionresultsanddatafromsensorscanbedirectlydisplayedonthescreen.All7algorithmssupportthecustomizedtext. Demonstration:Displaying“Mind+”ontheupperrightcorneratcoordinatesof(230,35) Mind+SampleProgram: MakeCodeSampleProgram: ArduinoSampleProgram: #include"HUSKYLENS.h" HUSKYLENShuskylens; voidsetup() { Serial.begin(115200); Wire.begin(); while(!huskylens.begin(Wire)) { Serial.println(F("Beginfailed!")); delay(100); } while(!huskylens.customText("mind+",230,35))//boolcustomText(Stringtext,uint16_tx,uint8_ty) { Serial.println(F("customtextfailed!")); delay(100); } } voidloop() { }Result 7.8.3SavingthePhotosorScreenshotsintoSDCard Likeadigitalcamera,HUSKYLENScantakephotosorscreenshots,andsavethemonanSDcard.WithanonboardSDcardslotonHUSKYLENS,youcanjustplugintheSDcardanduseit.Thescreenshotscontainthetexts,framesdisplayedonthescreen,whilethephotoscontainonlytheimage. All7algorithmssupportthisfunction.AnSDcardisrequiredwhenusingthisfunction. Tips: First-linebrands,suchasSanDisk,Toshiba,Samsung,andKingstonarerecommended.IncompatibilityproblemsmayexistbetweenSDcardsofsmallbrands. TheimagessavedbyHUSKYLENSiswithresolutionratioof320*240.Anditisunchangeable. PleaseformattheSDcardasFAT32.Takingphotosandscreenshots,andsavingthemcostssometime.So,itisrecommendedtousethisfunctionatleast0.5secondsapart. TheSDcardslotisfacinginwards,so,theSDcardshouldbeinsertedoutwardsasshownbelow: Demonstration:PressbuttonAofmicro:bitorpulldowntheArduinoPinA0,thenHUSKYLENSwilltakeascreenshotandsaveitinSDcard Mind+SamplePorgram: MakeCodeSamplePorgram: ArduinoSamplePorgram: #include"HUSKYLENS.h" HUSKYLENShuskylens; voidsetup() { Serial.begin(115200); pinMode(A0,INPUT_PULLUP); Wire.begin(); while(!huskylens.begin(Wire)) { Serial.println(F("Beginfailed!")); delay(100); } } voidloop() { if(digitalRead(A0)==0) { while(!huskylens.saveScreenshotToSDCard())//boolsaveScreenshotToSDCard()orboolsavePictureToSDCard() { Serial.println(F("savescreenshottoSDcardfailed!")); delay(100); } Serial.println(F("savingscreenshottoSDcard...")); delay(500);//Theintervalbetweencallingthisfunctionisnotlessthan0.5seconds. } }Result PressbuttonAofmicro:bitorpulldowntheArduinoPinA0,thenHUSKYLENSwilltakeascreenshotandsaveitinSDcard.TakeouttheSDcardandinsertitintoacomputer,thenyoucanviewthescreenshottakenbyHUSKYLENS. TheimageshownonthesucreenofHUSKYLENS Readtheimagefile(.bmp)ontheSDcardonacomputer Opentheimagefile 7.8.4SDCardsaving/loadingthemodels HUSKYLENSsupportstakingmultipleobjectslearnedfromthesamealgorithmasonedatamodel.TheSDcardcanbeusedtosavethemodel.Themodelcanbereloadedevenifallthedatafromthecurrentalgorithmisdeleted,allowingHUSKYLENStoautomaticallylearnthedatainthemodel.Bysavingthemodel,HUSKYLENScanbeusedformultiplescenesinonealgorithm.Forexample,intheobjectclassificationalgorithm,learnrock-paper-scissorsasonemodelandgarbageclassificationasonemodel.Then,throughmodelswitching,therequiredfunctionscanbequicklyrealizedtoavoidrepeatinglearning. ThisfunctionrequiresanSDcard,whichneedstobeformattedasFAT32.All7algorithms,eachofwhichcansave5models,supportSDcardsavingandloadingmodels. Method1:Operatemanuallyunderthesecondarymenuofeachalgorithm Herewetaketheobjectclassificationfunctionasademonstration.Theusageinotheralgorithmsarethesame. 1.Learnnewobjects:LetHUSKYLENSlearnseveralnewobjects.Forexample:intheobjectclassificationfunction,learnseveralanimalswithdifferentIDnumbersinturn. 2.Exportmodel:longpress"FunctionButton"toenterparametersettingsinterfaceofthesecondarymenuintheclassificationfunction,andthendial"FunctionButton"totherightuntiltheoptionof“exporttoSDcard"(thatis,savethemodeltotheSDcard).Shortpress"FunctionButton",dial"FunctionButton",selectanyonefrom0to4(equivalenttoselectthesavelocation,makingiteasytodistinguishthedifferentmodels),thenshortpress"FunctionButton"tosavethemodel. AfterthemodelisexportedtotheSDcard,readtheSDcardwiththecomputer,andyoucanseethemodeldatafilewithsuffix.confinthe"HUSKYLENS"folder.Thefilenamessavedbydifferentalgorithmsaredifferent.Shownasbelow: Tip:Accordingtothenamesofthefiles,wecanknowwhichalgorithmfunctiontheexportedmodeldatafilebelongsto.Thepictureslearnedineachmodelcannotbeviewed. 3.Importmodel:WhenthemodeldatafileisalreadyintheSDcard,wecandirectlyimportitintoHUSKYLENS.Forexample,intheobjectclassificationfunction,ifthemodeldatafileofobjectclassificationisalreadyintheSDcard,then,justselect"ImportfromSDCard"inparametersettinginterfaceofsecondarymenuofobjectclassificationfunction,andselectanyonefrom0to4toloadthemodelintoHUSKYLENS. Afterimportingthemodel,HUSKYLENScanrealizerecognitionusingthecurrentmodel. Tips:Whenimportingmodels,onlymodelswiththesamealgorithmaresupported. Method2:MakeAProgramtoTriggerSaving/LoadingModels Inthisway,micro:bit,Arduino,andothermainboardscanbeusedtoautomaticallytriggerthesavingorloadingofmodelfiles.Thefollowingcodeblockcanbeusedtoachievethisfunction. Mind+Block: MakeCodeBlock: Arduinofunction: boolsaveModelToSDCard(intfileNum); boolloadModelFromSDCard(intfileNum);7.8.5MakeAProgramtoTriggerLearningFunction Inadditiontomanuallypressingthe"learnbutton"tolearnthetargetobject,itcanalsobetriggeredprogrammatically.Thisfunctionenablesmicro:Bit,Arduino,andothermainboardstoautomaticallycontrolthelearningofHUSKYLENS. All7algorithmsofHUSKYLENSsupportthisfunction. Demonstration:PressbuttonAonthemainboardofmicro:bitorpulldowntheArduinoPinA0toletHUSKYLENSlearntheobjectonce.Theobject’sIDis1. Mind+SampleProgram: MakeCodeSampleProgram: ArduinoSampleProgram: #include"HUSKYLENS.h" HUSKYLENShuskylens; voidsetup() { Serial.begin(115200); pinMode(A0,INPUT_PULLUP); Wire.begin(); while(!huskylens.begin(Wire)) { Serial.println(F("Beginfailed!")); delay(100); } } voidloop() { if(digitalRead(A0)==0) { while(!huskylens.writeLearn(1))//boolwriteLearn(intID) { Serial.println(F("learnobjectID1failed!")); delay(100); } Serial.println(F("learnobjectID1success")); } }Result Inobjectclassificationmode,aimHUSKYLENSatthefollowingthreeimagesinturn.PressbuttonAofmicro:bitorpulldowntheArduinoPinA0,thenHUSKYLENSwilllearnthesethreeimagesasobjects:ID1inturn.WhenHUSKYLENSrecognizesanyofthesethreeimagesagain,itdisplaysobject:ID1onthescreen,indicatingthatthethreeworkersarewearingsafetyhats. 1 2 3 HereyoucancustomizethenameofID1,suchassafe:ID1;Youcanalsocustomizethetextonthescreen,overlayingrelevantinformationtoindicatethatthestatusiswithsafetyhat.Withtheinformation,therecognitionresultsareeasytounderstand. 8.ArduinoTutorial PleasedownloadandinstalltheHUSKYLENSLibraryfirst. 8.1InstalltheLibrary Unzipthefile,thencopythefoldertothe"libraries"folderoftheArduinoIDE.Thencheckwhetherthefoldernameis"HUSKYLENS".Ifnot,pleasechangeitas"HUSKYLENS".PleasenotethatthelibraryfilenamemustbeHUSKYLENS. All.hfilesand.cppfilesmustintherootdirectoryofthe"HUSKYELSN"folder. 8.2Project1:ReadPositionData Inthisproject,HuskyLenswillbeconnectedtoArduinomainboard.AndArduinoUnowillreadpositiondataoftheobjectfromHuskyLens.Thentheserialportmonitorwillprintthedata.Sothat,youcanreadthepositionoftheobjectinrealtime. Requirements Hardware DFRduinoUNOR3(orsimilar)x1 HUSKYLENSx1 M-M/F-M/F-FJumperwires Software ArduinoIDE(version1.8.xisrecommended) DownloadandinstalltheHUSKYLENSLibrary(Abouthowtoinstallthelibrary?) UARTMode(SoftwareSerial) ConnectionDiagram HuskyLensProtocolSetting YouneedtosettheprotocoltypeofHuskyLens.Theprotocolshouldbe'Serial9600'.Ofcourse,yourcanadopttheAutoDetectprotocol,whichiseasy-to-useandconvenient. SampleCode #include"HUSKYLENS.h" #include"SoftwareSerial.h" HUSKYLENShuskylens; SoftwareSerialmySerial(10,11);//RX,TX //HUSKYLENSgreenline>>Pin10;blueline>>Pin11 voidprintResult(HUSKYLENSResultresult); voidsetup(){ Serial.begin(115200); mySerial.begin(9600); while(!huskylens.begin(mySerial)) { Serial.println(F("Beginfailed!")); Serial.println(F("1.Pleaserecheckthe\"ProtocolType\"inHUSKYLENS(GeneralSettings>>ProtocolType>>Serial9600)")); Serial.println(F("2.Pleaserechecktheconnection.")); delay(100); } } voidloop(){ if(!huskylens.request())Serial.println(F("FailtorequestdatafromHUSKYLENS,rechecktheconnection!")); elseif(!huskylens.isLearned())Serial.println(F("Nothinglearned,presslearnbuttononHUSKYLENStolearnone!")); elseif(!huskylens.available())Serial.println(F("Noblockorarrowappearsonthescreen!")); else { Serial.println(F("###########")); while(huskylens.available()) { HUSKYLENSResultresult=huskylens.read(); printResult(result); } } } voidprintResult(HUSKYLENSResultresult){ if(result.command==COMMAND_RETURN_BLOCK){ Serial.println(String()+F("Block:xCenter=")+result.xCenter+F(",yCenter=")+result.yCenter+F(",width=")+result.width+F(",height=")+result.height+F(",ID=")+result.ID); } elseif(result.command==COMMAND_RETURN_ARROW){ Serial.println(String()+F("Arrow:xOrigin=")+result.xOrigin+F(",yOrigin=")+result.yOrigin+F(",xTarget=")+result.xTarget+F(",yTarget=")+result.yTarget+F(",ID=")+result.ID); } else{ Serial.println("Objectunknown!"); } } OperationsandExpectedResults UploadtheabovecodestoyourArduinoboard. LetyourHuskyLenslearnanewthingfirst.Youcanrefertothepreviouschaptersofthistutorial. OpentheserialmonitorofArduinoIDE,thenyouwillgetthepositiondataoftheobject. IfHuskyLensisinthefacerecognition,objecttracking,objectrecognition,colorrecognition,tagrecognitionmode,youwillgettheresultslikefollows: IfHuskyLensisinthelinetrackingmode,youwillgettheresultslikefollows: I2CMode ConnectionDiagram HuskyLensProtocolSetting YouneedtosettheprotocoltypeofHuskyLens.Theprotocolshouldbe'I2C'.Ofcourse,yourcanadopttheautodetectprotocol,whichiseasy-to-useandconvenient. SampleCode #include"HUSKYLENS.h" #include"SoftwareSerial.h" HUSKYLENShuskylens; //HUSKYLENSgreenline>>SDA;blueline>>SCL voidprintResult(HUSKYLENSResultresult); voidsetup(){ Serial.begin(115200); Wire.begin(); while(!huskylens.begin(Wire)) { Serial.println(F("Beginfailed!")); Serial.println(F("1.Pleaserecheckthe\"ProtocolType\"inHUSKYLENS(GeneralSettings>>ProtocolType>>I2C)")); Serial.println(F("2.Pleaserechecktheconnection.")); delay(100); } } voidloop(){ if(!huskylens.request())Serial.println(F("FailtorequestdatafromHUSKYLENS,rechecktheconnection!")); elseif(!huskylens.isLearned())Serial.println(F("Nothinglearned,presslearnbuttononHUSKYLENStolearnone!")); elseif(!huskylens.available())Serial.println(F("Noblockorarrowappearsonthescreen!")); else { Serial.println(F("###########")); while(huskylens.available()) { HUSKYLENSResultresult=huskylens.read(); printResult(result); } } } voidprintResult(HUSKYLENSResultresult){ if(result.command==COMMAND_RETURN_BLOCK){ Serial.println(String()+F("Block:xCenter=")+result.xCenter+F(",yCenter=")+result.yCenter+F(",width=")+result.width+F(",height=")+result.height+F(",ID=")+result.ID); } elseif(result.command==COMMAND_RETURN_ARROW){ Serial.println(String()+F("Arrow:xOrigin=")+result.xOrigin+F(",yOrigin=")+result.yOrigin+F(",xTarget=")+result.xTarget+F(",yTarget=")+result.yTarget+F(",ID=")+result.ID); } else{ Serial.println("Objectunknown!"); } } OperationsandExpectedResults UploadtheabovecodestoyourArduinoboard. LetyourHuskyLenslearnanewthingfirst.Youcanrefertothepreviouschaptersofthistutorial. OpentheserialmonitorofArduinoIDE,thenyouwillgetthepositiondataoftheobject,sameastheresultsinUARTmode.Pleaserefertothepreviouschapter,whichwillnotberepeatedhere. 8.3Project2:DIYLineTrackingRobot Inthispart,wewillusetheDevastatorTankMobileRobot,HuskyLensandRomeoboardtomakealinetrackingrobot. Pleasereferthisposttogetthedemonstration. 8.4ArduinoAPIIntroduction PleaseclickheretoviewtheAPIintroductiondocuments. 10.micro:bitTutorial Inthischapter,wewillusemicro:bitboardtoreaddatafromtheHuskyLens.ThecommunicationprotocolisI2C.WeadoptMind+andMakeCode,thencombinewithseveralprojectcasestodemonstratetheusage. NowweadoptMind+fordemonstrationfirst.LaterweadoptMakeCodetodemonstrate. 10.1Mind+Introduction Mind+isaScratch3.0-basedprogrammingtool,whichallowsyoutobuildaprogrambydraggingandsnappingcodingblocks.Withtonsoftutorials,sampleprojectsandalargecommunity,itisoneofthebesttoolsforyoutolearnprogramingfromabsolutelyzero! Mind+supportsawiderangeofhardwareincludingArduino,micro:bitorevenaseriesofESP32-basededucationalmicrocontrollers. PleaseviewMind+officialsitehttp://mindplus.cctodownloadthelatestMind+. 10.2LoadHuskyLensExtension IntheupperrightcorneroftheMind+window,dialtheswitchtotheofflinemode. ClicktheExtensionsbuttoninthelowerleftcornertoviewtheextensionswindow. Selectamaincontrolboard.Hereweselectthemicro:bit. Afterselectingthemaincontrolboard,thecorrespondingextensionlabelsbecomeselectable.ThenclickSensorlabel,findHuskyLens.Clickittoload. Youcanenterthesensor'snameinthesearchbarinupperrightcornerwhentherearemanysensorslistedinthemenu. Afterselectingthemaincontrolboardandextensions,clickBackbuttonintheupperleftcornertoreturntotheprogrammingwindow. 10.3Mind+Project1:FaceRecognition ThischapterdemonstrateshowtoconnectHuskyLenstothemicro:bitboard,thenthemicro:bitboardreadsthefacerecognitionresultsfromHuskyLens.IfHuskyLensrecognizesyou(thelearnedface),thedot-matrixscreenofthemicro:bitdisplaysasmilingface,otherwiseitdisplaysacryingface. ThecommunicationprotocolbetweenHuskyLensandmicro:bitisI2C. Requirements Hardware micro:bitboardx1 [micro:bitexpansionboard](https://www.dfrobot.com/search-micro:bitexpansion.html)x1 HUSKYLENSx1 M-M/F-M/F-FJumperwires Software Mind+ HUSKYLENSExtension:Mind+built-in ConnectionDiagram Thefollowingpictureisonlyforreferencewhenwiring.TheRandTpinsofHuskyLens(theirfunctionsareSCLandSDAhere)areconnectedtotheSCL(P19)andSDA(P20)pinsofthemicro:bitrespectively.ThecommunicationprotocolbetweenHuskyLensandmicro:bitisI2C. Amicro:bitexpansionboardisrecommendedforsimplifywiring. Tips:HuskyLensconsumesheavycurrent,upto3.3V320mAormore.Themciro:bitboardisnotenoughtosupplypower.Therefore,externalpowersupplyisrequired.Youcanconnecttheexternalpowersupplytotheexternalpowerconnectorofthemicro:bitexpansionboardortheUSBconnectorofHuskyLens. HuskyLensProtocolSetting YouneedtosettheprotocoltypeofHuskyLens.TheprotocolshouldbeI2C.Ofcourse,yourcanadopttheautodetectprotocol,whichiseasy-to-useandconvenient. SampleCode Dragandsnapthecodingblockstoprogram,andmakeasimplefacerecognitionprojects.Thesamplecodeisshownbelow. OperationsandExpectedResults ClicktheConnectDevicebutton,thenselecttheCOMportcorrespondingtothemicrobit. IfnoCOMportisfoundoryouusemcirobitforthefirsttime,pleaseclicktheInstallSerialportDriverbuttontoinstallthedriverwithoneclick. ClicktheUploadbuttontouploadthesamplecodetoyourmicro:bitboard. LetyourHuskyLenslearnyourfacefirst.Youcanrefertothechapter7.1ofthistutorial. WhenHuskyLensrecognizesyourface,thedot-matrixscreenonthemicro:bitboardwillshowasmilingface.Ifitwerenotyourface,ornofaceappeared,itwoulddisplayacryingface. 10.4CodingBlockIntroduction Below,weadoptMakeCodefordemonstrationbelow. 10.5MakeCodeIntroduction MicrosoftMakeCodeisafree,opensourceplatformforcreatingengagingcomputersciencelearningexperiencesthatsupportaprogressionpathintoreal-worldprogramming.ClickheretoviewtheMakeCodeformicro:bit. 10.6LoadHuskyLensExtension CreateanewprojectinMakeCodewebversion,andthenclickthe"More..."button(gearicon)atthetoprightandselect"Extensions"fromitsdrop-downmenutoopentheextensionpage. Enterhuskylensinthesearchbar,thenclickthesearchbutton(themagnifyingglassbuttonontherightofthesearchbar),youwillseetheHuskyLensextensions.ThenclickittoloadtheHuskyLensextensionintotheMakeCode. Intheprogrammingpage,youcanseetheHuskylensmodule. 10.7Project1:FaceRecognition ThischapterdemonstrateshowtoconnectHuskyLenstothemicro:bitboard,thenthemicro:bitboardreadsthefacerecognitionresultsfromHuskyLens.IfHuskyLensrecognizesyou(thelearnedface),thedot-matrixscreenofthemicro:bitdisplaysasmilingface,otherwiseitdisplaysacryingface. ThecommunicationprotocolbetweenHuskyLensandmicro:bitisI2C. Requirements Hardware micro:bitboardx1 micro:bitexpansionboardx1 HUSKYLENSx1 M-M/F-M/F-FJumperwires Software MicrosoftMakeCodeformicro:bit HUSKYLENSMakeCodeExtension ConnectionDiagram Thefollowingpictureisonlyforreferencewhenwiring.TheRandTpinsofHuskyLens(theirfunctionsareSCLandSDAhere)areconnectedtotheSCL(P19)andSDA(P20)pinsofthemicro:bitrespectively.ThecommunicationprotocolbetweenHuskyLensandmicro:bitisI2C. Amicro:bitexpansionboardisrecommendedforsimplifywiring. Tips:HuskyLensconsumesheavycurrent,upto3.3V320mAormore.Themciro:bitboardisnotenoughtosupplypower.Therefore,externalpowersupplyisrequired.Youcanconnecttheexternalpowersupplytotheexternalpowerconnectorofthemicro:bitexpansionboard,ortheHuskyLensUSBconnector. HuskyLensProtocolSetting YouneedtosettheprotocoltypeofHuskyLens.TheprotocolshouldbeI2C.Ofcourse,yourcanadopttheautodetectprotocol,whichiseasy-to-useandconvenient. SampleCode OperationsandExpectedResults Uploadtheabovecodestothemicro:bitboard. Refertothepreviouschapterwhichexplainingthefacerecognitionfunction(chapter7.1),letyourHuskyLenslearnaface,suchasyourface. WhenHuskyLensrecognizesyourface,thedot-matrixscreenonthemicro:bitboardwillshowasmilingface.Ifitwerenotyourface,ornofaceappeared,itwoulddisplayacryingface. 10.8CodingBlockIntroduction 11.FAQ Q.WhenIuploadthefirmwarebythek-flash,butIgetthe"endofcentraldirectoryrecordcouldnotbefound"errormessage.HowcanIfixthis? A.Thefirmwareyoudownloadedisnotcorrect,thatis,Thefileisincompleteandwrong.(e.g.Thecorrectfirmwareisupto9MB,butthefirmwareyoudownloadisonly66KB.)Itmaycausedbytheunstablenetworkorothermatters.Pleasedownloaditfromthegithubagain. https://github.com/HuskyLens/HUSKYLENSUploader 12.MoreDocuments LatestFirmware:V0.5.1a HistoryVersionFirmware(github) ArduinoLibrary(github) micro:bitMakecodeLibrary(github) ProtocolDocument TagPictures(Morethan500) ColorBlockPictures 3Dmodelfile(.stp) K-FlashSoftware Download.NETFramework4.7.1forK-Flash DownloadWIKIPage(PDF) Forum Community GetHUSKYLENSfromDFRobotStoreorDFRobotDistributor. TurntotheTop



請為這篇文章評分?