【发布时间】:2017-12-03 10:48:21
【问题描述】:
您好,我使用 AVFoundation 捕获图像,无法检测到模糊图像。
我已尝试以下链接中的建议解决方案: OpenCV with Laplacian formula to detect image is blur or not in iOS 但它仅适用于使用默认 cameraPicker 捕获的图像。
使用:
cv::Mat finalImage;
cv::Mat matImage = [self convertUIImageToCVMat:image];
cv::Mat matImageGrey;
cv::cvtColor(matImage, matImageGrey, CV_RGBA2GRAY);
matImage.release();
cv::Mat newEX;
const int MEDIAN_BLUR_FILTER_SIZE = 15; // odd number
cv::medianBlur(matImageGrey, newEX, MEDIAN_BLUR_FILTER_SIZE);
matImageGrey.release();
cv::Mat laplacianImage;
cv::Laplacian(newEX, laplacianImage, CV_8U); // CV_8U
newEX.release();
cv::Mat laplacianImage8bit;
laplacianImage.convertTo(laplacianImage8bit, CV_8UC1);
laplacianImage.release();
cv::cvtColor(laplacianImage8bit,finalImage,CV_GRAY2BGRA);
int rows = finalImage.rows;
int cols= finalImage.cols;
int maxLap = -16777216;
unsigned char *pixels = laplacianImage8bit.data;
for (int i = 0; i < (laplacianImage8bit.elemSize()*laplacianImage8bit.total()); i++) {
if (pixels[i] > maxLap) {
maxLap = pixels[i];
}
}
pixels=NULL;
finalImage.release();
BOOL isBlur = (maxLap <= kBlurThreshhold)? YES : NO;
NSLog(@"Max: %d, Cols: %d, Rows: %d", maxLap, cols, rows);
请注意,我必须以 1500 X 1500 分辨率调整图像大小。在根据要求对其应用模糊检测之前。一个有用的解决方案将不胜感激。
谢谢。
【问题讨论】:
标签: ios objective-c iphone opencv