dbgba优化整理OpenCV系列示例打包下载20240513:
人脸识别DynamicFace代码片段
#SingleInstance Force SetBatchLines -1 SetWorkingDir %A_ScriptDir% ; 加载并初始化OpenCV hOpenCV := DllCall("LoadLibrary", "Str", "opencv_world490.dll", "Ptr") autoit_opencv_com_path := A_ScriptDir "\autoit_opencv_com490.dll" hOpenCVCom := DllCall("LoadLibrary", "Str", autoit_opencv_com_path, "Ptr") ComObjCreate := Func("_ComObjCreate").Bind(autoit_opencv_com_path) cv := ComObjCreate.Call("OpenCV.cv") Cap := ComObjCreate("OpenCV.CV.VideoCapture") Mat := ComObjCreate("OpenCV.CV.MAT") Frame := ComObjCreate("OpenCV.CV.MAT") Cap.open(0) ; 打开第几个摄像头【请确保你的电脑有可用的摄像头】 faceCascade := ComObjCreate("Opencv.cv.CascadeClassifier") faceCascade.load(".\Lib\haarcascade_frontalface_default.xml") Loop { Ret := Cap.read(Frame) faces := faceCascade.detectMultiScale(Frame, 1.1+0, 10+0) Loop % faces.MaxIndex()+1 CV.rectangle(Frame, faces[A_Index-1], ComArrayMake([255, 0, 255]), 3) CV.imshow("Live", Frame) ; CV.WaitKey(5) ; if !WinExist("Live") { ; CV.destroyAllWindows() ; Break ; } } _ComObjCreate(opencvPath, ComObject) { DllCall(opencvPath "\DllActivateManifest") ComObject := ComObjCreate(ComObject) DllCall(opencvPath "\DllDeactivateActCtx") Return ComObject } ComArrayMake(InputArray) { Arr := ComObjArray(VT_VARIANT:=12, InputArray.Length()) Loop % InputArray.Length() Arr[A_Index-1] := InputArray[A_Index] Return Arr }
声明:站内资源为整理优化好的代码上传分享与学习研究,如果是开源代码基本都会标明出处,方便大家扩展学习路径。请不要恶意搬运,破坏站长辛苦整理维护的劳动成果。本站为爱好者分享站点,所有内容不作为商业行为。如若本站上传内容侵犯了原著者的合法权益,请联系我们进行删除下架。
评论(0)