【发布时间】:2020-01-31 19:07:43
【问题描述】:
我在 c++/Objective C 项目中使用 OpenCV 3.4.6,并给出了一个带有负矩形区域的图像,如下所示:
我应该检测那些负面区域,将它们反转,最后得到原始图像。
我尝试使用findContours,增强原始图像的对比度或添加阈值,但未检测到矩形。 p>
这是我尝试过的测试之一:
Mat contrasted = [self enhanceContrastTo: matOriginal];
Mat thresholded;
threshold(contrasted, thresholded, 125, 241, THRESH_BINARY);
std::vector<std::vector<cv::Point> > contours;
std::vector<Vec4i> hierarchy;
findContours( thresholded, contours, hierarchy, CV_RETR_EXTERNAL, CV_RETR_TREE );
/* contrast method */
+(Mat)enhanceContrastTo:(Mat)image {
cv::Mat lab_image;
cv::cvtColor(image, lab_image, CV_BGR2Lab);
// Extract the L channel
std::vector<cv::Mat> lab_planes(3);
cv::split(lab_image, lab_planes); // now we have the L image in lab_planes[0]
// apply the CLAHE algorithm to the L channel
cv::Ptr<cv::CLAHE> clahe = cv::createCLAHE();
// clahe->setClipLimit(4);
clahe->setClipLimit(3);
cv::Mat dst;
clahe->apply(lab_planes[0], dst);
// Merge the the color planes back into an Lab image
dst.copyTo(lab_planes[0]);
cv::merge(lab_planes, lab_image);
// convert back to RGB
cv::Mat image_clahe;
cv::cvtColor(lab_image, image_clahe, CV_Lab2BGR);
return image_clahe;
}
矩形是肉眼清晰可见的,希望opencv也能识别出来但是不知道怎么识别。
有什么想法吗?
谢谢
【问题讨论】:
-
我也想知道解决方法。希望有人能帮忙!
-
我最初的想法是使用离散傅立叶变换:docs.opencv.org/3.4.6/d8/d01/…。我实际上从未有过使用此功能的用例,但我想这些特定点在频域中应该很明显。如果您尝试一下,请告诉我。
-
感谢您的回复!我按照链接https://docs.opencv.org/3.4.6/d8/d01/tutorial_discrete_fourier_transform.html 中显示的代码进行操作,但是我得到了一个我无法解释的结果,也许我做错了什么,这是我的代码:Code,这是结果:Result
标签: c++ objective-c opencv image-processing