cvReleaseImage followed by cvCloneImage,

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

cvReleaseImage followed by cvCloneImage,

si seulement
Hi
My main issues is a "garbage collection", ie, the internal memory keep increasing at a rate of 100Mb / 10sec... This happen when i called a function that reduces the size of an image. The function it self "cvPyrDown" is not the problem is the code around it the issue.
There is 2 functions,
The "doPyrDown" which effectively used the cvPyrDown and does a check to see if the doPyrDown can be done. (effectively it divide height and width by 2, if 240>120>60>30>15>7.5, the later can not be achieve as it is no longuer an integer).
The "ReduceMainFrame", this function is called from the "main", it receieved "NumberofTime" which come from a slider control. The slider can be control from 0 to 10, knowing that only the first 6 step can be done if your webcam display 480 by 240.

The issues lies in the bottom the "ReduceMainFram", I am passing an pointer of the "image in", and the "image out".
Example:
In->width = 240 before reduce
Out->width = 240 before reduce
Img01->width = 120 once reduce
Img01 (data) need to be passed to Out(data)
but size are different.
therefor cvCopy(Img01,out,0); does not work
Out = cvCloneImage(Img01); comes in mind, but then the memory of the old out is not release therefore your memory slowly increase (or fast).

so I decided to used
cvReleaseImage(out);
out = cvCloneImage(Img01);

which works to some extend... every so often the out(data) has a Null pointer, and the image can not be display. I have tested the code using ubuntu 9.10, also the image is created using either webcam or the "tree.avi" (comes with opencv). In both cases the cvShowImage() crashes between 1 to 15 images.(random).


I provid the full application, also only the last 2 function need to be look at. In the last function look at from the last 10 lines).I have left some code with //"code" since I have tried differents solution, and some time going backward can help).
I have left some print comment, you will see when and where the application crashes. The application expect either a webcam plugin or
a video at this location.("/home/eric/Desktop/tree.avi");(see Init_Data).

It is long and also my first post, I have only dealt with opencv for the last 2weeks and Ubuntu for the last month. I usually do ladder logic PLC program, or a Excel Visual basic program. I have used Opencv book by O'Reilly as a base.


Thanks for your help, and your time. (hope one day I will be able to send lift back to some-one else.)

Eric,

Start of the code bellow:

/*

The aim is to open one window with a real time record of a webcam        ----Done-----
the other window will be a gaussian of that first window.             ----Done-----
there will be 2 slider to control the length of x and y coordinate average    ----Done-----

This will allow the user to see the affect of the gaussian depending on the width and height of the gaussian

there will also be a "pause" slider control to stop the webcam from updating the window.

There will a be a third window which use the "Canny Edge Detection", changing the guassian function will affect the Edge Detection. fun application actually.

Please note that there is an "issue" with the function that resize the picture.
if used this function will with in 10minutes used most of the memory.
The exercise is to understand and prevent it from happening.
*/


#include <opencv/cv.h>
#include <opencv/highgui.h>
#include <stdio.h>
#include <string.h>


//Creation of HMI title
#define HMI_Web "From Webcam - Hello the world -" //Title of window 1
#define HMI_Gaussian "- Webcam after a Gaussian Transform -" //Title of window 2
#define HMI_Canny "Webcam Color >>> Gaussian >>> Grey color Transform >>> Edge Dection" // Title of window 3




//Creation of Global
IplImage* g_CamDisplay;// Active window display (on pause this will not update)
IplImage* g_GaussianDisplay;
CvCapture* g_capture= NULL;
IplImage *g_CannyDisplay;
IplImage *grey = 0;

int g_Par_Gauss_1 =1;
int g_Par_Gauss_2 =1;
int g_Freeze_Image = 1;
int g_Do_Gauss = 1;
int g_Resize_Scale = 1 ;
int g_Use_Canny = 0 ;
double g_Canny_LowThresh = 10, g_Canny_HighThresh =100 , g_Canny_Aperture =3 ;

//Creation of warning variable
int Display_Warning001 = 0 ;//Used in "doPyrDown" can not reduced any further.
int Request_Warning001 = 0;


