圖像處理——Edge Boxes邊緣檢測

前言

傳統的邊緣檢測對一些內容,色彩比較豐富的圖像,提取出來的邊緣並不理想,ECCV2014來自於微軟研究院的Piotr等人的《Edge Boxes: Locating Object Proposals from Edges》這個文章,採用的是純圖像的方法實現了目標檢測的算法,也是基於物體的邊緣分割。這個算法對邊緣的提取要好過傳統的canny算法。如果想要深入瞭解可以看大神的論文

Edge Boxes

1.檢測代碼

void edgebox(Mat &src,Mat &dst, modelInit &model, paraClass &o)
{
	Mat I = src.clone();
	assert(I.rows != 0 && I.cols != 0);

	clock_t begin = clock();
	model.opts.nms = 1;
	Mat I_resize;
	float shrink = 4;
	resize(I, I_resize, Size(), 1 / shrink, 1 / shrink);
	tuple<Mat, Mat, Mat, Mat> detect = edgesDetect(I_resize, model, 4);
	Mat E, O, unuse1, unuse2;
	tie(E, O, unuse1, unuse2) = detect;
	E = edgesNms(E, O, 2, 0, 1, model.opts.nThreads);
	Mat bbs;
	cout << 1 << endl;
	bbs = edgebox_main(E, O, o) * shrink;
	cout << "time:" << ((double)clock() - begin) / CLOCKS_PER_SEC << "s" << endl;

	I.copyTo(dst);


	//for top10 box scores

	for (int i = 0; i < model.opts.showboxnum; i++) {

		//draw the bbox
		Point2f p1(bbs.at<float>(i, 0), bbs.at<float>(i, 1));
		Point2f p2(bbs.at<float>(i, 0) + bbs.at<float>(i, 2), bbs.at<float>(i, 1) + bbs.at<float>(i, 3));
		Point2f p3(bbs.at<float>(i, 0), bbs.at<float>(i, 1) + bbs.at<float>(i, 3));
		Point2f p4(bbs.at<float>(i, 0) + bbs.at<float>(i, 2), bbs.at<float>(i, 1));


		int tlx = (int)bbs.at<float>(i, 0);
		int tly = (int)bbs.at<float>(i, 1);
		//brx may be bigger than I.cols-1
		//bry may be bigger than I.rows-1
		int brx = std::min((int)(bbs.at<float>(i, 0) + bbs.at<float>(i, 2)), I.cols - 1);
		int bry = std::min((int)(bbs.at<float>(i, 1) + bbs.at<float>(i, 3)), I.rows - 1);

		Mat box;
		box = I.colRange(tlx, brx).rowRange(tly, bry);

		rectangle(dst, p1, p2, Scalar(0, 255, 0), 1);
		Point2f ptext(bbs.at<float>(i, 0), bbs.at<float>(i, 1) - 3);
		putText(dst, to_string(bbs.at<float>(i, 4)), ptext, FONT_HERSHEY_SIMPLEX, 0.5, Scalar(0, 255, 0), 1);

	}
}

void  edgeDetection(Mat &src, Mat &dst, modelInit &model, paraClass &o)
{
	Mat I = src.clone();
	
	assert(I.rows != 0 && I.cols != 0);

	///clock_t begin = clock();
	model.opts.nms = 1;
	Mat I_resize;
	float shrink = 4;
	
	tuple<Mat, Mat, Mat, Mat> detect = edgesDetect(I, model, 4);
	Mat E, O, unuse1, unuse2;
	tie(E, O, unuse1, unuse2) = detect;
	E = edgesNms(E, O, 2, 0, 1, model.opts.nThreads);
	Mat bbs;
	bbs = edgebox_main(E, O, o) * shrink;

	double E_min, E_max;
	cv::minMaxLoc(E, &E_min, &E_max);
	dst = (E - E_min) / (E_max - E_min) * 255;
	dst.convertTo(dst, CV_8U);
}

2.運行效果
在這裏插入圖片描述
在這裏插入圖片描述
在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章