Sunday, October 2, 2022
HomeiOS Developmentios - Tips on how to assign a singular ID to a...

ios – Tips on how to assign a singular ID to a detected face utilizing Imaginative and prescient


I am at present migrating over from Google MLKit to the Imaginative and prescient framework to detect and monitor faces in actual time. Following is a simplified model of how I am implementing the framework, however I am additionally utilizing VNDetectFaceLandmarksRequest for the landmarks and VNDetectFaceRectanglesRequest for the face angles.

non-public var lastObservation: VNDetectedObjectObservation?
non-public var sequenceRequestHandler = VNSequenceRequestHandler()

func captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) {
    guard
        let pixelBuffer: CVPixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer),
        let lastObservation = self.lastObservation
        else { return }
    
    let request = VNTrackObjectRequest(detectedObjectObservation: lastObservation, completionHandler: handleUpdate)
    
    do {
        attempt sequenceRequestHandler.carry out([request], on: pixelBuffer)
    } catch {
        print(error)
    }
}

non-public func handleUpdate(_ request: VNRequest, error: Error?) {
    DispatchQueue.important.async {
        guard let newObservation = request.outcomes?.first as? VNDetectedObjectObservation else { return }
        self.lastObservation = newObservation
        
        /// do issues with the commentary
    }
}

My earlier infrastructure assigns every detected face with a singular ID, which I would like to have the ability to do with Imaginative and prescient. For instance, if two persons are seen within the digicam, the primary particular person’s face can be assigned with 0 and the second face can be assigned with 1. This distinctive ID is used as the important thing to a dictionary in order that I can retailer sure attributes about every face within the worth. Nevertheless, I can not appear to be have a property for a singular ID for every face utilizing Imaginative and prescient. I’ve discovered a hashValue property of VNDetectedObjectObservation, however I am unsure if it may very well be used because the distinctive ID for every face.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments