本文整理汇总了C++中Energy::minimize方法的典型用法代码示例。如果您正苦于以下问题:C++ Energy::minimize方法的具体用法?C++ Energy::minimize怎么用?C++ Energy::minimize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Energy
的用法示例。
在下文中一共展示了Energy::minimize方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: expandOnLabel
//.........这里部分代码省略.........
// First set up horizontal links
for ( int y = startY; y <= endY; y++ )
for ( int x = startX+1; x <=endX; x++){
int oldLabelPix = labeling[x+y*width];
int oldLabelNeighbPix = labeling[x-1+y*width];
Value E00,E01,E10,E11=0;
if ( oldLabelPix != oldLabelNeighbPix )
E00 = horizWeights[x-1+y*width];
else E00 = 0;
if ( oldLabelNeighbPix != label )
E01 = horizWeights[x-1+y*width];
else E01 = 0;
if ( label != oldLabelPix )
E10 = horizWeights[x-1+y*width];
else E10 = 0;
e->add_term2(variables[(x-startX)-1+(y-startY)*blockWidth],variables[(x-startX)+(y-startY)*blockWidth],E00,E01,E10,E11);
}
// Next set up vertical links
for ( int y = startY+1; y <= endY; y++ )
for ( int x = startX; x <=endX; x++){
int oldLabelPix = labeling[x+y*width];
int oldLabelNeighbPix = labeling[x+(y-1)*width];
Value E00,E01,E10,E11=0;
if ( oldLabelPix != oldLabelNeighbPix )
E00 = vertWeights[x+(y-1)*width];
else E00 = 0;
if ( oldLabelNeighbPix != label )
E01 = vertWeights[x+(y-1)*width];
else E01 = 0;
if ( label != oldLabelPix )
E10 = vertWeights[x+(y-1)*width];
else E10 = 0;
e->add_term2(variables[(x-startX)+(y-startY-1)*blockWidth],variables[(x-startX)+(y-startY)*blockWidth],E00,E01,E10,E11);
}
// Next set up diagonal links
float SQRT_2= 1/sqrt(2.0);
for ( int y = startY+1; y <= endY; y++ )
for ( int x = startX+1; x <=endX; x++){
int oldLabelPix = labeling[x+y*width];
int oldLabelNeighbPix = labeling[x-1+(y-1)*width];
Value E00,E01,E10,E11=0;
if ( oldLabelPix != oldLabelNeighbPix )
E00 = SQRT_2*diag1Weights[x-1+(y-1)*width];
else E00 = 0;
if ( oldLabelNeighbPix != label )
E01 = SQRT_2*diag1Weights[x-1+(y-1)*width];
else E01 = 0;
if ( label != oldLabelPix )
E10 = SQRT_2*diag1Weights[x-1+(y-1)*width];
else E10 = 0;
e->add_term2(variables[(x-startX)-1+(y-startY-1)*blockWidth],variables[(x-startX)+(y-startY)*blockWidth],E00,E01,E10,E11);
}
// More diagonal links
for ( int y = startY+1; y <= endY; y++ )
for ( int x = startX; x <=endX-1; x++){
int oldLabelPix = labeling[x+y*width];
int oldLabelNeighbPix = labeling[(x+1)+(y-1)*width];
Value E00,E01,E10,E11=0;
if ( oldLabelPix != oldLabelNeighbPix )
E00 = SQRT_2*diag2Weights[(x+1)+(y-1)*width];
else E00 = 0;
if ( oldLabelNeighbPix != label )
E01 = SQRT_2*diag2Weights[(x+1)+(y-1)*width];
else E01 = 0;
if ( label != oldLabelPix )
E10 = SQRT_2*diag2Weights[(x+1)+(y-1)*width];
else E10 = 0;
e->add_term2(variables[(x-startX+1)+(y-startY-1)*blockWidth],variables[(x-startX)+(y-startY)*blockWidth],E00,E01,E10,E11);
}
e->minimize();
for ( int y = startY; y <= endY; y++ )
for ( int x = startX; x <= endX; x++){
if ( e->get_var(variables[(x-startX)+(y-startY)*blockWidth]) != 0 )
{
if ( labeling[x+y*width] != label ){
labeling[x+y*width] = label;
changeMaskNew[x+y*width] = 1;
changeMask[x+y*width] = 1;
}
}
}
delete e;
}