如何将GPUImage rawDataOutput的输出馈送到OpenCV findCountours函数



目前我有以下内容:

[cameraFeed] -> [gaussianBlur] -> [sobel] -> [luminanceThreshold] -> [rawDataOutput]

rawdataoutput我想把它传递给OpenCV findCountours函数。不幸的是,我想不出正确的方法来做这件事。以下是获取rawdataoutput的回调块,它应该将其传递给OpenCV函数,但它不起作用。我假设涉及到一些事情,例如将GPUImage给出的BGRA图像转换为CV_8UC1(单通道),但我无法将它们弄清楚。一些帮助将非常感激,谢谢!

    // Callback on raw data output
    __weak GPUImageRawDataOutput *weakOutput = rawDataOutput;
    [rawDataOutput setNewFrameAvailableBlock:^{
        [weakOutput lockFramebufferForReading];
        GLubyte *outputBytes = [weakOutput rawBytesForImage];
        NSInteger bytesPerRow = [weakOutput bytesPerRowInOutput];
        // OpenCV stuff
        int width = videoSize.width;
        int height = videoSize.height;
        size_t step = bytesPerRow;
        cv::Mat mat(height, width, CV_8UC1, outputBytes, step); // outputBytes should be converted to type CV_8UC1
        cv::Mat workingCopy = mat.clone();
        // PASS mat TO OPENCV FUNCTION!!!
        [weakOutput unlockFramebufferAfterReading];
        // Update rawDataInput if we want to display the result
        [rawDataInput updateDataFromBytes:outputBytes size:videoSize];
        [rawDataInput processData];
    }];

尝试将CV_8UC1更改为CV_8UC4,然后转换为灰色。在代码中替换行

cv::Mat mat(height, width, CV_8UC1, outputBytes, step);
cv::Mat workingCopy = mat.clone();

cv::Mat mat(height, width, CV_8UC4, outputBytes, step);
cv::Mat workingCopy;
cv::cvtColor(mat, workingCopy, CV_RGBA2GRAY);

相关内容

  • 没有找到相关文章

最新更新