Android OpenCV Programming

Learning the Packages of OpenCV SDK for Android

Return to OpenCV for Android Tutorials List

In the previous tutorial, you learnt about the file structure of OpenCV SDK for Android. Now, we will learn the packages which are available for us to use in OpenCV SDK for Android. At the end of this tutorial, you will definitely know what OpenCV for android has to offer.

Each package is imported like this:

import org.opencv.core.Mat;

Each packages has java classes which contain functions which you use.

First of all, lets find the packages in the sdk folder manually. On your computer, once you have downloaded the OpenCV SDK, you can browse to the following address in order to find all the OpenCV for Android classes.


There, you will find the following packages (OpenCV 3.0):

Also, when you have created an OpenCV project in Android Studio, you will find the packages in the project browser like this:

Now, I will explain to you the purpose of each and every package so that you learn about OpenCV without any effort :D. You won’t regret coming on my blog 🙂

Note that each package can be imported like this as I told before:

Package  Name Purpose Description
android OpenCV interaction with Android platform This package has functions which can allow you to implement an OpenCV project in your Android device. This package handles interactions between OpenCV and Your phone.
calib3d  Project 3D coordinates of objects in a scene. “calib3d” stands for Camera Calibration and 3D Reconstruction. This package has functions which can determine 3D coordinates of objects. So lets say you have a box in a picture. calib3D functions can project 3D coordinates of that box if you provide “intrinsic” and “extrinsic” coordinates.

There are functions to estimate intrinsic and extrinsic parameters 🙂

core Brain of OpenCV. Does all what OpenCV does elsewhere.  “core” is the core package of OpenCV. This package contains functions which provide the base functionality of OpenCV. This include mathematical and matrix operations, algorithmic procedures and much more.

This library is not responsible for image processing. That library is called “imgproc” and it is discussed below.

engine  Provides basic information about current OpenCV SDK installation in your project  Basically, if in your project, you wish to obrain basic information about your OpenCV SDK such as  its packages, version, SDK path, and list of libraries.

Moreover, you can specify a specific version of OpenCV that user’s phone should download from play store. Pretty cool, right?

features2d  Detect and track features in a a 2D test image/frame  You will use this library to detect features, draw them and track them on the screen.
imgcodecs  Read/write images from your disc  Well, imagine you wish to work on an image that is in your disk instead of receiving it from camera. In this case, you will use this library. Its functions allow you to do the following:

  • Read single image
  • Read multiple images
  • Write an image (output)
  • Read specific formats of images in different ways to suit your project and purpose (encode/decode)
imgproc  Image Processing. DUH!  Whether you have loaded an image, or are using camera as input, you will be needing OpenCV to process the image. Well, “imgproc” is the library that has all the functions that you can use, manipulate and exploit to your liking.

This library has functions and classes which allow you to blur image, draw shapes, compare shapes, write text on image, apply enhancement functions and much, much, much more!

This library also has functions which detect points of interest of your liking.

ml  Machine Learning (Artificial Intelligence)  You can train OpenCV to do do Computer Vision according to your requirements. All you need to do is to teach it.

This library has classes and functions that train OpenCV to perform computer vision job for you 🙂


objdetect  Detect features or an object  This library has functions that give you the ability to implement detection of a specific custom-defined object in an image or camera feed.

Ever heard of Haar like feature detection? You can do that in this library.

photo  Image Enhancement  This library handles Image enhancement.

Want to set ISO? Exposure setting? contrast? Saturation? hue? Shit? Well, this library has all these functionalities and much more! You can calibrate so much.

One interesting feature is de-noising which will let you play with noise in your image ;D. Useful, right?

utils  Compatibility converters to support different formats of data This library has functions that convert image data from one mathematical format into another. For example, you can convert from one matrix format into another for image processing using a specifically designed code. It is a life saver.
video  Video Processing  This library will help you to perform video processing. You can track objects in a video, subtract background, apply video filters and much more.
videoio  Interact with video files  Using this library, you can open video files, open different format of video files and work with them.


This tutorial was brief and was supposed to give you the starting knowledge in order to grow your knowledge about OpenCV by yourself. Let me know in the comments what you think. I will be glad to answer. Now proceed to hte next tutorial 🙂

Return to OpenCV for Android Tutorials List


Codeigniter 2.20 – Uploading files to a folder and Inserting in Database table

Back to CodeIgniter Tutorials

In this tutorial, I am going to show how to upload multiple files into a folder and insert its name in a database table. In an application, we may either have to upload a single or multiple files. Take portfolio page for instance. They allow freelancers to upload multiple files for the same portfolio item. So our goal here is the same. The goals are:

  1. Take one or multiple files as an input.
  2. Once submit is pressed, the file is uploaded.
  3. When the file is uploaded, an its name is inserted in the database table.

In order to understand this tutorial, you must know how to install, and use codeigniter. Follow the following links if you want to learn these steps.

Now lets begin!

In order to upload a file to a folder, first a view is built that takes File as an input and has a submit button. I am using a controller named c_upload and my view is v_uploader

VIEW: v_uploader

I am taking multiple files as an input.

<?php //echo base_url('index.php/c_uploader/do_upload'); ?>

Select One or multiple FilesAllowed files: gif, png, png, pdf

If you wish to upload a single file, then all you need to do is to remove the “multiple” keyword in line 5. Here is the code.

<?php //echo base_url('index.php/c_uploader/do_upload'); ?>

Select One or multiple FilesAllowed files: gif, png, png, pdf


CONTROLLER: c_upload

From view, I am calling a function called do_upload(). I also have another function set_upload_options().

Load these helpers

$this->load->helper("URL", "DATE", "URI", "FORM");

Load these libraries


Load this model


Finally, here are the functions

Note: In set_upload_options() function, you can configure upload path

function do_upload(){


    $files = $_FILES;
    $cpt = count($_FILES['userfile']['name']);
    for($i=0; $i<$cpt; $i++){
        $_FILES['userfile']['name']		= $files['userfile']['name'][$i];
        $_FILES['userfile']['type']		= $files['userfile']['type'][$i];
        $_FILES['userfile']['tmp_name']	= $files['userfile']['tmp_name'][$i];
        $_FILES['userfile']['error']	= $files['userfile']['error'][$i];
        $_FILES['userfile']['size']		= $files['userfile']['size'][$i];    


	    $upload_data 	= $this->upload->data();
		    $file_name 	=   $upload_data['file_name'];
		    $file_type 	=   $upload_data['file_type'];
		    $file_size 	=   $upload_data['file_size'];

	    // Output control
			$data['getfiledata_file_name'] = $file_name;
			$data['getfiledata_file_type'] = $file_type;
			$data['getfiledata_file_size'] = $file_size;
        // Insert Data for current file

        //Create a view containing just the text "Uploaded successfully"
		$this->load->view('upload_success', $data);


private function set_upload_options(){   
	//  upload an image options
    $config = array();
    $config['upload_path'] = './fileselif/';
    $config['allowed_types'] = 'gif|jpg|png|pdf';
    $config['max_size']      = '0';
    $config['overwrite']     = FALSE;

    return $config;

Now the Model code

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class M_upload extends CI_Model {

	function __construct() {

	function M_notice (){
	function insertNotices($arrayOfNoticeFiles){
		$tableName  = "t_notices";
		$inputArray = $arrayOfNoticeFiles;

		$data = array(
			'document_foldername'				=> $inputArray["document_foldername"],
			'document_filename'					=> $inputArray["document_filename"]

		$this->db->insert($tableName, $data); 


/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */

These are the steps explaining the program.

Back to CodeIgniter Tutorials