ZBLOG

我的代码如下extension CameraViewController: PoseLandmarkerServiceLiveStreamDelegate { func poseLandmarkerService( _ poseLandmarkerService: PoseLandmarkerService, didFinishDetection result: ResultBundle?, error: Error?) { Di...

在你的代码中,configJsonData 没有前缀 self.,这会导致编译器提示你需要显式使用 self。为了修复这个问题,你需要在访问 configJsonData 时加上 weakSelf 的前缀,因为它是通过 [weak self] 捕获的。

以下是修改后的代码:

extension CameraViewController: PoseLandmarkerServiceLiveStreamDelegate {

  func poseLandmarkerService(
    _ poseLandmarkerService: PoseLandmarkerService,
    didFinishDetection result: ResultBundle?,
    error: Error?) {
        
      DispatchQueue.main.async { [weak self] in
        guard let weakSelf = self else { return }
        weakSelf.inferenceResultDeliveryDelegate?.didPerformInference(result: result)
        guard let poseLandmarkerResult = result?.poseLandmarkerResults.first as? PoseLandmarkerResult else { return }
        let imageSize = weakSelf.cameraFeedService.videoResolution

        let poseOverlays = OverlayView.poseOverlays(
            fromMultiplePoseLandmarks: poseLandmarkerResult.landmarks,
            inferredOnImageOfSize: imageSize,
            ovelayViewSize: weakSelf.overlayView.bounds.size,

            locatMinX: weakSelf.configJsonData?.LocationList.first?.RectPoint.first?.x ?? 0,
            locatMaxX: weakSelf.configJsonData?.LocationList.first?.RectPoint.last?.x ?? 0,
            locatMinY: weakSelf.configJsonData?.LocationList.first?.RectPoint.first?.y ?? 0,

            imageContentMode: weakSelf.overlayView.imageContentMode,
            andOrientation: UIImage.Orientation.from(
                deviceOrientation: UIDevice.current.orientation))
          
        weakSelf.overlayView.draw(poseOverlays: poseOverlays,
                                   inBoundsOfContentImageOfSize: imageSize,
                                   imageContentMode: weakSelf.cameraFeedService.videoGravity.contentMode)
      }
  }
}

修改要点:

  1. 将对 configJsonData 的访问改为使用 weakSelf.configJsonData
  2. 确保其他属性和方法的调用保持一致,这样就不会出现相同的问题。

这样一来,所有的属性和方法调用都将以正确的方式捕获并避免潜在的问题。


内容由零声教学AI助手提供,问题来源于学员提问

本站部分文章来源于网络,版权归原作者所有,如有侵权请联系站长删除。
转载请注明出处:https://golang.0voice.com/?id=21567

分享:
扫描分享到社交APP
上一篇
下一篇
发表列表
游客 游客
此处应有掌声~
评论列表

还没有评论,快来说点什么吧~

联系我们

在线咨询: 点击这里给我发消息

微信号:3007537140

上班时间: 10:30-22:30

关注我们
x

注册

已经有帐号?