variable assignment

Mar 31, 2016 at 8:21pm
I'm implementing the function "sum" which add the pixels of an image here's the code
1
2
3
4
5
6
7
 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 but I CAN'T assign it to a float variable
tmp=sum(imgMax, k, l, wmax); my program crashes after this assignment and shows me this error "Segmentation fault (core dumped)" any help please ?
Last edited on Mar 31, 2016 at 8:22pm
Mar 31, 2016 at 8:26pm
That usually means you have some sort of out of bounds access on an array that corrupted your stack. I'm guessing it has something to do with line 5 that is writing outside of memory you control.
Mar 31, 2016 at 8:40pm
The function returns a result :
 
std::cout << "result= " <<sum(imgMax, k, l, wmax)<< std::endl;

BUT I can't assign it to a variable
Topic archived. No new replies allowed.