//Creation of function
int Use_WebCam();
void Init_Data();
void Run_Gauss(), Freeze_Image_Fun(int pos), Do_Gauss_Fun(int pos);
void Create_HMI(), Par_Gauss_1_Fun(int pos), Par_Gauss_2_Fun(int pos);
void Resize_Fun(int pos), Do_Canny_Fun(int pos);
void LowThresh_Fun(int pos) , HighThresh_Fun(int pos) , Aperture_Fun(int pos);


int ReduceMainFrame(int NumberofTime, IplImage *in, IplImage *out);



int doPyrDown(IplImage *in, IplImage *out, int Passing_Only);
IplImage *doCanny(IplImage *in);












int main(){
IplImage* img1;
IplImage* img_In;
int i = 0;
CvFont font;


    Create_HMI();
    Init_Data();
   
    grey = cvCreateImage( cvGetSize(g_CamDisplay), 8, 1 );//init grey pic
    while(1){
        Use_Webcam();


//Problematic code.
        //Scale down the size "Display only"
        /*
        img_In = cvCloneImage(g_CamDisplay);
        if (ReduceMainFrame( 0 g_Resize_Scale , img_In, img1 ) == 0 ) {
            //img1 = cvCloneImage(g_CamDisplay);
            cvShowImage( HMI_Web , img1);// this is to crash the application
        }
        */
        cvShowImage( HMI_Web , g_CamDisplay);
        img1 = cvCloneImage(g_CamDisplay);
         cvRectangle(img1 ,cvPoint(480/2,480/2) ,cvPoint(480/2 + 480/4,480/2+480/4) ,CV_RGB( 255, 0, 0 ) ,55,8,0);// create a rectangle in the copy just to see if the copy can be overwritten
        i = ReduceMainFrame( g_Resize_Scale , g_CamDisplay, img1) ;
        printf("001 before the IF");
        if (img1 != NULL){printf("002 before the Shown In the IF");
                cvShowImage( HMI_Web , img1);
                printf("003 After the Shown In the IF\n");}
        cvReleaseImage ( &img1 );





//working code
            if (g_Do_Gauss == 1 ) {Run_Gauss();}
            if (g_Do_Gauss == 0 ) {g_GaussianDisplay = g_CamDisplay ;}
        cvShowImage( HMI_Gaussian , g_GaussianDisplay );

        // if no edge detection only show the grey color once the gaussian as taken effect
        cvCvtColor( g_GaussianDisplay, grey, CV_BGR2GRAY);            
        if (g_Use_Canny == 0 ) { cvShowImage ( HMI_Canny , grey );}
        if (g_Use_Canny == 1 ) {
            g_CannyDisplay = doCanny(grey);
            cvShowImage( HMI_Canny , grey );
        }
            char c = cvWaitKey(50);
            if ( c==33) break;
          }


    cvReleaseImage ( &g_CamDisplay );
    cvReleaseImage ( &g_GaussianDisplay );
    cvReleaseCapture(&g_capture);
    cvDestroyWindow( HMI_Web );
    cvDestroyWindow( HMI_Gaussian );
    cvDestroyWindow( HMI_Canny );    
    return 0;
}



void Create_HMI(){
int Pos_Par_Gauss_1 = 0;//Init value
int Pos_Par_Gauss_2 = 0;//Init value
int Pos_of_Resize = 1;
int Pos_LowTresh = 10;
int Pos_HighTresh = 100;
int Pos_Aperture = 1;
    cvNamedWindow(HMI_Web, CV_WINDOW_AUTOSIZE);//Init window 1
    //Create the freeze image Trackbar
    cvCreateTrackbar("Freeze Image", HMI_Web, &g_Freeze_Image,1, Freeze_Image_Fun);
    //Creation of the automated change for the 2 Gaussian Parameter.

/*http://opencv.willowgarage.com/documentation/image_processing.html#cvSmooth*/

    cvNamedWindow(HMI_Gaussian, CV_WINDOW_AUTOSIZE);
    cvCreateTrackbar("Perform Gaussian Image", HMI_Gaussian, &g_Do_Gauss,1, Do_Gauss_Fun);
    cvCreateTrackbar("Open \"The Canny\" Edge detector", HMI_Gaussian, &g_Use_Canny, 1, Do_Canny_Fun);
    cvCreateTrackbar("Original Display only Resize Image", HMI_Gaussian, &Pos_of_Resize , 10, Resize_Fun);
    cvCreateTrackbar("Parametre Gauss 1", HMI_Gaussian, &Pos_Par_Gauss_1, 101, Par_Gauss_1_Fun);
    cvCreateTrackbar("Parametre Gauss 2", HMI_Gaussian, &Pos_Par_Gauss_2, 101, Par_Gauss_2_Fun);

    cvNamedWindow(HMI_Canny,  CV_WINDOW_AUTOSIZE);
    cvResizeWindow(HMI_Canny, 640 , 640);
    cvCreateTrackbar("Low Thresh", HMI_Canny , &Pos_LowTresh , 300, LowThresh_Fun);
    cvCreateTrackbar("High Thresh", HMI_Canny , &Pos_HighTresh , 300, HighThresh_Fun);
    cvCreateTrackbar(" Aperture", HMI_Canny , &Pos_Aperture , 3, Aperture_Fun);


}


