• Skip to primary navigation
  • Skip to main content
opencv-logo

OpenCV

Open Computer Vision Library

  • Releases
  • Forum
    • OpenCV Forum (New!)
    • Askbot (Old Forum)
  • Courses
    • All Courses
    • Computer Vision I
    • Computer Vision II
    • Deep Learning With PyTorch
  • Store
  • Partnership
    • Development Partnership
    • Gold Sponsorship
    • CUDA
    • ARM
    • Intel
  • Resources
    • News
    • Books
    • Podcast
    • Tools
      • SuperAnnotate
    • Links
    • Media Kit
  • License
  • About

Android Best Practices

General Notes

  • Follow the Android Code Style Guidelines.

Debugging

  • Use Mat.toString() and 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.

Performance

Memory

Memory efficiency should be your first concern. As we all know, memory reallocations are deadly for the device accumulator, so try to avoid them.

  1. Avoid excessive memory allocations and copyings.
  2. 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.

JNI calls

  1. 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 Mat.setTo() instead.
  2. Be careful with OpenCV calls within loops. Better to prepare everything outside the loop and to avoid repetitive JNI-calls.

Become a Member

Stay up to date on OpenCV and Computer Vision news

Join our Newsletter  

General Link

  • About
  • Releases
  • License

Courses

  • Computer Vision I
  • Computer Vision II
  • Deep Learning With PyTorch

Partnership

  • Development Partnership
  • Gold Sponsorship
  • CUDA
  • ARM
  • Intel

Resources

  • News
  • Books
  • Podcast
  • Links
  • Media Kit

Copyright © 2021 , OpenCV team
Contact Us | Privacy Policy | Terms & Conditions

We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.AcceptPrivacy policy