Due to printing, especially oil printing rather than laser printing, the printing quality may be poor. In addition, uneven filling by students may also lead to similar results. After scanning, the areas that should have been solid rectangles become regions composed of noise points.
Positioning block may like this:
Opt question ans blocks may like this:
This situation can be addressed by filling in small areas after contour search or by directly eliminating interference through closing operations.
Select the size of the structure as needed,Here, a 9*9 structure is used outside.
Mat kernel = getStructuringElement(MORPH_RECT, Size(9, 9));
Mat closed;
morphologyEx(binary, closed, MORPH_CLOSE, kernel);
Result img:
However, due to the contamination around the positioning block, it may also cause some new problems, resulting in the rectangular shape of the positioning block being larger than expected.
Red rect is the detected rect shape of the positioning block, which is larger than expected,the blue one.
Here, the open operation is adopted to eliminate the interfering items that extend outwards. Of course, an inward search method can also be used here to remove the black borders around the white target rectangle.
Here, we employ a 5*5 structure to perform the opening operation.
Mat kernel2 = getStructuringElement(MORPH_RECT, Size(5, 5));
Mat opened;
morphologyEx(closed, opened, MORPH_OPEN, kernel);
binary = opened.clone();
Here , result:
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。