因此,我使用opencv捕获文档,扫描并裁剪文档.当房间里没有灯光时,它可以很好地工作.当房间里有一些灯光,桌子上有眩光并且文件靠近它时,它也会抓住眩光作为矩形的一部分.
如何从照片中消除眩光?
这是我用来获取我想要的图像的代码:
Mat &image = *(Mat *) matAddrRgba;
Rect bounding_rect;
Mat thr(image.rows, image.cols, CV_8UC1);
cvtColor(image, thr, CV_BGR2GRAY); //Convert to gray
threshold(thr, thr, 150, 255, THRESH_BINARY + THRESH_OTSU); //Threshold the gray
vector<vector<Point> > contours; // Vector for storing contour
vector<Vec4i> hierarchy;
findContours(thr, contours, hierarchy, CV_RETR_CCOMP,
CV_CHAIN_APPROX_SIMPLE); // Find the contours in the image
sort(contours.begin(), contours.end(),
compareContourAreas); //Store the index of largest contour
bounding_rect = boundingRect(contours[0]);
rectangle(image, bounding_rect, Scalar(250, 250, 250), 5);
Run Code Online (Sandbox Code Playgroud)
这是我正在谈论的眩光照片:
我发现的东西是使用inRange,找到适当的颜色标量,我们可以去除光线.这是一个代码片段,但它始终崩溃说它需要8位图像与chanels.
Mat &image = *(Mat *) matAddrRgba;
Mat …Run Code Online (Sandbox Code Playgroud)