我也为了好玩做过类似的项目。链接在这里:https://github.com/sawin0/FaceDetection
对于那些不想深入研究回购协议的人。
我有一个快速建议给你,如果你有圆和面的路径作为 CGPath 那么你可以使用
contains(_:using:transform:)
来比较圆和面的边界框。
这是一个代码片段
let circleBox = circleCGPath.boundingBox
let faceBox = faceRectanglePath.boundingBox
if(circleBox.contains(faceBox)){
print("face is inside the circle")
}else{
print("face is outside the circle")
}
我希望这对您和其他人也有帮助。
附注如果有更好的方法请随时分享。