Consider this C code from OpenCV Tutorial 8 - Chapter 9
// Learn the background statistics for one more frame
void accumulateBackground( IplImage *I ){
static int first = 1;
cvCvtScale( I, Iscratch, 1, 0 );
if( !first ){
cvAcc( Iscratch, IavgF );
cvAbsDiff( Iscratch, IprevF, Iscratch2 );
cvAcc( Iscratch2, IdiffF );
Icount += 1.0;
}
first = 0;
cvCopy( Iscratch, IprevF );
}
It seems the way the code is designed that because of
if( !first )
the program will never execute:
cvAcc( Iscratch, IavgF );
cvAbsDiff( Iscratch, IprevF, Iscratch2 );
cvAcc( Iscratch2, IdiffF );
Icount += 1.0;
In Lisp I'm trying to translate this as:
(defun accumulate-background (i)
(setf 1st 1)
(cvt-scale i i-scratch-1 1 0) ;; To float
(if (not 1st)
(progn (acc i-scratch-1 i-avg-f)
(abs-diff i-scratch-1 i-prev-f i-scratch-2)
(acc i-scratch-2 i-diff-f)
(setf i-count (+ i-count 1.0))))
(setf 1st 0)
(copy i-scratch-1 i-prev-f))
For the equivalent function, with (not 1st)
for !first
, and I think that's correct.
In C++ I do:
static int first = 1;
if( first ){
cout << "reached this part of code " << endl << " " << first << endl << endl;
}
but never produce any output because of the code design, it seems. Why would the designer of the tutorial code like this? He is copying from Learning OpenCV.