答案 0 :(得分:1)
在您发布的link中,您可以在此处找到图片的中心:
/// Get the mass centers:
vector<Point2f> mc( contours.size() );
for( int i = 0; i < contours.size(); i++ )
{ mc[i] = Point2f( mu[i].m10/mu[i].m00 , mu[i].m01/mu[i].m00 ); }
您可以像这样找到图片的中心:
#include "opencv2\opencv.hpp"
using namespace cv;
int main()
{
Mat1b gray = imread("path_to_image", IMREAD_GRAYSCALE);
Moments mu = moments(gray, true);
Point center;
center.x = mu.m10 / mu.m00;
center.y = mu.m01 / mu.m00;
Mat3b res;
cvtColor(gray, res, CV_GRAY2BGR);
circle(res, center, 2, Scalar(0,0,255));
imshow("Result", res);
waitKey();
return 0;
}
生成的图像是: