Saturday, November 21, 2026
HomeiOS Developmentios - Methods to assign a novel ID to a detected face...

ios – Methods to assign a novel ID to a detected face utilizing Imaginative and prescient

[ad_1]

I am at the moment 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.

personal var lastObservation: VNDetectedObjectObservation?
personal 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 {
        strive sequenceRequestHandler.carry out([request], on: pixelBuffer)
    } catch {
        print(error)
    }
}

personal func handleUpdate(_ request: VNRequest, error: Error?) {
    DispatchQueue.primary.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 novel ID, which I need 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 could be assigned with 0 and the second face could 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 novel ID for every face utilizing Imaginative and prescient. I’ve discovered a hashValue property of VNDetectedObjectObservation, however I am unsure if it could possibly be used because the distinctive ID for every face.

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments