Android Best Practices
Mat.dump() methods for debugging.
- If you develop in C++, debug your code on a host. But be aware of the performance difference. We recommend to develop/debug/optimize C++ code on a host, but please check the real speed of application on a device.
Memory efficiency should be your first concern. As we all know, memory reallocations are deadly for the device accumulator, so try to avoid them.
- Avoid excessive memory allocations and copyings.
- Initialize all the matrices at the application start and reuse them later. Please note that if the matrix doesn’t have required size and depth, OpenCV will reallocate it before usage. Simply create all the matrices with appropriate size and depth for every purpose beforehand and use them everywhere.
- Don’t use too many calls to OpenCV Java API, because JNI-calls are really expensive. For example if you want to fill your image with zeros, don’t use
put method, call the
- Be careful with OpenCV calls within loops. Better to prepare everything outside the loop and to avoid repetitive JNI-calls.