Ask Your Question

choukri el's profile - activity

2020-03-21 07:20:33 -0600 received badge  Popular Question (source)
2016-04-24 14:02:52 -0600 commented question double free or corruption (!prev) c++ opencv
2016-04-24 12:34:50 -0600 asked a question double free or corruption (!prev) c++ opencv

I'm implementing a method that decomposes the images,it takes an image as input and returns many images as output called BEMCs.Here is my main function where I try to return just the first BEMC :

int main(int argc, char **argv)
{
if (argc != 2) {
    std::cout << "Usage: ./emd <image>" << std::endl;
    return 1;
}
cv::Mat inputImg;
cv::Mat imgMode;

inputImg=imread(argv[1],CV_LOAD_IMAGE_COLOR); 

if(! inputImg.data )                             
{   cout <<  "Could not open or find the image" << std::endl ;
    return -1;
}
namedWindow("Source Image",WINDOW_AUTOSIZE);
imshow("Source Image",inputImg);
cv::waitKey(1000);

Mat gray;
cvtColor(inputImg,gray,COLOR_BGR2GRAY);
Mat grayy;
gray.convertTo(grayy, CV_32F);
sprintf(modeTitle, "BEMC-%d", 1);
std::cout << "Decomposition " << modeTitle << std::endl;
cv::Mat imgMod(grayy) , result;

imgMod = decompose(grayy); *************main.cpp:387********                                                 
//**** decompose is the function that generate the error******
...........................
...........................
}

Here's a portion of my function decompose,first I'm trying to find maximas of the image ,then I'm trying to store them into vectors that I use to do other things:

cv::Mat decompose(cv::Mat input )
{
cv::Mat inputImg;
input.copyTo(inputImg);

std::vector<Euclidean> vectEMax, vectEMin;

cv::Mat imgMax;
...................................
vectEMax.push_back(max);vectEMax.push_back(min);

 ................................

 std::vector<Euclidean>::iterator it1, it2;

 ..............................

I'm using the iteretors to calculate distances between maximas,all these operations work fine,I insert the elements in vectEMax and calculate without any problems. At the end of the program I have to return an image as a result of the method .

cv::Mat  imgMoyenne //imgMoyenne is an image based on maximas,calculted  
                         in the program
    ....................
    cv::Mat diff_im;
    inputImg.copyTo(diff_im);
    diff_im = inputImg - imgMoyenne ;
    return diff_im;}*****************main.cpp:345**************

The program crashes after the return,it shows * glibc detected * ./gdb_core: double free or corruption (!prev): 0x08c33d78 * here is a gdb output

Program terminated with signal 6, Aborted.
  #0  0xb7738424 in __kernel_vsyscall ()

  thread apply all bt

 Thread 1 (Thread 0xb4282740 (LWP 3652)):
 #0  0xb773a424 in __kernel_vsyscall ()
 #1  0xb6f1f1df in __GI_raise (sig=6)
 at ../nptl/sysdeps/unix/sysv/linux/raise.c:64
 #2  0xb6f22825 in __GI_abort () at abort.c:91
 #3  0xb6f5c39a in __libc_message (do_abort=2, 
 fmt=0xb70578e8 "*** glibc detected *** %s: %s: 0x%s ***\n")
 at ../sysdeps/unix/sysv/linux/libc_fatal.c:201
 #4  0xb6f66ee2 in malloc_printerr (action=<optimized out>, 
 str=<optimized out>, ptr=0x8c33d78) at malloc.c:5039
#5  0xb7549c22 in cv::fastFree(void*) ()
from /usr/local/lib/libopencv_core.so.2.4
#6  0xb763e78b in cv::Mat::deallocate() ()
from /usr/local/lib/libopencv_core.so.2.4
#7  0x0804c1fd in cv::Mat::release (this=0xbfda1fc8)
at /usr/local/include/opencv2/core/mat.hpp:367
#8  0x0804c055 in cv::Mat::~Mat (this=0xbfda1fc8, __in_chrg=<optimized out>)
at /usr/local/include/opencv2/core/mat.hpp:276
#9  0x0804b24c in decompose (input=...) at main.cpp:345
#10 0x0804b87f in main (argc=2, argv=0xbfda25a4) at main.cpp:387

I need your help please

2016-04-06 06:36:06 -0600 commented question Segmentation fault when calling a method which contains an image as parameter

thank you @LorenaGdL for your reply ,please is there any other method to access the pixels ?

