目前我有以下内容:
[cameraFeed] - > [gaussianBlur] - > [sobel] - > [brightnessThreshold] - > [rawDataOutput]
rawDataOuput我想将它传递给OpenCV findCountours函数。不幸的是,我无法找到正确的方法来做到这一点。以下是获取rawDataOuput并应将其传递给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];
}];
答案 0 :(得分:0)
尝试将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);