使用Google Cloud Vision API分析您应用程序中上传的图片并防范不适当的内容。
在获取自己的Google API Key之后,创建一个用于以下示例中的Picguard实例
let picguard = Picguard(APIKey: "foobar")
如果您的应用程序允许用户上传照片,您可能需要频繁地使用NSFW过滤器来拒绝包含
Picguard提供了检测上述所有类别的统一方法,并使用算法计算NSFW内容的平均可能性
picguard.detectUnsafeContentLikelihood(image: anImage) { result in
switch result {
case .Success(let likelihood):
print("Likelihood of NSFW content: \(likelihood)")
case .Error(let error):
print("Error detecting NSFW content: \(error)")
}
}
有时您可能需要知道照片中是否含有任何人脸。在这种情况下,Picguard提供了一个简单的方法来计算图片中存在任何人脸的可能性
picguard.detectFacePresenceLikelihood(image: anImage) { result in
switch result {
case .Success(let likelihood):
print("Likelihood of face presence: \(likelihood)")
case .Error(let error):
print("Error detecting face presence: \(error)")
}
}
由于Picguard是一个功能齐全的Google Cloud Vision API客户端,您可以自行构造上述助手未涵盖的请求,并以您自己的方式解释结果
picguard.annotate(image: anImage, features: [
.Face(maxResults: 2),
.Label(maxResults: 5),
.Landmark(maxResults: 3),
]) { result in
switch result {
case .Success(let response):
print("Face annotations: \(response.faceAnnotations)")
print("Label annotations: \(response.labelAnnotations)")
print("Landmark annotations: \(response.landmarkAnnotations)")
case .Error(let error):
print("Error analyzing image: \(error)")
}
}
所有*Annotation
数据类型都有详细的文档,并反映了等效的API类。
如果您在将其用于应用程序之前想要与Picguard互动,我们特意为您准备了一个
Picguard是用Swift 2.2编写的,需要Xcode 7.3或更高版本进行编译。最低部署目标是iOS 9和OS X 10.11。
Picguard 使用 Swift 2.2 编写,并需要 Xcode 7.3 或更高版本来开发。
使用以下命令安装 Carthage 依赖,您就可以开始使用了!
$ carthage bootstrap --platform 'iOS,Mac'
Picguard 遵循 GitHub的Swift风格指南 中描述的标准。
请注意,其中一点是“使用制表符,而不是空格”。理由:当使用制表符时,开发者可以配置 IDE 将其显示为 2、3、4 或任何其他喜欢数量的空格 - 因此在这方面没有讨论。
请将 构建设置 保存在 Configuration
目录内适当的 xcconfig
文件中。请勿在 pbxproj
中包含任何构建设置。
源文件 和 spec 文件 应分别放置在 Sources
和 Tests
目录中,无需额外的子目录。您可以在 Xcode 项目内部使用组来管理文件。
Bitrise CI 配置应描述在 bitrise.yml
文件中,且不要在 Bitrise.io UI 内覆盖任何工作流程。
此仓库使用 git-flow,并保护 develop
和 master
分支免受强制推送和红色构建的影响,这意味着整个开发过程是由拉取请求驱动的。
此项目由 Netguru 用爱制成,并由以下人员维护:
另外,别忘了查看 原始 Picguard,我们用于验证上传图片的 Ruby gem!
此项目许可协议为 MIT 许可协议。有关更多信息,请参阅 LICENSE.md。