welcome to linkAR technical documentation

next previous

Adding Images

In order to start image matching the images must be loaded to the matching pool of the ARmatcher.
The images can be loaded from the local resources, from the internet URL link or from preprocessed .dat files.

We load them in the onCreate method of the HelloARlibActivity

3.1.- Adding images from local resources

Add images to the matching pool from local resources .

    /**Add images from local resources to image matching pool
    * Adding image returns image id assigned to the image in the matching pool.
    * We will save it to know which image was matched
    * (The best practice is to make image adding in another thread to avoid stacks)
    * IMORTANT !!! Decoding large images to Bitmap may result in insufficient memory allocations and application crushing,      
    * therefore large images must be reduced/scaled.*/
    int imageResourceId=R.drawable.dolphins;
    Bitmap bmp = BitmapFactory.decodeResource(getResources(), imageResourceId);	
    int imagePool_Id = aRmatcher.addImage(bmp);
    if(imagePool_Id != -1){
      Log.i(TAG,"image added to the pool with id: " + imagePool_Id);
      Log.i(TAG,"image not added to the pool"); 

3.2.- Adding images from Internet URL link

    /**Add image from URL */
    /**It is possible to load remote images to the image pool by setting a valid URL */ 
    String url = "http://static.panoramio.com/photos/large/70381416.jpg";
    int imagePool_Id_2 = aRmatcher.addImage(url);        
    if(imagePool_Id_2 != -1){
      Log.i(TAG,"image added to the pool with id: " + imagePool_Id_2);
      Log.i(TAG,"image not added to the pool"); 

3.3.- Adding Large (High resolution) images

In android there is a limitation on images size that can be decoded to bitmap , witch can cause application to crush. To avoid this situation image scaling is needed to be done.

The library provides helper functions to handle the image scaling.

    /**Add LARGE (High resolution) image with unique ID*/
    int id=333;
    int maxSize=1200;
     * The API provides a helper function to reduce the image size, to avoid memory allocation errors.
    Bitmap b = aRmatcher.decodeScaledImageFromResource(R.drawable.underworld, maxSize);
      Log.i(TAG,"image added to the pool with id: " + id);
    } else {
      Log.i(TAG,"image not added to the pool"); 

3.4.- Adding images data drom the .dat file

The image can be converted or received in processed format and loaded into the library. You can do that in linkAR Community.

    /**Add image data from .dat file*/
   int imagePool_Id_3 ;
   imagePool_Id_3 = aRmatcher.addImageFromData(path);
     Log.i(TAG,"image added to the pool with id: " + imagePool_Id_3);
   } else {
     Log.i(TAG,"image not added to the pool"); 

next previous