A
Anna Smidt
Thanks for the help so far.
I have some problems left. One of them is an undeclared identifier, but
it's unclear to me why the compiler fights with me. It says
"iter: undeclared identifier"
I thought that the
identifier was clear: "int", or is int just the declaration, and the
identifier is something else?
Thanks a lot.
Anna
//============================================================================
int AAM_IC::Fit(const IplImage* image, AAM_Shape& Shape,
int max_iter /* = 30 */, bool showprocess /* = false */)
{
//initialize some stuff
double t = (double)cvGetTickCount();
CvMat p; cvGetCols(__search_pq, &p, 4, 4+__shape.nModes());
double e1(1e100), e2;
Shape.Point2Mat(__current_s);
const CvMat* A0 = __texture.GetMean();
SetAllParamsZero();
__shape.CalcParams(__current_s, __search_pq);
IplImage* Drawimg = 0;
char filename[100];
if(showprocess){
Drawimg = cvCreateImage(cvGetSize(image), image->depth,
image->nChannels);
mkdir("result");
cvCopy(image, Drawimg);
Draw(Drawimg, 2);
sprintf(filename, "result/Init.jpg");
cvSaveImage(filename, Drawimg);
}
for(int iter = 0; iter < max_iter; iter++)
{
//check the current shape
if(!AAM_IC::IsShapeWithinImage(__current_s, image->width, image->height)){
fprintf(stderr, "ERROR(%s, %d): Shape out of image\n",
__FILE__, __LINE__);
return iter;
}
//warp image to template image A0
__paw.FasterGetWarpTextureFromMatShape(__current_s, image, __warp_t,
true);
AAM_TDM::AlignTextureToRef(A0, __warp_t);
//calculate error image
cvSub(__warp_t, A0, __error_t);
if(showprocess){
cvCopy(image, Drawimg);
Draw(Drawimg, 2);
sprintf(filename, "result/Iter-%02d.jpg", iter+1);
cvSaveImage(filename, Drawimg);
}
//check for texture divergence
e2 = cvNorm(__error_t);
if(e2 < 0.01 || (iter>max_iter/3&&fabs(e2-e1)<0.01*e1)) break;
e1 = e2;
//1. calculate dot product of modified steepest descent images
// with error image
//2. calculate delta q and delta p by multiplying by inverse Hessian.
//In summary: we calculate parameters update
cvGEMM(__error_t, __G, 1, NULL, 1, __delta_pq, CV_GEMM_B_T);
//apply inverse compositional algorithm to update parameters
InverseCompose(__delta_pq, __current_s, __update_s);
//smooth shape
cvAddWeighted(__current_s, 0.4, __update_s, 0.6, 0, __update_s);
//update parameters
__shape.CalcParams(__update_s, __search_pq);
//calculate constrained new shape
__shape.CalcShape(__search_pq, __update_s);
//check for shape convergence
cvSub(__current_s, __update_s, __delta_s);
if(/*cvNorm(__delta_s)<0.01*/cvNorm(__delta_s, 0, CV_C) < 0.25) break;
else cvCopy(__update_s, __current_s);
}
Shape.Mat2Point(__current_s);
t = ((double)cvGetTickCount()-t)/(cvGetTickFrequency()*1000.);
printf("AAM IC Fitting time cost %.3f millisec\n", t);
cvReleaseImage(&Drawimg);
return iter;
}
I have some problems left. One of them is an undeclared identifier, but
it's unclear to me why the compiler fights with me. It says
"iter: undeclared identifier"
I thought that the
identifier was clear: "int", or is int just the declaration, and the
identifier is something else?
Thanks a lot.
Anna
//============================================================================
int AAM_IC::Fit(const IplImage* image, AAM_Shape& Shape,
int max_iter /* = 30 */, bool showprocess /* = false */)
{
//initialize some stuff
double t = (double)cvGetTickCount();
CvMat p; cvGetCols(__search_pq, &p, 4, 4+__shape.nModes());
double e1(1e100), e2;
Shape.Point2Mat(__current_s);
const CvMat* A0 = __texture.GetMean();
SetAllParamsZero();
__shape.CalcParams(__current_s, __search_pq);
IplImage* Drawimg = 0;
char filename[100];
if(showprocess){
Drawimg = cvCreateImage(cvGetSize(image), image->depth,
image->nChannels);
mkdir("result");
cvCopy(image, Drawimg);
Draw(Drawimg, 2);
sprintf(filename, "result/Init.jpg");
cvSaveImage(filename, Drawimg);
}
for(int iter = 0; iter < max_iter; iter++)
{
//check the current shape
if(!AAM_IC::IsShapeWithinImage(__current_s, image->width, image->height)){
fprintf(stderr, "ERROR(%s, %d): Shape out of image\n",
__FILE__, __LINE__);
return iter;
}
//warp image to template image A0
__paw.FasterGetWarpTextureFromMatShape(__current_s, image, __warp_t,
true);
AAM_TDM::AlignTextureToRef(A0, __warp_t);
//calculate error image
cvSub(__warp_t, A0, __error_t);
if(showprocess){
cvCopy(image, Drawimg);
Draw(Drawimg, 2);
sprintf(filename, "result/Iter-%02d.jpg", iter+1);
cvSaveImage(filename, Drawimg);
}
//check for texture divergence
e2 = cvNorm(__error_t);
if(e2 < 0.01 || (iter>max_iter/3&&fabs(e2-e1)<0.01*e1)) break;
e1 = e2;
//1. calculate dot product of modified steepest descent images
// with error image
//2. calculate delta q and delta p by multiplying by inverse Hessian.
//In summary: we calculate parameters update
cvGEMM(__error_t, __G, 1, NULL, 1, __delta_pq, CV_GEMM_B_T);
//apply inverse compositional algorithm to update parameters
InverseCompose(__delta_pq, __current_s, __update_s);
//smooth shape
cvAddWeighted(__current_s, 0.4, __update_s, 0.6, 0, __update_s);
//update parameters
__shape.CalcParams(__update_s, __search_pq);
//calculate constrained new shape
__shape.CalcShape(__search_pq, __update_s);
//check for shape convergence
cvSub(__current_s, __update_s, __delta_s);
if(/*cvNorm(__delta_s)<0.01*/cvNorm(__delta_s, 0, CV_C) < 0.25) break;
else cvCopy(__update_s, __current_s);
}
Shape.Mat2Point(__current_s);
t = ((double)cvGetTickCount()-t)/(cvGetTickFrequency()*1000.);
printf("AAM IC Fitting time cost %.3f millisec\n", t);
cvReleaseImage(&Drawimg);
return iter;
}