Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
OpenCV:Camshift的方向角_Opencv - Fatal编程技术网

OpenCV:Camshift的方向角

OpenCV:Camshift的方向角,opencv,Opencv,最近,我试图理解Camshift在方向角(θ)上的代码 在Camshift的参考文献“用于感知用户界面的计算机视觉人脸跟踪”中,本文中的方向角与OpenCV中的代码不同 The code in the OpenCV is as follows: cvCamShift( const void* imgProb, CvRect windowIn,CvTermCriteria criteria, CvConnectedComp* _comp,CvBox2D* box ) { const in

最近,我试图理解Camshift在方向角(θ)上的代码

在Camshift的参考文献“用于感知用户界面的计算机视觉人脸跟踪”中,本文中的方向角与OpenCV中的代码不同

The code in the OpenCV is as follows:

cvCamShift( const void* imgProb, CvRect windowIn,CvTermCriteria criteria, CvConnectedComp* _comp,CvBox2D* box )
{
    const int TOLERANCE = 10;
    CvMoments moments;
    double m00 = 0, m10, m01, mu20, mu11, mu02, inv_m00;
    double a, b, c, xc, yc;
    double rotate_a, rotate_c;
    double theta = 0, square;
    double cs, sn;
    double length = 0, width = 0;
    int itersUsed = 0;
    CvConnectedComp comp;
    CvMat  cur_win, stub, *mat = (CvMat*)imgProb;
comp.rect = windowIn;

mat = cvGetMat( mat, &stub );

itersUsed = cvMeanShift( mat, windowIn, criteria, &comp );
windowIn = comp.rect;

windowIn.x -= TOLERANCE;
if( windowIn.x < 0 )
    windowIn.x = 0;

windowIn.y -= TOLERANCE;
if( windowIn.y < 0 )
    windowIn.y = 0;

windowIn.width += 2 * TOLERANCE;
if( windowIn.x + windowIn.width > mat->width )
    windowIn.width = mat->width - windowIn.x;

windowIn.height += 2 * TOLERANCE;
if( windowIn.y + windowIn.height > mat->height )
    windowIn.height = mat->height - windowIn.y;

cvGetSubRect( mat, &cur_win, windowIn );

/* Calculating moments in new center mass */
cvMoments( &cur_win, &moments );

m00 = moments.m00;
m10 = moments.m10;
m01 = moments.m01;
mu11 = moments.mu11;
mu20 = moments.mu20;
mu02 = moments.mu02;

if( fabs(m00) < DBL_EPSILON )
    return -1;

inv_m00 = 1. / m00;
xc = cvRound( m10 * inv_m00 + windowIn.x );
yc = cvRound( m01 * inv_m00 + windowIn.y );
a = mu20 * inv_m00;
b = mu11 * inv_m00;
c = mu02 * inv_m00;

/* Calculating width & height */
square = sqrt( 4 * b * b + (a - c) * (a - c) );

/* Calculating orientation */
theta = atan2( 2 * b, a - c + square );//Here, i confused!!!!!
/* Calculating width & length of figure */
cs = cos( theta );
sn = sin( theta );

rotate_a = cs * cs * mu20 + 2 * cs * sn * mu11 + sn * sn * mu02;
rotate_c = sn * sn * mu20 - 2 * cs * sn * mu11 + cs * cs * mu02;
length = sqrt( rotate_a * inv_m00 ) * 4;
width = sqrt( rotate_c * inv_m00 ) * 4;

/* In case, when tetta is 0 or 1.57... the Length & Width may be exchanged */
if( length < width )
{
    double t;

    CV_SWAP( length, width, t );
    CV_SWAP( cs, sn, t );
    theta = CV_PI*0.5 - theta;
}

/* Saving results */
if( _comp || box )
{
    int t0, t1;
    int _xc = cvRound( xc );
    int _yc = cvRound( yc );

    t0 = cvRound( fabs( length * cs ));
    t1 = cvRound( fabs( width * sn ));

    t0 = MAX( t0, t1 ) + 2;
    comp.rect.width = MIN( t0, (mat->width - _xc) * 2 );

    t0 = cvRound( fabs( length * sn ));
    t1 = cvRound( fabs( width * cs ));

    t0 = MAX( t0, t1 ) + 2;
    comp.rect.height = MIN( t0, (mat->height - _yc) * 2 );

    comp.rect.x = MAX( 0, _xc - comp.rect.width / 2 );
    comp.rect.y = MAX( 0, _yc - comp.rect.height / 2 );

    comp.rect.width = MIN( mat->width - comp.rect.x, comp.rect.width );
    comp.rect.height = MIN( mat->height - comp.rect.y, comp.rect.height );
    comp.area = (float) m00;
}

if( _comp )
    *_comp = comp;

if( box )
{
    box->size.height = (float)length;
    box->size.width = (float)width;
    box->angle = (float)((CV_PI*0.5+theta)*180./CV_PI);
    while(box->angle < 0)
        box->angle += 360;
    while(box->angle >= 360)
        box->angle -= 360;
    if(box->angle >= 180)
        box->angle -= 180;
    box->center = cvPoint2D32f( comp.rect.x + comp.rect.width*0.5f,
        comp.rect.y + comp.rect.height*0.5f);
}

return itersUsed;
OpenCV中的代码如下:
CVCAMSIFT(常量无效*imgProb,CvRect窗口输入,CVTERM标准,CvConnectedComp*_comp,CvBox2D*box)
{
常数int公差=10;
瞬间;
双m00=0,m10,m01,mu20,mu11,mu02,inv_m00;
双a、b、c、xc、yc;
双旋转a,旋转c;
双θ=0,平方;
双cs,sn;
双倍长度=0,宽度=0;
int itersUsed=0;
CvConnectedComp comp;
CvMat cur_win,stub,*mat=(CvMat*)imgProb;
comp.rect=windowIn;
mat=cvGetMat(mat和存根);
ITERSUESED=cvMeanShift(材料、窗口、标准和组件);
windowIn=comp.rect;
windowIn.x-=公差;
if(windowIn.x<0)
windowIn.x=0;
windowIn.y-=公差;
如果(窗口输入y<0)
windowIn.y=0;
窗宽+=2*公差;
如果(windowIn.x+windowIn.width>mat->width)
windowIn.width=mat->width-windowIn.x;
窗高+=2*公差;
if(windowIn.y+windowIn.height>mat->height)
windowIn.height=mat->height-windowIn.y;
cvGetSubRect(mat和cur_win、windowIn);
/*计算新质心中的力矩*/
cvMoments(&cur_-win,&moments);
m00=力矩。m00;
m10=力矩。m10;
m01=力矩。m01;
mu11=力矩。mu11;
mu20=力矩。mu20;
mu02=力矩。mu02;
if(fabs(m00)宽度-xc)*2);
t0=cvRound(晶圆长度*sn));
t1=cvRound(晶圆宽度*cs));
t0=最大值(t0,t1)+2;
组件垂直高度=最小值(t0,(材料->高度-_yc)*2);
组件矩形x=最大值(0,xc-组件矩形宽度/2);
组件校正y=最大值(0,_yc-组件校正高度/2);
comp.rect.width=MIN(材料->宽度-comp.rect.x,comp.rect.width);
comp.rect.height=MIN(材料->高度-comp.rect.y,comp.rect.height);
组件面积=(浮动)m00;
}
如果(_comp)
*_comp=comp;
如果(方框)
{
框->size.height=(浮动)长度;
框->size.width=(浮动)宽度;
长方体->角度=(浮动)((CV_π*0.5+θ)*180./CV_π);
同时(框->角度<0)
框->角度+=360;
同时(框->角度>=360)
框->角度-=360;
如果(框->角度>=180)
框->角度-=180;
框->中心=cvPoint2D32f(复合矩形x+复合矩形宽度*0.5f,
组件矩形y+组件矩形高度*0.5f);
}
返回已使用的ITERS;
}

我的目标是根据三角函数理论计算长度轴上的两点,所以我需要知道方向角和质心,现在我可以得到质心

根据《机器人视觉》(Robot Vision)一文,方向角被视为x轴和半长轴(namaly,长度)之间的角度,该文是《用于感知用户界面的计算机视觉人脸跟踪》的参考文献。然而,在OpenCV中,x轴和y轴的方向分别指向右侧和下方,这与纸张不同,那么如何理解方向角呢?变化如何


谢谢你阅读我的问题。祝你今天愉快

你找到电源了吗?我对此也感到困惑。