Use opencv 2.4.5 library in Android

Source: Internet
Author: User

On the official website of opencv, how to use the opencv library in Android?ArticleBut according to that article, it is impossible to successfully import the opencv library. Therefore, this article provides the correct method for mounting the database and the sequence of function calls when mounting opencvmanager.


First, this article does not discuss how to mount the opencv library through the static Block Method (because this method is not successful). It discusses how to simultaneously mount the opencv library through the cvcameraviewlistener interface, this is also recommended on the official opencv Website:

Using async Initialization isRecommendedWay for application
Development. It uses the opencv manager to access opencv libraries externally installed in the target system.

The steps for mounting through this method are as follows:

  1. Implement Virtual functions to be implemented by cvcameraviewlistener. In eclipse, You can automatically complete the virtual functions to be implemented.
  2. Define the baseloadercallback callback function interface and implement the onmanagerconnected () method in this class.
    Private baseloadercallback mloadercallback = new baseloadercallback (this) {@ override public void onmanagerconnected (INT status) {Switch (Status) {Case loadercallbackinterface. success: {system. out. println ("opencv loaded successfully");} break; default: {system. out. println ("opencv loaded failed! "); Super. onmanagerconnected (Status);} break ;}}};


  3. Override the onresume method in the activity. after calling the default onresume method, perform synchronous mounting of the opencv Library (version 2.4.5)
    Opencvloader. initasync (opencvloader. opencv_version_2_4_5, this, mloadercallback );

  4. Now we have mounted the opencv library. The key issue is that the classes and methods related to the opencv library cannot be used in the oncreate function, because the opencv library is not mounted yet! Not even if you put the initasync method in oncreate! It took a long time for the blogger to troubleshoot the problem after debugging. You can use the handler method to delay the startup of new threads to wait for the opencv library to load.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.