admin管理员组文章数量:1122846
I am having an issue updating the UI from the background thread.
The issue is whenever I set inferenceResult
published var to observer the change in UI - I only get one result and then callback from camera frame stops.
If I comment setting the published var on result self.inferenceResult =
and prints the result - I get the expected result per frame printed in the console continuously. I am trying to print the result continuously in the UI but as soon as I set the published var I only get one result and it stops.
Any ideas, Thanks
class CameraPreviewer: ObservableObject, CameraFeedManagerDelegate {
@Published var inferenceResult: [ImageClassificationResult] = []
func didOutput(pixelBuffer: CVPixelBuffer) {
DispatchQueue.global(qos: .userInitiated).async { [weak self] in
guard let self = self else { return }
let results = self.imageClassifier.classify(frame: pixelBuffer)
DispatchQueue.main.async {
self.inferenceResult = resultspactMap { result in
guard let label = result.label else { return nil }
return ImageClassificationResult(
inferenceTime: result.inferenceTime,
label: label,
score: result.score
)
}
}
}
}
Here is my View code
struct PreviewView: View {
@StateObject private var cameraPreviewer = CameraPreviewer()
var body: some View {
VStack {
Text("Inference Results").font(.headline)
ScrollView {
LazyVStack(alignment: .leading, spacing: 8) {
ForEach(cameraPreviewer.inferenceResult) { item in
HStack {
VStack(alignment: .leading, spacing: 4) {
Text("Label: \(item.label)")
.font(.body)
.foregroundColor(.primary)
}
//...
本文标签: iosUpdating UI from the background thread image classification Swift UIStack Overflow
版权声明:本文标题:ios - Updating UI from the background thread image classification Swift UI - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736281959a1926490.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论