5 検知のレンダリング最適化

サンプルでは検知およびレンダリングの並列ポリシーが採用されています。

これは1つのスレッドで動作を検知し、別のスレッドで検知した動作をレンダリングすることを意味します。iOSの場合、カメラのコールバックキューで動作を直接検知します。検知した後で、動作を同期された別のキューで次のようにレンダリングします(一部のコードは省略されています。全コードを見たい場合は、サンプルを参照してください)。

- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection {

    //2 つのフレームをバッファー処理します。
    if (self.iBufferedCount >= 2) {
        return;
    }
    //動作を検知します。
    st_result_t iRet = st_mobile_human_action_detect(_hDetector,pBGRAImageIn,ST_PIX_FMT_BGRA8888,iWidth,iHeight,iBytesPerRow,stMobileRotate,self.iCurrentAction,&detectResult);
    self.iBufferedCount ++;
    CFRetain(pixelBuffer);
    //動作検知結果を別のスレッドでレンダリングするためにコピーします
    __block st_mobile_human_action_t newDetectResult;
    memset(&newDetectResult, 0, sizeof(st_mobile_human_action_t));
    copyHumanAction(&detectResult, &newDetectResult);
    //スレッドをレンダリングします
    dispatch_async(self.renderQueue, ^{
        //美化やスタンプなどの操作
        //コピーした動作の検知結果を解放します
        freeHumanAction(&newDetectResult);
        //結果をレンダリングします
        [self.glPreview renderTexture:textureResult];
        CFRelease(pixelBuffer);
        self.iBufferedCount --;
    });
}

copyHumanActionおよびfreeHumanActionメソッドの詳細については、サンプルを参照してください。

Last updated