Make a camera that recognizes animals and shoots automatically
Apple’s Vision framework has an animal recognition computer vision request.
The request result determines if there is an animal in the frame and sets it to take a picture.
let animalRequest:VNRecognizeAnimalsRequest = {
let request = VNRecognizeAnimalsRequest(completionHandler: { (request, error) in
guard let animalObservation = results.first as? VNRecognizedObjectObservation else { return }// If there is animalObservation, there are animals, so release the shutter self.avCapturePhotoOutput.capturePhoto(with: settings, delegate: self as! AVCapturePhotoCaptureDelegate)
})
request.revision = VNRecognizeAnimalsRequestRevision1//In revision 1, only dogs and cats can be recognized.
return request
}()
Within the captureOutput delegate method, execute the above request and parse the frame.
func captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) {
guard let pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer) else { return }
let imageRequestHandler = VNImageRequestHandler(cvPixelBuffer: pixelBuffer, orientation: orientation, options: [:])
do {
try imageRequestHandler.perform([animalRequest])
} catch {
print(error)
}
}
Using other requests in the same way, you can recognize humans and arbitrary objects and take pictures.
Observation also includes a Bounding Box that shows the location of dogs and cats, so you can also autofocus on it.
🐣***
We send information related to machine learning.
Request for work:
rockyshikoku@gmail.com