我有两种方法:一种用于对CLAHE进行对比度校正,另一种用于对图像进行二值化。
我称之为的顺序是:1。CLAHE,2。Binarize
当我只使用一个时,它们都很好用。但是当我按照上面提到的顺序打电话时,我得到了这张照片:
我的CLAHE代码:
- (UIImage*)correctContrast:(UIImage*)image {
cv::Mat cvImage = [self cvMatFromUIImage:image];
cv::Mat grayImage;
cv::cvtColor(cvImage, grayImage, CV_BGR2GRAY);
cv::Mat contrastCorrectedImage;
cv::Ptr<cv::CLAHE> clahe = cv::createCLAHE();
clahe->setClipLimit(1.5);
clahe->apply(grayImage, contrastCorrectedImage);
UIImage* contrastCorrectedUIImage = [self UIImageFromCVMat:contrastCorrectedImage];
return contrastCorrectedUIImage;
}
对图像进行二值化:
- (UIImage*)binarize:(UIImage*)image {
cv::Mat cvImage = [self cvMatFromUIImage:image];
cv::Mat grayImage;
cv::cvtColor(cvImage, grayImage, CV_BGR2GRAY);
double MAX_THRESHOLD = 255;
double THRESHOLD_VALUE = 165;
cv::Mat binarizedImage;
cv::threshold(grayImage, binarizedImage, THRESHOLD_VALUE, MAX_THRESHOLD, CV_THRESH_BINARY);
UIImage* binarizedUIImage = [self UIImageFromCVMat:binarizedImage];
return binarizedUIImage;
}
以及我如何使用它们:
let contrastImage = self.openCV.correctContrast(uiImageCropped!)
let binarizedImage = self.openCV.binarize(contrastImage!)
self.image = binarizedImage
修改 输入图像只是一张普通的名片。