简体   繁体   中英

HMCameraSnapshot to UIImage

I'm playing the a homekit camera device where I can get the stream video an display it in a HMCameraView. I need to take snapshot of this video stream and this can be done using cameraSnapshotControl function. Works great I can see using the delegate function: HMCameraSnapshotControlDelegate that snapshot are taken. However I spent hours looking how to convert this snapshot in a basic image like UIImage... I do not need to display this image but analyse it (CoreML). Someone already try this? Seems that nobody code with Homekit Apple framework...

I just ran into this same issue and I couldn't find anything in Apple's official documentation explaining how to do it. After playing around with a few things, I eventually discovered that you can do this by setting the cameraSource property on HMCameraView, which accepts both video streams and snapshots.

@IBOutlet weak var cameraLiveStreamView: HMCameraView!
...

func cameraSnapshotControl(_ cameraSnapshotControl: HMCameraSnapshotControl, didTake snapshot: HMCameraSnapshot?, error: Error?) {
   cameraLiveStreamView?.cameraSource = cameraSnapshotControl.mostRecentSnapshot
}

Hope this helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM