Open b005t3r opened 5 years ago
We can always use something like Valgrind or Address Sanitizer for that: https://github.com/deeplearning4j/libnd4j/wiki/Debugging-libnd4j http://btorpey.github.io/blog/2014/03/27/using-clangs-address-sanitizer/
Actually, I think I found the cause of this (however, haven't tried a fix yet).
Here's my example code first:
Mat img = ... // created with byte[]
Mat region = new Mat(img, rect); // cut out just a part of the image for processing
MatVector channels = new MatVector();
split(region, region);
Mat red = channels.get(2);
Mat green = channels.get(1);
Mat blue = channels.get(0);
threshold(green, green, 40, 255, THRESH_TOZERO); // keep pixels above value
Mat redMask = new Mat();
compare(green, red, redMask, CMP_GT);
Mat blueMask = new Mat();
compare(green, blue, blueMask, CMP_GT);
Mat mask = new Mat();
threshold(green, mask, 1, 255, THRESH_BINARY); // keep pixels above value
bitwise_and(redMask, mask, mask);
bitwise_and(blueMask, mask, mask);
// sometimes more or less at this point I notice that red, green and blue have been dellocated internally - set to 0 cols and rows, etc. - but heir corresponding masks aren't
I'll try to work around that by allocating red
, green
and blue
and putting them in the MatVector
before calling split()
. I hope that works, but it looks like an issue with memory management in JavaCPP (at least that's my best guess at the moment).
Use PointerScope to get more control over memory management: http://bytedeco.org/news/2018/07/17/bytedeco-as-distribution/
I'll try that as well, but could you explain how it works exactly (and does it have a negative impact on performance)? Does it "lock" or allocations until the scope is released, so nothing allocated in that scope will get released before exiting the scope?
Something like that, as explained on the post and in the docs. If there's anything unclear after reading those, let me know.
Maybe this was a bug with OpenCV? Please try again with OpenCV 4.3.0 and see what that gives.
I'm getting this weird native code crash once in a while:
You can see that the crash originated in:
org.bytedeco.opencv.global.opencv_core.mean
Is there any way to check what this actually might be (there's no information logged to std err or std out)?