如何使用拟合椭圆函数及其角度获得坐标点(opencv)

时间:2015-10-31 04:47:21

标签: c++ opencv

在这里,我找到了找到椭圆的所有x,y坐标的轮廓方法,但我需要坐标和角度值。

cv::Mat binaryImg;
cv::threshold(grayImg, binaryImg, 100, 255, cv::THRESH_BINARY);
std::vector<std::vector<cv::Point> > contours;
findContours(binaryImg, contours, CV_RETR_TREE, CV_CHAIN_APPROX_NONE);
for(size_t i = 1; i < contours.size(); i++) {
std::vector<CvPoint> points;
if(contours[i].size() >= 5) {
cv::RotatedRect Ellipse = fitEllipse(contours[i]);
majoraxis = Ellipse.size.height;
minoraxis = Ellipse.size.width;
angle = Ellipse.angle;
xcenter=Ellipse.center.x;
ycenter=Ellipse.center.y;
for(unsigned int i=0;i<contours.size();i++){
   for(unsigned int j=0;j<contours[i].size();j++)
   {
       cout << "Point(x,y)=" << contours[i][j].x << "," << contours[i][j].y << endl;

   }}

这里是我的形象

here my image 上面的代码找到了轮廓x,y坐标点,但我需要从中心点开始的角度。它们的坐标点

1 个答案:

答案 0 :(得分:0)

您可以使用内置函数ellipse2Poly()