void LowThresh_Fun(int pos){
    g_Canny_LowThresh = (double) (pos + 0);
}

void HighThresh_Fun(int pos){
    g_Canny_HighThresh = (double)(pos +0 ) ;
}

void Aperture_Fun(int pos){
   
    g_Canny_Aperture = (double) ( (pos + 1)* 2 - 1);// this will give 1 - 3 - 5 - 7  for pos = 0,1,2,3
    printf("\n position of Aperture is %d, and calc Aperture is %f \n" , pos, g_Canny_Aperture);
}



void Par_Gauss_1_Fun(int pos){
    /*make sure that the value used for that Gaussian is >=0 and odd number.
    By def of the trackbar "pos" can only be >=0, then only things to check
    is odd number.
    In fact here, I create an odd number, like this no check and code is therefore faster
    */
    g_Par_Gauss_1 = ((pos + 1) * 2) - 1;
}

void Par_Gauss_2_Fun(int pos){
    /*make sure that the value used for that Gaussian is >=0 and odd number.
    By def of the trackbar "pos" can only be >=0, then only things to check
    is odd number.
    In fact here, I create an odd number, like this no check and code is therefore faster
    */
    g_Par_Gauss_2 = ((pos + 1) * 2) - 1;
}

void Freeze_Image_Fun(int pos){
    //do Nothing.
}

void Do_Gauss_Fun(int pos){
    //do Nothing.
}

void  Do_Canny_Fun(int pos){
    //do Nothing.
}

void Resize_Fun(int pos){
    g_Resize_Scale = pos + 1;
}


void Init_Data(){
    g_capture = cvCreateCameraCapture (-1);
    /*if no camera check there is fall back. fall back will have limited time display
    what happen when video is finished?*/
    if (g_capture == NULL) {
        g_capture = cvCreateFileCapture("/home/eric/Desktop/tree.avi");
    }
    //Initialise one Image of the Video
    if (g_capture != NULL) {
    g_CamDisplay = cvQueryFrame( g_capture);
    }
    //Initialise one Frame of the Gaussian
    g_GaussianDisplay = cvCreateImage( cvGetSize(g_CamDisplay),
        IPL_DEPTH_8U,
        3
        );    
}

int Use_Webcam(){
    //this will open the webcam and extract image in "RT" (RT = Real Time)

    if (g_Freeze_Image == 0 ) { //value off 1 means that the webcam is a standstill image
        if (g_capture != NULL) {
        g_CamDisplay = cvQueryFrame( g_capture);
        }
    }
    return 0;
}


void Run_Gauss(){
    /*Run the Smooth filter
    note the 2 parameter that can be tune while:
????????Exercise will be to create similar funciton for that last 2 param and explain there function.
    */
    cvSmooth( g_CamDisplay, g_GaussianDisplay , CV_GAUSSIAN, g_Par_Gauss_1 , g_Par_Gauss_2 , 0,0);

}



IplImage* doCanny(IplImage *in){
IplImage *out= in;
double Canny_Aperture = g_Canny_Aperture;
    if(in->nChannels != 1) return(0); //Canny only handles gray scale images
    if (g_Canny_Aperture <= 1 ) {Canny_Aperture = 3;}//for some reason value of 1 seems to be problematic, is this due to overflow???
        cvCanny (in, out, g_Canny_LowThresh , g_Canny_HighThresh , Canny_Aperture) ;
    return (out);
}







