2014-06-09 10:09:18 -0600 | asked a question | Segmentation fault when writing to subranges of Mat Hi there, I'm new to OpenCV a have some trouble regarding writing to a subrange of a Mat-Object. The code below iterates a given Image. For each pixel, it takes pixel within a range of 5x5, finds the brightest pixel, and put all other pixel to 0. I call the function multiple times. After a random number of calls the function gives me a segmentation fault or "malloc memory corruption". Sometimes I can call the function 10 times with no problems sometimes only twice, then the program stops. I tracked down the problem to the line, where I write to the original image using the subimage. There is the function that drives me crazy: The Mat-Object is generated using: Please help me understand the problem. If you know a better or more efficient way to achieve the same result please let me know. I am open for any improvements Regards benniz |