単純な指数フィルターを適用できるプログラムを作成しました。プログラムのバグを追跡するためにValgrindを使用しました。理解できないエラーメッセージが表示されます。
valgrindのエラーメッセージは次のとおりです。
=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==
これが私のメインプログラムです:
#include"filtre.h"
using namespace std;
using namespace cv;
int main(int argc, char* argv[])
{
Mat image;
Mat imageFiltree;
// Load the image
image = imread(argv[1], CV_LOAD_IMAGE_GRAYSCALE);
if(argc != 2 || !image.data)
{
printf( "No image data \n" );
return -1;
}
// apply the filter
filtrage(imageFiltree, image, 15, 15, 1.);
// Display the result
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;
}
私のフィルター機能:
#include "filtre.h"
using namespace std;
using namespace cv;
//exponential kernel
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 ;
}
//which applies the filter function
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);
// Horizontal filtering
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];
}
// Vertical filtering
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];
}
// Release the memory
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)];
// copy of the original image and conversion to a depth of 64 bits
image.convertTo(imageCopie, CV_64F, 1./255.);
// Create the 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));
// apply the filter
application_filtre(dataPaddingFiltree, imagePadding, sizeH1, sizeH2, beta);
imagePaddingFiltree = Mat(imagePadding.cols, imagePadding.rows, CV_64FC1, dataPaddingFiltree);
// Extract the image without padding + image conversion (depth 8 bits)
Rect roi(sizeH1/2, sizeH2/2, image.cols, image.rows);
Mat temp = imagePaddingFiltree(roi);
temp.convertTo(imageFiltree, CV_8U, 255);
// Release the memory
delete[] dataPaddingFiltree;
}
メッセージはどういう意味ですか?