int doPyrDown(IplImage* in, IplImage* out,int Passing_Only){

    cvCopy(in,out,0);

int ShouldDisplay_Warning ;
    if (Passing_Only == 0 ) {
        if (in->width % 2 == 0 && in->height % 2 ==0){
        cvReleaseImage ( &out) ;
            out = cvCreateImage(
                cvSize(in->width / 2, in->height / 2),
                in->depth,
                in->nChannels
                );
            cvPyrDown(in, out,CV_GAUSSIAN_5x5); //there is a single working choice for the filter
            //therefore no point to put as an argument for the doPyrDown function.
            Request_Warning001 = 0; //Reset the message indicator.
        }
        if(in->width % 2 !=0 || in->height % 2 !=0){
            Request_Warning001 = 1;
        }
    }
    return (0);

}



int ReduceMainFrame(int NumberofTime, IplImage *in, IplImage *out){

int i , j;
IplImage *Img01 = NULL;
    Img01 = cvCloneImage(in);
    j = doPyrDown(Img01, out, 1);//passing only make sure Out = In
    for (i=1; i < NumberofTime ; i++){            
            j = doPyrDown(Img01 , out, 0);
            cvReleaseImage(&Img01);
            Img01 = cvCloneImage(out);
    }
   
    if (Request_Warning001 == 1 && Display_Warning001 == 0) {
        //printf("\n The image becomes too small and at least either width or height is becoming an odd value once divided by a further factor 2\n");
        Display_Warning001 = 1;
    }
    if (Request_Warning001 == 0 && Display_Warning001 == 1){
        //printf("\n This level of reduction is now acceptable\n");
        Display_Warning001 = 0;
    }
    //cvCopy(Img01,out,0);
    //check reliability of Img01 against in
        /*cvReleaseImage(&out);
                out = cvCreateImage(
                cvSize(Img01->width, Img01->height),
                Img01->depth,
                Img01->nChannels
                );
        */cvCopy(Img01,out,0);
        //cvReleaseImage(&out);//If you do not release the image then the memory goes sky high.
                out = cvCreateImage(
                cvSize(in->width, in->height),
                in->depth,
                in->nChannels
                );
        cvCopy(in,out,0);
    //    out = cvCloneImage( Img01);
    cvReleaseImage( &Img01);
    return (0);
}









 

Reply | Threaded
Open this post in threaded view
|

Re: cvReleaseImage followed by cvCloneImage,

Jean-Pierre Landry
I haven't gone through all your code but something caught my eye about
how you're using pointers as parameters...

You have to remember that function's parameters are copied onto the
stack when the function is called.  So if you pass an integer, a copy of
this integer is copied onto the stack and the initial integer is left
unchanged...  If you pass a pointer to this integer you're then able to
change the value pointed by this pointer and the value of the initial
integer.  (I'm guessing that's pretty basic pointer stuff that you
already know...)  The thing to realize here is that a copy of the
pointer you supplied was put on the stack.  So it enables you to change
the value pointed to it but you can't expect to change the actual
pointer in your function and have your original pointer altered as
well...  To be able to do this you would have to go down another level
of indirection and use a pointer to pointer as your parameter...
Taking your 'doPyrDown' as an example, your passing a pointers to
IplImage.  So you can expect to change the images pointed to them but
can't expect to be able to change where the pointers point...


int doPyrDown(IplImage* in, IplImage* out,int Passing_Only){

      cvCopy(in,out,0);

      int ShouldDisplay_Warning ;
      if (Passing_Only == 0 ) {
          if (in->width % 2 == 0 && in->height % 2 ==0){


// not sure you should be doing this...
          cvReleaseImage ( &out) ;


// now you're changing the copied pointer value that will get thrown out
// when the function terminates and therefore it will leak memory...
              out = cvCreateImage(
                  cvSize(in->width / 2, in->height / 2),
                  in->depth,
                  in->nChannels
                  );


              cvPyrDown(in, out,CV_GAUSSIAN_5x5); //there is a single
working choice for the filter
              //therefore no point to put as an argument for the
doPyrDown function.
              Request_Warning001 = 0; //Reset the message indicator.
          }
          if(in->width % 2 !=0 || in->height % 2 !=0){
              Request_Warning001 = 1;
          }
      }
      return (0);

}


