Detecting a rectangular bright area in an image using OpenCv

Earlier, I asked the question Marking a point of interest in an image using C ++ . I used the same solution and got the desired point using the adaptive threshold and Blog Detection Algorithm (Growing Regions). I have an original source shape where I want to detect a rectangular area in the center.

Original Image:

Original image. But after I used the algorithm, I got something like this (details are visible if you open it in a new tab)

Tagged Image:

enter image description herewhere, in addition to the rectangular area, luminous light spots are also visible. I used two-way filtering, but still I can not detect the rectangular area. But this algorithm works for a night image where the background is darker than expected.

Can someone tell me if the same algorithm is sufficient with some changes or if any other effective methods are available.

thank

+5
source share
2 answers

Using a simple combination of blur and threshold, I managed to get this result (modified for viewing):

rlkJM.jpg

After that, using erosion and the squares.cpp method (which is a sample from OpenCV) produces:

TWNOL.jpg

, : . , , ( ) .

:

Mat img = imread(argv[1]);

    // Blur
Mat new_img = img.clone();
medianBlur(new_img, new_img, 5);

// Perform threshold
double thres = 210;
double color = 255;
threshold(new_img, new_img, thres, color, CV_THRESH_BINARY);
imwrite("thres.png", new_img);

// Execute erosion to improve the detection
int erosion_size = 4;   
Mat element = getStructuringElement(MORPH_CROSS,
                                   Size(2 * erosion_size + 1, 2 * erosion_size + 1),
                                   Point(erosion_size, erosion_size) );
erode(new_img, new_img, element);
imwrite("erode.png", new_img);

vector<vector<Point> > squares;
find_squares(new_img, squares);
std::cout << "squares: " << squares.size() << std::endl;

draw_squares(img, squares);

imwrite("area.png", img);

find_squares() , . , , squares.size() 3.

4 (X, Y), OpenCV vector<Point>, X Y.

squares , :

1st ------ 4th
 |          |
 |          |
 |          |
2nd ------ 3rd

, , , Y 1- 4- :

for (int i = 0; i < squares.size(); i++)
{
    for (int j = 0; j < squares[i].size(); j++)
    {
    //  std::cout << "# " << i << " " << squares[i][j].x << ","<< squares[i][j].y << std::endl;
        if (j == 0 || j == 3)
            squares[i][j].y = 0;
    }
}

YtrbI.jpg

+4

, ,

  • , ,

  • "code"

  • .

. , .

+1