Bonjour à tous,

J'ai écrit un programme qui permet d'appliquer un simple filtre exponentiel. Dans le but d'en tracker les bugs j'ai utilisé valgrind. Ce dernier me fournit différents messages d'erreurs mais je n'arrive pas à comprendre d'où ils viennent (d'opencv ou une erreur de programmation de ma part).
Pouvez-vous m'aidez s'il vous plaît ?

voici le main :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
 
#include"filtre.h"
 
using namespace std;
using namespace cv;
 
 int main(int argc, char* argv[]) 
{
         Mat image;
        Mat imageFiltree;
 
        // chargement de l'image                                                                                                                    
        image = imread(argv[1], CV_LOAD_IMAGE_GRAYSCALE);
 
        if(argc != 2 || !image.data)
                {
                        printf( "No image data \n" );
                        return -1;
                }
 
 
        //application du filtre                                                                                                                     
       filtrage(imageFiltree, image, 15, 15, 1.);
 
  // affichage du resultat                                                                                                                    
        namedWindow("image d'origine", CV_WINDOW_AUTOSIZE);
        namedWindow("image filtree", CV_WINDOW_AUTOSIZE);
 
        imshow("image d'origine", image);
        imshow("image filtree", imageFiltree);
 
        waitKey(0);
 
 
        return 0;
 
}
le filtrage :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
 
 #include "filtre.h"
 
 using namespace std;
 using namespace cv;
 
 void noyau_exponentiel(long size, double *h, double beta)
 {
         double constante = beta / 2.;
 
        for(int i = 0, x = -size/2; i < size, x <= size/2; ++i, ++x)
               h[i] = constante * exp(-beta * abs(x));
 
        return ;
}
 
void application_filtre(double *imageFiltree, Mat const& image, long sizeH1, long sizeH2, double beta)
{
        double *h1 = new double[sizeH1], *h2 = new double[sizeH2];
        long  width = image.cols, height = image.rows;
        double *dataImage = (double*)image.data;
        double *imageTemp = new double[width*height];
 
        assert(h1 && h2 && imageTemp);
 
        noyau_exponentiel(sizeH1, h1, beta);
        noyau_exponentiel(sizeH2, h2, beta);
 
        // filtrage horizontal                                                                                                                      
        for(long y = sizeH2/2; y < height - sizeH2/2; ++y)
                for(long x = sizeH1/2; x < width - sizeH1/2; ++x)
                        {
                                imageTemp[y*width + x] = 0.;
                                for(long i = -sizeH1/2; i <= sizeH1/2; ++i)
                                        imageTemp[y*width + x] += dataImage[y*width + x+i] * h1[sizeH1/2 + i];
                        }
 
        // filtrage vertical                                                                                                                   for(long y = sizeH2/2; y < height - sizeH2/2; ++y)
                for(long x = sizeH1/2; x < width - sizeH1/2; ++x)
                        {
                                imageTemp[y*width + x] = 0.;
                                for(long i = -sizeH1/2; i <= sizeH1/2; ++i)
                                        imageTemp[y*width + x] += dataImage[y*width + x+i] * h1[sizeH1/2 + i];
                        }
 
        // filtrage vertical                                                                                                                        
        for(long y = sizeH2/2; y < height - sizeH2/2; ++y)
                for(long x = sizeH1/2; x < width - sizeH1/2; ++x)
                        {
                                imageFiltree[y*width + x] = 0.;
                                for(long i = -sizeH2/2; i <= sizeH2/2; ++i)
                                        imageFiltree[y*width + x] += imageTemp[(y+i)*width +x] * h2[sizeH2/2 + i];
                        }
 
        // liberation de la memoire                                                                                                                 
        delete[] imageTemp;
        delete[] h1;
        delete[] h2;
 
        return;
}
void filtrage(Mat &imageFiltree, Mat const &image, long sizeH1, long sizeH2, double beta)
{
        Mat imageCopie;
        Mat imagePadding;
        Mat imagePaddingFiltree;
        double *dataPaddingFiltree = new double[(image.cols + sizeH1 - 1) * (image.rows + sizeH2 -1)];
 
        //copie de l'image d'origine et conversion pour une profondeur de 64 bits                                                                   
        image.convertTo(imageCopie, CV_64F, 1./255.);
 
        // creation de l'image padding                                                                                                              
        imagePadding = Mat(image.cols + sizeH1 - 1, image.rows + sizeH2 -1, CV_64FC1);
        copyMakeBorder(imageCopie, imagePadding, sizeH2 / 2, sizeH2 /2, sizeH1 /2, sizeH1/2, BORDER_CONSTANT, cvScalar(0,0,0));
 
        //application du filtre                                                                                                                     
        application_filtre(dataPaddingFiltree, imagePadding, sizeH1, sizeH2, beta);
        imagePaddingFiltree = Mat(imagePadding.cols, imagePadding.rows, CV_64FC1, dataPaddingFiltree);
 
        // extraction de l'image sans padding + conversion de l'image (depth 8 bits)                                                                
        Rect roi(sizeH1/2, sizeH2/2, image.cols, image.rows);
        Mat temp = imagePaddingFiltree(roi);
        temp.convertTo(imageFiltree, CV_8U, 255);
 
        // liberation de la memoire                                                                                                                 
        delete[] dataPaddingFiltree;
}
valgrind :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
 
=5842== Conditional jump or move depends on uninitialised value(s)
==5842==    at 0x51B1A7A: ??? (in /usr/lib/libopencv_core.so.2.3.1)
==5842==    by 0x51B983C: cv::Mat::convertTo(cv::_OutputArray const&, int, double, double) const (in /usr/lib/libopencv_core.so.2.3.1)
==5842==    by 0x401997: filtrage(cv::Mat&, cv::Mat const&, long, long, double) (in /home/toto/Documents/vision_taff/openCv/rehaussemen_de_contraste/main)
==5842==    by 0x402487: main (in /home/toto/Documents/vision_taff/openCv/rehaussemen_de_contraste/main)
==5842==  Uninitialised value was created by a heap allocation
==5842==    at 0x4C2AC27: operator new[](unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==5842==    by 0x40129B: application_filtre(double*, cv::Mat const&, long, long, double) (in /home/toto/Documents/vision_taff/openCv/rehaussemen_de_contraste/main)
==5842==    by 0x401899: filtrage(cv::Mat&, cv::Mat const&, long, long, double) (in /home/toto/Documents/vision_taff/openCv/rehaussemen_de_contraste/main)
==5842==    by 0x402487: main (in /home/toto/Documents/vision_taff/openCv/rehaussemen_de_contraste/main)
==5842==