2016-04-06 05:26:49 -0600 received badge  Editor (source)
2016-04-06 04:39:09 -0600 commented question Segmentation fault when calling a method which contains an image as parameter

yes I did, I defined them like this :

cv::Mat imgSource(inputImg);
cv::Mat imgMax(inputImg);
cv::Mat newImgMax(imgMax.size().height,imgMax.size().width,CV_32F);
2016-04-06 04:09:23 -0600 asked a question Segmentation fault when calling a method which contains an image as parameter

Hi everybody ! I'm going to start by showing you the debugger output :

#0  0x0804c2cb in cv::Mat::Mat (this=0xbffff110, m=...)
    at /usr/local/include/opencv2/core/mat.hpp:117
#1  0x0804ad14 in decompose (input=...) at main.cpp:241
#2  0x0804bbd7 in main (argc=2, argv=0xbffff6c4) at main.cpp:322

Here's my code :

   #define MAX_ITERATIONS 15
    //////////////////
    /////////////////
    float sum(cv::Mat img, int startedY, int startedX, int w) {
        float res = 0.0f;
    for (int j = startedY - ((w - 1) / 2) ; j < startedY + ((w + 1) / 2); j++)
        for (int i = startedX - ((w - 1) / 2); i < startedX + ((w + 1) / 2); i++) {
             {
                if ((i >= 0 && i < img.size().width) && (j >= 0  && j < img.size().height)) {
                    res += img.at<float>(j,i);
                }}}   return res; }

     cv::Mat decompose(cv::Mat input)
    {
 ///////////////////
cv::Mat imgSource(inputImg);
cv::Mat imgMax(inputImg);
cv::Mat newImgMax(imgMax.size().height,imgMax.size().width,CV_32F);
    /////////////////////////////////
   ////////////////////////////////////
    for (int l = 0; l < imgSource.size().width; l++){
     for (int k = 0; k < imgSource.size().height; k++){
       if( (k >= 0 && k < imgSource.size().height) && (l >= 0  && l < imgSource.size().width) ) {
newImgMax.at<float>(k,l) = (float)sum(imgMax,k, l, wmax) / (wmax * wmax);******* *LIGNE 241*****
     }}}
    ////////////////////
  /////////////////////
    }
    int main(int argc, char **argv)
    {
        char modeTitle[30]= {0}, residueTitle[50];
        double variance = 1000000;
        if (argc != 2) {
            std::cout << "Usage: ./emd <image>" << std::endl;
            return 1;
        }
     cv::Mat inputImg;
     cv::Mat imgMode;

    inputImg=imread(argv[1]); 
    if(! inputImg.data )                             
        {cout <<  "Could not open or find the image" << std::endl ;
            return -1; }

    namedWindow("Source Image",WINDOW_AUTOSIZE);
    imshow("Source Image",inputImg);
    cv::waitKey(1000);
        for (int i = 1; i < MAX_ITERATIONS + 1; i++) {
            sprintf(modeTitle, "BEMC-%d", i);
            std::cout << "Decomposing " << modeTitle << std::endl;
            imgMode = decompose(inputImg);**************LIGNE 322****************
//////////////
/////////////
}

here's a portion of /usr/local/include/opencv2/core/mat.hpp :

inline Mat::Mat(const Mat& m)
    : flags(m.flags), dims(m.dims), rows(m.rows), cols(m.cols), data(m.data),
    refcount(m.refcount), datastart(m.datastart), dataend(m.dataend),
    datalimit(m.datalimit), allocator(m.allocator), size(&rows)
{
    if( refcount )
        CV_XADD(refcount, 1);**************** LIGNE 117******************
    if( m.dims <= 2 )
    {
        step[0] = m.step[0]; step[1] = m.step[1];
    }
    else
    {
        dims = 0;
        copySize(m);
    }
}

Any ideas how I could fix this issue?

2016-04-04 03:55:44 -0600 commented question Segmentation fault (core dumped) image processing c++/opencv

okay I will see these libraries, thank you for your advices and your replies @LorenaGdL @LBerger @StevenPuttemans

2016-04-03 18:13:29 -0600 commented question Segmentation fault (core dumped) image processing c++/opencv

After several tests I found that the call to the function "sum" is done only once independently of indexes(rows,cols) for example when I try :

std::cout << " (1,0)= " <<sum(imgMax,1, 0, wmax) <<std::endl;

it returns a value and when I try :

std::cout << " (2,3)= " <<sum(imgMax,2, 3, wmax) <<std::endl;
std::cout << " (1,0)= " <<sum(imgMax,1, 0, wmax) <<std::endl;

it returns the result of the first and crashes after any suggestions please ?

2016-04-03 07:26:02 -0600 asked a question Segmentation fault (core dumped) image processing c++/opencv

I want to apply a smooth to an image,for that purpose I create the function "sum" Here's my code

double sum(cv::Mat img, int startedX, int startedY, int w) {
double res = 0;
std::cout << "startedX= " << startedX<< "/ startedY= " << startedY<<  std::endl; 
for (int i = startedX - ((w - 1) / 2); i < startedX + ((w + 1) / 2); i++) {
  std::cout << "i= " << i <<  std::endl;    
    for (int j = startedY - ((w - 1) / 2) ; j < startedY + ((w + 1) / 2); j++) {std::cout << " j= " <<j<<  std::endl;
     if ((i >= 0 && i < img.size().width) && (j >= 0  && j < img.size().height)) {      
            res += img.at<float>(i,j); }}}
              return res;}

This is a portion of my main function where the program crashes :

for (int k = 0; k < imgSource.size().width; k++) {
 for (int l = 0; l < imgSource.size().height; l++) {
        if( (k >= 0 && k < imgSource.size().width) && (l >= 0  && l < imgSource.size().height) ) {
      std::cout << "k= "<<k <<"  l= "<<l<< " wmax= "<< wmax<<std::endl; 
      newImgMax.at<float>(k,l) =(float)sum(imgMax,k,l, wmax) / (wmax * wmax);
       }}}

for k=0 and l=0 the program works fine and returns a value but for k=0 and l=1 the call of the function(sum(imgMax,0,1,1)) doesn't pass,it crashes and shows a segmentation fault core dumped.This is my output

k= 0  l= 0 wmax= 1
startedX= 0/ startedY= 0
i= 0
j= 0
k= 0  l= 1 wmax= 1
Segmentation fault (core dumped)
2016-04-03 05:56:22 -0600 received badge  Enthusiast
2016-03-31 13:31:19 -0600 commented question can't modify the pixel value

the function works fine, the program crahsesafter this ligne

 **tmp=sum(imgMax, k, l, wmax);**

and shows me an error "segmentation fault core dumped'

2016-03-31 05:49:02 -0600 commented question can't modify the pixel value

I'm implementing the function "sum" which add the pixels of an image here's the code

float sum(cv::Mat img, int startedX, int startedY, int w) { float res = 0.0f;
for (int i = startedX - ((w - 1) / 2); i < startedX + ((w + 1) / 2); i++) {
    for (int j = startedY - ((w - 1) / 2) ; j < startedY + ((w + 1) / 2); j++)         {
        if ((i >= 0 && i < img.size().width) && (j >= 0  && j < img.size().height)) {
          res =res + img.at<float>(i,j);
                }  }
return res;}

in the main function I can call and edit the return of the function without any problem

 std::cout << "result= " <<sum(imgMax, k, l, wmax)<< std::endl;

but I CAN'T assign it to a float variable

float tmp =0.0f ; tmp=sum(imgMax, k, l, wmax);

my program crashes afterthis lign

2016-03-29 15:23:42 -0600 commented question can't modify the pixel value

I'm implementing the FABEMD(Fast and Adaptive Bidimensional Empirical Mode Decomposition Using Order-Statistics Filter Based Envelope Estimation) Method,it consists in decomposing an image into many BIMFs ,after generating the envelopes(upper(imgMax) and lower(imgMin)) I have to apply an averaging smooth for each one ,newImgMax represents the upper envelope after smoothing and it will be used to calculate the first BIMF :

for (int k = 0; k < input.size().width; k++) {
   for (int l = 0; l < input.size().height; l++) {
       if( (k >= 0 && k < input.size().width) && (l >= 0  && l < input.size().height) ) {
         newImgMax.at<float>(k,l) = (sum(imgMax, k, l, wmax) / (wmax * wmax));} } }
2016-03-29 11:37:47 -0600 asked a question can't modify the pixel value

Hi everyone,

I want to smooth an image with opencv/c++,here's my code

newImgMax.at<float>(k,l) = (sum(imgMax, k, l, wmax) / (wmax * wmax));

my function sum works fine,I can edit the result of the function but I can't assign it to a pixel,the function sum returns a float and when I try to assign it to a float variable(not a pixel) I can't too.Any help please ?