簡體   English   中英

OpenCV檢測變暗的矩形

[英]OpenCV detect darkened rectangle

我正在嘗試使用OpenCV來隔離半透明的深色矩形區域,該區域上覆蓋了許多文本。 這些矩形區域的大小和位置在窗口中可能會有所不同。 有沒有辦法檢測這些變暗的區域?

在此處輸入圖片說明

也許在顯示黑暗區域疊加層之前進行一些比較操作並將其與幀進行比較會比較容易?

這應該為您提供基於兩個圖像的所有邊界框。

#include <cv.h>
#include <highgui.h>

using namespace cv;

Mat im = imread("original.jpg");
Mat im2 = imread("darkened.jpg");

Mat diff_im = im - im2;

Mat diff_im_binary;
threshold(diff_im, diff_im_binary, 30, 255, THRESH_BINARY);

findContours(diff_im_binary, contours, hierarchy, CV_RETR_TREE,  CV_CHAIN_APPROX_SIMPLE, Point(0, 0) );

 /// Approximate contours to polygons + get bounding rects and circles
 vector<vector<Point> > contours_poly( contours.size() );
 vector<Rect> boundRect( contours.size() );
 vector<Point2f>center( contours.size() );
 vector<float>radius( contours.size() );

 for( int i = 0; i < contours.size(); i++ )
 { 
     approxPolyDP( Mat(contours[i]), contours_poly[i], 3, true );
     boundRect[i] = boundingRect( Mat(contours_poly[i]) );
 }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM