所以,即時通訊使用opencv捕獲文件,掃描並裁剪它。當房間裏沒有照明時,它完美地工作。當房間裏有一些燈光,桌子上有眩光並且文檔靠近它時,它也會將眩光視爲矩形的一部分。從照片中刪除眩光opencv
如何從照片中去除眩光?
下面是一個使用來獲得我想要的圖像的代碼IM:
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);
這裏講的是眩光IM的照片:
我發現的東西在inRange中使用,爲顏色找到合適的標量,並使用inpaint去除光線。這是一個代碼片段,但它總是崩潰,說它需要chanels的8位圖像。
Mat &image = *(Mat *) matAddrRgba;
Mat hsv, newImage, inpaintMask;
cv::Mat lower_red_hue_range;
inpaintMask = Mat::zeros(image.size(), CV_8U);
cvtColor(image, hsv, COLOR_BGR2HSV);
cv::inRange(hsv, cv::Scalar(0, 0, 215, 0), cv::Scalar(180, 255, 255, 0),
lower_red_hue_range);
image = lower_red_hue_range;
inpaint(image, lower_red_hue_range, newImage, 3, INPAINT_TELEA);
您可以嘗試與服用3-4個快照,從不同的角度,以克服眩光的桌子上的效果。 – ZdaR
如果你沒有回答答案,那麼你很難知道答案。 –
眩光與鏡頭眩光消除技術非常相似,並且簡單地說,它們添加到RGB色彩空間以使其接近最大值。這可能會很複雜,您可能需要使用空間過濾器來確保儘可能保持背景。對於這樣的事物,有一種洋蔥皮方法,從3x3矩陣開始,去除額外的眩光成分,並以洋蔥皮朝着中心移動。你可以運行它來查看它是否遵循眩光模式並將其刪除。 –