티스토리 뷰

#include <iostream>
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/core.hpp>
#include <opencv2/features2d.hpp>
#include <vector>

using namespace std;
using namespace cv;


int main() {
    Mat image = imread("building.jpg", IMREAD_GRAYSCALE);

	// basic MSER detector
	Ptr<MSER> ptrMSER =
		MSER::create(5,		// delta value for local detection
			200,	// min acceptable area
			2000);	// max acceptable area

	// vector of point sets
	vector<vector<Point>> points;
	// vector of rectangles
	vector<Rect> rects;
	// detect MSER features
	ptrMSER->detectRegions(image, points, rects);

	cout << points.size() << " MSERs detected" << endl;

	// create white image
	Mat output(image.size(), CV_8UC3);
	output = Scalar(255, 255, 255);

	// OpenCV random number generator
	RNG rng;

	// Display the MSERs in color areas 
	// for each detected feature
	// reverse order to display the larger MSER first
	for (vector<vector<Point>>::reverse_iterator it = points.rbegin();
		it != points.rend(); ++it) {

		// generate a random color
		Vec3b c(rng.uniform(0, 254), rng.uniform(0, 254), rng.uniform(0, 254));
		// for each point in MSER set
		for (vector<Point>::iterator itPts = it->begin();
			itPts != it->end(); ++itPts) {
			// do not overwrite MSER pixels
			if (output.at<Vec3b>(*itPts)[0] == 255) {
				output.at<Vec3b>(*itPts) = c;
			}
		}
	}

	imwrite("mser.bmp", output);
}

'영상처리 > OpenCV' 카테고리의 다른 글

19. Canny operator  (0) 2019.06.12
18. Bilateral filter  (0) 2019.06.02
16. watershed transformation  (0) 2019.05.28
15. Morphological operations  (0) 2019.05.26
14. Integral image  (0) 2019.05.21
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함