You would have to resort to something like this to get what you want:

    int doPyrDown(IplImage* in, IplImage** out,int Passing_Only)

and
    cvRelease(out);
and
    *out = cvCreateImage(...);


A careful examination of your pointers before and after your function
calls with a debugger might confirm what I'm saying here (or not! :-)  )

Hope this helps, let me know...



si seulement wrote:

> Hi
> My main issues is a "garbage collection", ie, the internal memory keep increasing at a rate of 100Mb / 10sec... This happen when i called a function that reduces the size of an image. The function it self "cvPyrDown" is not the problem is the code around it the issue.
> There is 2 functions,
> The "doPyrDown" which effectively used the cvPyrDown and does a check to see if the doPyrDown can be done. (effectively it divide height and width by 2, if 240>120>60>30>15>7.5, the later can not be achieve as it is no longuer an integer).
> The "ReduceMainFrame", this function is called from the "main", it receieved "NumberofTime" which come from a slider control. The slider can be control from 0 to 10, knowing that only the first 6 step can be done if your webcam display 480 by 240.
>
> The issues lies in the bottom the "ReduceMainFram", I am passing an pointer of the "image in", and the "image out".
> Example:
> In->width = 240 before reduce
> Out->width = 240 before reduce
> Img01->width = 120 once reduce
> Img01 (data) need to be passed to Out(data)
> but size are different.
> therefor cvCopy(Img01,out,0); does not work
> Out = cvCloneImage(Img01); comes in mind, but then the memory of the old out is not release therefore your memory slowly increase (or fast).
>
> so I decided to used
> cvReleaseImage(out);
> out = cvCloneImage(Img01);
>
> which works to some extend... every so often the out(data) has a Null pointer, and the image can not be display. I have tested the code using ubuntu 9.10, also the image is created using either webcam or the "tree.avi" (comes with opencv). In both cases the cvShowImage() crashes between 1 to 15 images.(random).
>
>
> I provid the full application, also only the last 2 function need to be look at. In the last function look at from the last 10 lines).I have left some code with //"code" since I have tried differents solution, and some time going backward can help).
> I have left some print comment, you will see when and where the application crashes. The application expect either a webcam plugin or
> a video at this location.("/home/eric/Desktop/tree.avi");(see Init_Data).
>
> It is long and also my first post, I have only dealt with opencv for the last 2weeks and Ubuntu for the last month. I usually do ladder logic PLC program, or a Excel Visual basic program. I have used Opencv book by O'Reilly as a base.
>
>
> Thanks for your help, and your time. (hope one day I will be able to send lift back to some-one else.)
>
> Eric,
>
> Start of the code bellow:
>
> /*
>
> The aim is to open one window with a real time record of a webcam        ----Done-----
> the other window will be a gaussian of that first window.             ----Done-----
> there will be 2 slider to control the length of x and y coordinate average    ----Done-----
>
> This will allow the user to see the affect of the gaussian depending on the width and height of the gaussian
>
> there will also be a "pause" slider control to stop the webcam from updating the window.
>
> There will a be a third window which use the "Canny Edge Detection", changing the guassian function will affect the Edge Detection. fun application actually.
>
> Please note that there is an "issue" with the function that resize the picture.
> if used this function will with in 10minutes used most of the memory.
> The exercise is to understand and prevent it from happening.
> */
>
>
> #include <opencv/cv.h>
> #include <opencv/highgui.h>
> #include <stdio.h>
> #include <string.h>
>
>
> //Creation of HMI title
> #define HMI_Web "From Webcam - Hello the world -" //Title of window 1
> #define HMI_Gaussian "- Webcam after a Gaussian Transform -" //Title of window 2
> #define HMI_Canny "Webcam Color >>> Gaussian >>> Grey color Transform >>> Edge Dection" // Title of window 3
>
>
>
>
> //Creation of Global
> IplImage* g_CamDisplay;// Active window display (on pause this will not update)
> IplImage* g_GaussianDisplay;
> CvCapture* g_capture= NULL;
> IplImage *g_CannyDisplay;
> IplImage *grey = 0;
>
> int g_Par_Gauss_1 =1;
> int g_Par_Gauss_2 =1;
> int g_Freeze_Image = 1;
> int g_Do_Gauss = 1;
> int g_Resize_Scale = 1 ;
> int g_Use_Canny = 0 ;
> double g_Canny_LowThresh = 10, g_Canny_HighThresh =100 , g_Canny_Aperture =3 ;
>
> //Creation of warning variable
> int Display_Warning001 = 0 ;//Used in "doPyrDown" can not reduced any further.
> int Request_Warning001 = 0;
>
>
> //Creation of function
> int Use_WebCam();
> void Init_Data();
> void Run_Gauss(), Freeze_Image_Fun(int pos), Do_Gauss_Fun(int pos);
> void Create_HMI(), Par_Gauss_1_Fun(int pos), Par_Gauss_2_Fun(int pos);
> void Resize_Fun(int pos), Do_Canny_Fun(int pos);
> void LowThresh_Fun(int pos) , HighThresh_Fun(int pos) , Aperture_Fun(int pos);
>
>
> int ReduceMainFrame(int NumberofTime, IplImage *in, IplImage *out);
>
>
>
> int doPyrDown(IplImage *in, IplImage *out, int Passing_Only);
> IplImage *doCanny(IplImage *in);
>
>
>
>
>
>
>
>
>
>
>
>
> int main(){
> IplImage* img1;
> IplImage* img_In;
> int i = 0;
> CvFont font;
>
>
>     Create_HMI();
>     Init_Data();
>    
>     grey = cvCreateImage( cvGetSize(g_CamDisplay), 8, 1 );//init grey pic
>     while(1){
>         Use_Webcam();
>
>
> //Problematic code.
>         //Scale down the size "Display only"
>         /*
>         img_In = cvCloneImage(g_CamDisplay);
>         if (ReduceMainFrame( 0 g_Resize_Scale , img_In, img1 ) == 0 ) {
>             //img1 = cvCloneImage(g_CamDisplay);
>             cvShowImage( HMI_Web , img1);// this is to crash the application
>         }
>         */
>         cvShowImage( HMI_Web , g_CamDisplay);
>         img1 = cvCloneImage(g_CamDisplay);
>          cvRectangle(img1 ,cvPoint(480/2,480/2) ,cvPoint(480/2 + 480/4,480/2+480/4) ,CV_RGB( 255, 0, 0 ) ,55,8,0);// create a rectangle in the copy just to see if the copy can be overwritten
>         i = ReduceMainFrame( g_Resize_Scale , g_CamDisplay, img1) ;
>         printf("001 before the IF");
>         if (img1 != NULL){printf("002 before the Shown In the IF");
>                 cvShowImage( HMI_Web , img1);
>                 printf("003 After the Shown In the IF\n");}
>         cvReleaseImage ( &img1 );
>
>
>
>
>
> //working code
>             if (g_Do_Gauss == 1 ) {Run_Gauss();}
>             if (g_Do_Gauss == 0 ) {g_GaussianDisplay = g_CamDisplay ;}
>         cvShowImage( HMI_Gaussian , g_GaussianDisplay );
>
>         // if no edge detection only show the grey color once the gaussian as taken effect
>         cvCvtColor( g_GaussianDisplay, grey, CV_BGR2GRAY);            
>         if (g_Use_Canny == 0 ) { cvShowImage ( HMI_Canny , grey );}
>         if (g_Use_Canny == 1 ) {
>             g_CannyDisplay = doCanny(grey);
>             cvShowImage( HMI_Canny , grey );
>         }
>             char c = cvWaitKey(50);
>             if ( c==33) break;
>           }
>
>
>     cvReleaseImage ( &g_CamDisplay );
>     cvReleaseImage ( &g_GaussianDisplay );
>     cvReleaseCapture(&g_capture);
>     cvDestroyWindow( HMI_Web );
>     cvDestroyWindow( HMI_Gaussian );
>     cvDestroyWindow( HMI_Canny );    
>     return 0;
> }
>
>
>
> void Create_HMI(){
> int Pos_Par_Gauss_1 = 0;//Init value
> int Pos_Par_Gauss_2 = 0;//Init value
> int Pos_of_Resize = 1;
> int Pos_LowTresh = 10;
> int Pos_HighTresh = 100;
> int Pos_Aperture = 1;
>     cvNamedWindow(HMI_Web, CV_WINDOW_AUTOSIZE);//Init window 1
>     //Create the freeze image Trackbar
>     cvCreateTrackbar("Freeze Image", HMI_Web, &g_Freeze_Image,1, Freeze_Image_Fun);
>     //Creation of the automated change for the 2 Gaussian Parameter.
>
> /*http://opencv.willowgarage.com/documentation/image_processing.html#cvSmooth*/
>
>     cvNamedWindow(HMI_Gaussian, CV_WINDOW_AUTOSIZE);
>     cvCreateTrackbar("Perform Gaussian Image", HMI_Gaussian, &g_Do_Gauss,1, Do_Gauss_Fun);
>     cvCreateTrackbar("Open \"The Canny\" Edge detector", HMI_Gaussian, &g_Use_Canny, 1, Do_Canny_Fun);
>     cvCreateTrackbar("Original Display only Resize Image", HMI_Gaussian, &Pos_of_Resize , 10, Resize_Fun);
>     cvCreateTrackbar("Parametre Gauss 1", HMI_Gaussian, &Pos_Par_Gauss_1, 101, Par_Gauss_1_Fun);
>     cvCreateTrackbar("Parametre Gauss 2", HMI_Gaussian, &Pos_Par_Gauss_2, 101, Par_Gauss_2_Fun);
>
>     cvNamedWindow(HMI_Canny,  CV_WINDOW_AUTOSIZE);
>     cvResizeWindow(HMI_Canny, 640 , 640);
>     cvCreateTrackbar("Low Thresh", HMI_Canny , &Pos_LowTresh , 300, LowThresh_Fun);
>     cvCreateTrackbar("High Thresh", HMI_Canny , &Pos_HighTresh , 300, HighThresh_Fun);
>     cvCreateTrackbar(" Aperture", HMI_Canny , &Pos_Aperture , 3, Aperture_Fun);
>
>
> }
>
>
> void LowThresh_Fun(int pos){
>     g_Canny_LowThresh = (double) (pos + 0);
> }
>
> void HighThresh_Fun(int pos){
>     g_Canny_HighThresh = (double)(pos +0 ) ;
> }
>
> void Aperture_Fun(int pos){
>    
>     g_Canny_Aperture = (double) ( (pos + 1)* 2 - 1);// this will give 1 - 3 - 5 - 7  for pos = 0,1,2,3
>     printf("\n position of Aperture is %d, and calc Aperture is %f \n" , pos, g_Canny_Aperture);
> }
>
>
>
> void Par_Gauss_1_Fun(int pos){
>     /*make sure that the value used for that Gaussian is >=0 and odd number.
>     By def of the trackbar "pos" can only be >=0, then only things to check
>     is odd number.
>     In fact here, I create an odd number, like this no check and code is therefore faster
>     */
>     g_Par_Gauss_1 = ((pos + 1) * 2) - 1;
> }
>
> void Par_Gauss_2_Fun(int pos){
>     /*make sure that the value used for that Gaussian is >=0 and odd number.
>     By def of the trackbar "pos" can only be >=0, then only things to check
>     is odd number.
>     In fact here, I create an odd number, like this no check and code is therefore faster
>     */
>     g_Par_Gauss_2 = ((pos + 1) * 2) - 1;
> }
>
> void Freeze_Image_Fun(int pos){
>     //do Nothing.
> }
>
> void Do_Gauss_Fun(int pos){
>     //do Nothing.
> }
>
> void  Do_Canny_Fun(int pos){
>     //do Nothing.
> }
>
> void Resize_Fun(int pos){
>     g_Resize_Scale = pos + 1;
> }
>
>
> void Init_Data(){
>     g_capture = cvCreateCameraCapture (-1);
>     /*if no camera check there is fall back. fall back will have limited time display
>     what happen when video is finished?*/
>     if (g_capture == NULL) {
>         g_capture = cvCreateFileCapture("/home/eric/Desktop/tree.avi");
>     }
>     //Initialise one Image of the Video
>     if (g_capture != NULL) {
>     g_CamDisplay = cvQueryFrame( g_capture);
>     }
>     //Initialise one Frame of the Gaussian
>     g_GaussianDisplay = cvCreateImage( cvGetSize(g_CamDisplay),
>         IPL_DEPTH_8U,
>         3
>         );    
> }
>
> int Use_Webcam(){
>     //this will open the webcam and extract image in "RT" (RT = Real Time)
>
>     if (g_Freeze_Image == 0 ) { //value off 1 means that the webcam is a standstill image
>         if (g_capture != NULL) {
>         g_CamDisplay = cvQueryFrame( g_capture);
>         }
>     }
>     return 0;
> }
>
>
> void Run_Gauss(){
>     /*Run the Smooth filter
>     note the 2 parameter that can be tune while:
> ????????Exercise will be to create similar funciton for that last 2 param and explain there function.
>     */
>     cvSmooth( g_CamDisplay, g_GaussianDisplay , CV_GAUSSIAN, g_Par_Gauss_1 , g_Par_Gauss_2 , 0,0);
>
> }
>
>
>
> IplImage* doCanny(IplImage *in){
> IplImage *out= in;
> double Canny_Aperture = g_Canny_Aperture;
>     if(in->nChannels != 1) return(0); //Canny only handles gray scale images
>     if (g_Canny_Aperture <= 1 ) {Canny_Aperture = 3;}//for some reason value of 1 seems to be problematic, is this due to overflow???
>         cvCanny (in, out, g_Canny_LowThresh , g_Canny_HighThresh , Canny_Aperture) ;
>     return (out);
> }
>
>
>
>
>
>
>
> int doPyrDown(IplImage* in, IplImage* out,int Passing_Only){
>
>     cvCopy(in,out,0);
>
> int ShouldDisplay_Warning ;
>     if (Passing_Only == 0 ) {
>         if (in->width % 2 == 0 && in->height % 2 ==0){
>         cvReleaseImage ( &out) ;
>             out = cvCreateImage(
>                 cvSize(in->width / 2, in->height / 2),
>                 in->depth,
>                 in->nChannels
>                 );
>             cvPyrDown(in, out,CV_GAUSSIAN_5x5); //there is a single working choice for the filter
>             //therefore no point to put as an argument for the doPyrDown function.
>             Request_Warning001 = 0; //Reset the message indicator.
>         }
>         if(in->width % 2 !=0 || in->height % 2 !=0){
>             Request_Warning001 = 1;
>         }
>     }
>     return (0);
>
> }
>
>
>
> int ReduceMainFrame(int NumberofTime, IplImage *in, IplImage *out){
>
> int i , j;
> IplImage *Img01 = NULL;
>     Img01 = cvCloneImage(in);
>     j = doPyrDown(Img01, out, 1);//passing only make sure Out = In
>     for (i=1; i < NumberofTime ; i++){            
>             j = doPyrDown(Img01 , out, 0);
>             cvReleaseImage(&Img01);
>             Img01 = cvCloneImage(out);
>     }
>    
>     if (Request_Warning001 == 1 && Display_Warning001 == 0) {
>         //printf("\n The image becomes too small and at least either width or height is becoming an odd value once divided by a further factor 2\n");
>         Display_Warning001 = 1;
>     }
>     if (Request_Warning001 == 0 && Display_Warning001 == 1){
>         //printf("\n This level of reduction is now acceptable\n");
>         Display_Warning001 = 0;
>     }
>     //cvCopy(Img01,out,0);
>     //check reliability of Img01 against in
>         /*cvReleaseImage(&out);
>                 out = cvCreateImage(
>                 cvSize(Img01->width, Img01->height),
>                 Img01->depth,
>                 Img01->nChannels
>                 );
>         */cvCopy(Img01,out,0);
>         //cvReleaseImage(&out);//If you do not release the image then the memory goes sky high.
>                 out = cvCreateImage(
>                 cvSize(in->width, in->height),
>                 in->depth,
>                 in->nChannels
>                 );
>         cvCopy(in,out,0);
>     //    out = cvCloneImage( Img01);
>     cvReleaseImage( &Img01);
>     return (0);
> }
>
>
>
>
>
>
>
>
>
>  
>
>
>
> ------------------------------------
>
> Change settings: http://www.yahoogroups.com/mygroups, select
>    Get Emails (get all posts)
>    Daily Digest (one summary email per day)
>    Read on the web (read posts on the web only)Or Unsubscribe by mailing [hidden email]