如何绘制椭圆轴

时间:2015-10-30 09:29:13

标签: c++ opencv

我正在使用Opencv和C ++的fitellipse,并且我得到了这些值:

/// Find the rotated rectangles and ellipses for each contour
vector<RotatedRect> minRect( contours.size() );
vector<RotatedRect> minEllipse( contours.size() );

for( int i = 0; i < contours.size(); i++ )
{
   minRect[i] = minAreaRect( Mat(contours[i]) );

   if( contours[i].size() > 5 )
      minEllipse[i] = fitEllipse( Mat(contours[i]) );

   // ...
}

float xc    = minEllipse[element].center.x;
float yc    = minEllipse[element].center.y;
float a     = minEllipse[element].size.width  / 2;   
float b     = minEllipse[element].size.height / 2;
float theta = minEllipse[element].angle; 

但是使用这些值,我如何绘制椭圆的轴,例如下面的椭圆? enter image description here

注意:元素是存储在minEllipse中的椭圆。

3 个答案:

答案 0 :(得分:4)

您可以使用$(function () { $('#tempactgraph').highcharts({ chart: { zoomType: 'xy' }, title: { text: 'Temperature & Activity Monitoring ' }, subtitle: { text: 'Source: Cowlar Sensors' }, xAxis: [{ categories: timestamp, crosshair: true }], yAxis: [{ // Primary yAxis labels: { format: '{value}°C', style: { color: Highcharts.getOptions().colors[1] } }, title: { text: 'Temperature', style: { color: Highcharts.getOptions().colors[1] } } }, { // Secondary yAxis title: { text: 'Activity', style: { color: Highcharts.getOptions().colors[0] } }, labels: { format: '{value} xx', style: { color: Highcharts.getOptions().colors[0] } }, opposite: true }], tooltip: { shared: true }, legend: { layout: 'vertical', align: 'left', x: 120, verticalAlign: 'top', y: 100, floating: true, backgroundColor: (Highcharts.theme && Highcharts.theme.legendBackgroundColor) || '#FFFFFF' }, series: [{ name: 'Activities', type: 'spline', connectNulls: 1, yAxis: 1, data: act, tooltip: { valueSuffix: ' xx' } }, { name: 'Temperature', type: 'spline', connectNulls: 1, data: temps, tooltip: { valueSuffix: '°C' } }] }); }); 获取旋转的边界矩形的四个角,如here所述。

然后你只需要计算矩形每一边的两个点的平均值来得到轴的端点......

minEllipse[element].points

答案 1 :(得分:3)

您可能正在寻找这些公式:

ct = cos(theta)
st = sin(theta)

LongAxix0.x = xc - a*ct
LongAxis0.y = yc - a*st
LongAxis1.x = xc + a*ct
LongAxix1.y = yc + a*st

ShortAxix0.x = xc - b*st
ShortAxix0.y = yc + b*ct
ShortAxis1.x = xc + b*st
ShortAxix2.y = yc - b*ct

答案 2 :(得分:0)

  

但是使用这些值,我如何绘制椭圆的轴?

椭圆的轴穿过其中心:

float xc = minEllipse[element].center.x;
float yc = minEllipse[element].center.y;

轴的起点和终点可以偏离由椭圆的宽度和高度定义的中心,即:

// horizontal axis start/ end point

// coordinates
int HxStart = xc - size.width  / 2;
int HyStart = yc;

int HxEnd = xc + size.width  / 2;
int HyEnd = yc;

// points
Point Hstart(HxStart, HyStart);
Point Hend(HxEnd, HyEnd);

// horizontal axis
Line horizontalAxis(Hstart, Hend);

// vertical axis start/ end point
int VxStart = xc;
int VyStart = yc - size.height  / 2;

int VxEnd = xc;
int VyEnd = yc + size.height  / 2;

// ----//----

现在,您可以在椭圆中心周围以提供的角度theta rotate轴(上面的点)。

有了上述内容并且知道如何构造一条线,你可以在任何给定的角度theta建立两个轴。