当前位置: 首页>>代码示例>>C++>>正文


C++ cv::findContours方法代码示例

本文整理汇总了C++中cv::findContours方法的典型用法代码示例。如果您正苦于以下问题:C++ cv::findContours方法的具体用法?C++ cv::findContours怎么用?C++ cv::findContours使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cv的用法示例。


在下文中一共展示了cv::findContours方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: generalized_hough_transform

Point GHT::generalized_hough_transform(Mat image, vector<vector<Point> > contours, Point refPoint) {
	Point max;
	max.x = 0;
	max.y = 0;
	cvtColor(image, image, CV_RGB2GRAY);
	blur(image, image, Size(3, 3));
	Canny(image, image, 30, 70);
	//imshow("INPUT", image);

/*
	Mat ref = Mat::zeros( image.size(), CV_32FC3 );
	drawContours(ref, contours, 0, Scalar(255), CV_FILLED);
	imshow("REF", ref);
//*/
	if (_imageYsize == 0){
		set_image_sizes(image.clone());
		_data = new float*[_imageYsize];
		for (int i = 0; i < _imageYsize; i++){
			_data[i] = new float[_imageXsize];
		}

		for (int i = 0; i < _imageYsize; i++){
			for (int j = 0; j < _imageXsize; j++){
				_data[i][j] = 0.0f;
			}
		}
	}

	int voteX, voteY, imageX, imageY;
	findContours(image, _inputContours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE); // for contour finding

	for (int i = 0; (unsigned)i < _inputContours.size(); i++){
		for (int j = 0; (unsigned)j < _inputContours.at(i).size(); j++){
			imageX = _inputContours.at(i).at(j).x;
			imageY = _inputContours.at(i).at(j).y;
			for (int c = 0; (unsigned) c < contours.at(0).size(); c++){
				voteX = refPoint.x - contours.at(0).at(c).x;
				voteY = refPoint.y - contours.at(0).at(c).y;
				if (
					(imageX + voteX) >= 0
							&&
					(imageX + voteX) < _imageXsize
							&&
					(imageY + voteY) >= 0
							&&
					(imageY + voteY) < _imageYsize) {

					if (_data[imageY + voteY][imageX + voteX] < 1.0f){
						_data[imageY + voteY][imageX + voteX] = 1.0f;
					} else {
						_data[imageY + voteY][imageX + voteX] += 1.0f;
						if ((refPoint.x - imageX + voteX)*(refPoint.x - imageX + voteX) < 400){
							_data[imageY + voteY][imageX + voteX] += 2.0f;
						}
						if ((refPoint.y - imageY + voteY)*(refPoint.y - imageY + voteY) < 400){
							_data[imageY + voteY][imageX + voteX] += 2.0f;
						}
					}
				}
			}
		}
	}
	float maxVal = -1;

	for (int i = 0; i < _imageYsize; i++){
		for (int j = 0; j < _imageXsize; j++){
			if (_data[i][j] > 5.0f){
				if (maxVal < _data[i][j]){
					maxVal = _data[i][j];
					max.y = i;
					max.x = j;
				}
			}
			_data[i][j] = 0.0f;
		}
	}

	return max;
}
开发者ID:FizzyMobile,项目名称:objecttracking,代码行数:79,代码来源:GHT.cpp


注:本文中的cv::findContours方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。