`frameProcessingChain` 在这个项目中做什么?

问题描述 投票:0回答:1

我正在查看苹果的示例项目检测实时视频源中的人类行为,它具有一个名为

frameProcessingChain
的属性,其声明如下

/// A cancellation token for the active video-processing chain.
    ///
    /// To tear down the frame processing chain, call this property's `cancel()`
    /// method, or allow it to deinitialize.
    private var frameProcessingChain: AnyCancellable?

同一个类中有这个方法,如下代码片段所示:

// Create the chain of publisher-subscribers that transform the raw video
    // frames from upstreamFramePublisher.
    frameProcessingChain = upstreamFramePublisher
        // ---- Frame (aka CMSampleBuffer) -- Frame ----

        // Convert each frame to a CGImage, skipping any that don't convert.
        .compactMap(imageFromFrame)

        // ---- CGImage -- CGImage ----

        // Detect any human body poses (or lack of them) in the frame.
        .map(findPosesInFrame)

        // ---- [Pose]? -- [Pose]? ----

        // Isolate the pose with the largest area in the frame.
        .map(isolateLargestPose)

        // ---- Pose? -- Pose? ----

        // Publish the locations of the pose's landmarks as an
        // `MLMultiArray` to the next subscriber.
        .map(multiArrayFromPose)

        // ---- MLMultiArray? -- MLMultiArray? ----

        // Gather a window of multiarrays, starting with an empty window.
        .scan([MLMultiArray?](), gatherWindow)

        // ---- [MLMultiArray?] -- [MLMultiArray?] ----

        // Only publish a window when it grows to the correct size.
        .filter(gateWindow)

        // ---- [MLMultiArray?] -- [MLMultiArray?] ----

        // Make an activity prediction from the window.
        .map(predictActionWithWindow)

        // ---- ActionPrediction -- ActionPrediction ----

        // Send the action prediction to the delegate.
        .sink(receiveValue: sendPrediction)

根据我的理解,这个属性

frameProcessingChain
并没有在项目的任何地方主动使用,它只是在函数运行后设置为代码片段中指定的值。

但是,如果我删除这个变量,那么项目将无法正常运行。 如果

frameProcessingChain
除了在此处分配一个值之外没有直接在项目中的任何地方使用,它还有什么作用?

swift publish-subscribe publisher subscriber anycancellable
1个回答
0
投票

如果frameProcessingChain除了在此处分配一个值之外没有直接在项目中的任何地方使用,它还有什么作用?

与任何变量一样,它保持其值不变。如果未分配管道,管道将不复存在,并且在发布者发布时不会出现。

© www.soinside.com 2019 - 2024. All rights reserved.