Wednesday, 31 July 2013

Configuring OpenCV 2.4.5, Eclipse CDT (Juno), MinGW (x86) on Windows 7

Eclipse CDT Juno was already installed.

My procedure was as follows:

 1. Download and install MinGW and add to the system PATH with  c:/mingw/bin

 2. Download cmake from and install it

 3. Download OpenCV2.4.5 Windows version

 4. Install/unzip Opencv to C:\OpenCV245PC\ (README,index.rst and CMakeLists.txt are here with all subfolders)

 5. Run CMake GUI tool

 6. Choose C:\OpenCV245PC\ as source

 7. Choose the destination, C:\OpenCV245MinGW\x86  where to build the binaries

 8. Press Configure button, choose MinGW Makefiles as the generator. There are some red highlights in the window, choose options as you need. 

 9. Press the Configure button again. Configuring is now done.

 10. Press the Generate button.

 11. Exit the program when the generating is done.

 12. Exit the Cmake program.

 13. Run the command line mode (cmd.exe) and go to the destination directory C:\OpenCV245MinGW\x86

 14. Type "mingw32-make" (without quotation marks). You will see a progress of building binaries. If the command is not found, you must make sure that the system PATH is added with c:/mingw/bin. The build continues according the chosen options to a completion.

 15. In Windows system PATH (My Computer > Right button click > Properties > Advanced > Environment Variables > Path) add the destination's bin directory, C:\OpenCV245MinGW\x86\bin


 17. Go to the Eclipse CDT IDE, create a C++ program using the sample OpenCV code (You can use code from top of this topic).

 18. Go to Project > Properties > C/C++ Build > Settings > GCC C++ Compiler > Includes, and add the source OpenCV folder (including quotation marks) "C:\OpenCV245PC\build\include"

 19. Go to Project > Properties > C/C++ Build > Settings > MinGW C++ Linker > Libraries, and add to the Libraries (-l)ONE BY ONE (this could vary from project to project, you can add all of them if you like or some of them just the ones that you need for your project): 
(for later version like opencv 2.4.6 change below 245 number to 246)opencv_calib3d245

 20. Add the built OpenCV library folder (including quotation marks),  "C:\OpenCV245MinGW\x86\lib" to Library search path (-L)

You can use this code to test your setup:

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/opencv.hpp>
#include <iostream>

using namespace std;
using namespace cv;

int main()

Mat img = imread("c:/lenna.png", CV_LOAD_IMAGE_COLOR);

namedWindow("MyWindow", CV_WINDOW_AUTOSIZE);
imshow("MyWindow", img);

return 0;

Don't forget to put image to the C:\ (or wherever you might find suitable, just be sure that eclipse have read acess.

Friday, 24 August 2012

How to make Windows 7 Bootable USB Pendrive

Many of us face a lot of problem when we have to reinstall windows on our computer or laptop. First thing we have to decide from where to install windows? The options available are DVD or USB Pendrive. In the latest new netbooks, mostly there is no DVD drive. So if you want to install windows you have to go with the other option, i.e. USB Pendrive. So here I give a brief and 100% tested tutorial on how to create a Windows 7 Bootable USB Pendrive to install Windows 7 from USB Pendrive.
First thing, you should check whether your BIOS supports booting from USB. Most of the computer/laptops support. But if your BIOS doesn’t, then sorry, you cannot boot from a USB Pendrive.
Second thing, you need another computer with Windows installed with a DVD drive, to copy its contents later.
So let us start with the procedure now:
1) Run command prompt (cmd). This can be done by clicking start and typing typing cmd in Windows 7. In Windows Xp, click on start and then click on run. Type cmd and run. This will open the command prompt which will look like this:
2) Then run diskpart utility from command prompt, by typing ‘diskpart’ on command prompt and pressing enter. This will run the diskpart utility in a separate windows, which is shown in 2nd picture below:
3) Now put in your pendrive in a USB port. Your pen drive must be atleast 4 GB, 8 GB pendrive is best for this purpose. Now go back to the diskpart console and type ‘listdisk’ and press enter. This will list the various storage devices available. You can see the size column of the disk and here we can see that ‘disk 2′ is our pen drive. Warning: In your computer it may be some other number. In our case it is ‘disk 2′.
4) Then you have to type ‘select disk 2′ and press enter. Note: in our case it is disk 2, in your case it may be disk 3, or disk 1 or any other number. You can enter ‘detail disk’ to see the details of the disk after selecting it to verify that you have selected the correct disk. You can see these steps in the image below:
5) Then you have to run a series of commands. The commands to be run in the order are:- clean
- create partition primary
- select partition 1
- active
- format fs=fat32
These steps are shown in the image below:
Please help us in paying our Server maintenance cost by clicking on the ad below.

6) The format step will take some time. You can have a tea or coffee in the meantime and come back. After the format is complete you have to run ‘assign’ command. And after this you can exit diskpart utility by entering the ‘exit’ command. The steps are shown below:
- assign
- exit
- The image below shows all the steps taken from the first step:
7) After the format is complete, put in your original Windows 7 DVD in your DVD drive, or if you have an .iso image of the DVD, mount that image using any virtual drive software like Power ISO.
- Now go to My Computer, and open the contents of DVD Drive. Press ‘ctrl+a’ to select all contents and copy all the contents by pressing ‘ctrl+c’.
- Now go back to My Computer and open the USB Drive and press ‘ctrl+v’ to paste all the contents of DVD into the USB Disk.

 When the copy finishes, you are done just remove the USB Drive safely and use it to install Windows 7 in your computer/laptop.

Saturday, 18 August 2012

android tutorial

10. Tutorial: Your first Android project

10.1. Install the demo application

This application is also available on the Android Marketplace under Android Temperature converter .
Alternatively you can also scan the following barcode with your Android smartphone to install it via the Google Play application.

QR Code to install the Android Temperature converter

10.2. Create Project

Select FileNewOtherAndroidAndroid Project and create the Android project "". Enter the following.

New Android Project Wizard

New Android Project Wizard - Android Target

New Android Project Wizard - Package Definition

Press "Finish". This should create the following directory structure.

Android Project Structure

10.3. Modifying resources

As described in the Android Development Tools (ADT) chapter, ADT provides specialized editors for resources files, e.g. layout files. These editors allow to switch between the XML representation of the file and a richer user interface via tabs on the bottom of the editor.
The following description uses the rich user interface to build layout files. For validation purposes, the resulting XML is also included in the description.

10.4. Create attributes

Android allows you to create static attributes, e.g. Strings or colors. These attributes can for example be used in your XML layout files or referred to via Java source code.
Select the file "res/values/string.xml" and press the Add button. Select "Color" and enter "myColor" as the name and "#3399CC" as the value.

Adding Android Attributes

Details for a String

Add the following "String" attributes. String attributes allow the developer to translate the application at a later point.

Table 1. String Attributes
Name Value
celsius to Celsius
fahrenheit to Fahrenheit
calc Calculate

Switch to the XML representation and validate that the values are correct.

<?xml version="1.0" encoding="utf-8"?>
  <string name="hello">Hello World, Convert!</string>
  <string name="app_name">Temperature Converter</string>
  <color name="myColor">#3399CC</color>
  <string name="myClickHandler">myClickHandler</string>
  <string name="celsius">to Celsius</string>
  <string name="fahrenheit">to Fahrenheit</string>
  <string name="calc">Calculate</string>

10.5. Add Views

Select "res/layout/main.xml" and open the Android editor via a double-click. This editor allows you to create the layout via drag and drop or via the XML source code. You can switch between both representations via the tabs at the bottom of the editor. For changing the position and grouping elements you can use the Eclipse "Outline" view.
The following shows a screenshot of the "Palette" view from which you can drag and drop new user interface components into your layout. Please note that the "Palette" view changes frequently so your view might be a bit different.

Palette for the Android Layout Editor

You will now create your new layout.
Right-click on the existing text object “Hello World, Hello!” in the layout. Select "Delete" from the popup menu to remove the text object. Then, from the “Palette” view, select Text Fields and locate "Plain Text". Drag this onto the layout to create a text input field. All object types in the section "Text Fields” derive from the class "EditText", they just specify via an additional attribute which text type can be used.
Afterwards select the Palette section "Form Widgets" and drag a “RadioGroup” object onto the layout. The number of radio buttons added to the radio button group depends on your version of Eclipse. Make sure there are two radio buttons by deleting or adding radio buttons to the group.
From the Palette section Form Widgets, drag a Button object onto the layout.
The result should look like the following.

Current layout of main.xml

Switch to main.xml and verify that your XML looks like the following.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=""
    android:orientation="vertical" >

        android:text="EditText" >

        android:layout_height="wrap_content" >

            android:text="RadioButton" >

            android:text="RadioButton" >

        android:text="Button" >


10.6. Edit View properties

If you select a user interface component (an instance of View), you can change its properties via the Eclipse "Properties" view. Most of the properties can be changed via the right mouse menu. You can also edit properties of fields directly in XML. Changing properties in the XML file is much faster, if you know what you want to change. But the right mouse functionality is nice, if you are searching for a certain property.
Open your main.xml layout file . The EditText control shows currently a default text. We want to delete this initial text in the XML code. Switch to the XML tab called main.xml and delete the android:text="EditText" property from the EditText part. Switch back to the "Graphical Layout" tab and check that the text is removed.
Use the right mouse click on the first radio button to assign the "celsius" String attribute to its "text" property. Assign the "fahrenheit" string attribute to the second radio button.

Change the text property of the radio button

Selection of the right text from the pre-defined string values

From now on, I assume you are able to use the properties menu on user interface components. You can always either edit the XML file or modify the properties via right mouse click.
Set the property "Checked" to true for the first RadioButton.
Assign "calc" to the text property of your button and assign "myClickHandler" to the onClick property.
Set the "Input type" property to "numberSigned" and "numberDecimal" on your EditText.
All your user interface components are contained in a LinearLayout. We want to assign a background color to this LinearLayout. Right-click on an empty space in Graphical Layout mode, then select Other PropertiesAll by NameBackground. Select “Color” and then select "myColor" "in the list which is displayed.

New look of the layout after the changes

Switch to the main.xml tab and verify that the XML is correct.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=""
    android:orientation="vertical" >

        android:inputType="numberDecimal|numberSigned" >

        android:layout_height="wrap_content" >

            android:text="@string/celsius" >

            android:text="@string/fahrenheit" >

        android:text="@string/calc" >


10.7. Change the Activity source code

During the generation of your new Android project you specified that an Activity called ConvertActivity should be created. The project wizard created the corresponding Java class.
Change your code in to the following. Note that the myClickHandler will be called based on the OnClick property of your button.


import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.Toast;

public class ConvertActivity extends Activity {
  private EditText text;

  public void onCreate(Bundle savedInstanceState) {
    text = (EditText) findViewById(;


  // This method is called at button click because we assigned the name to the
  // "On Click property" of the button
  public void myClickHandler(View view) {
    switch (view.getId()) {
      RadioButton celsiusButton = (RadioButton) findViewById(;
      RadioButton fahrenheitButton = (RadioButton) findViewById(;
      if (text.getText().length() == 0) {
        Toast.makeText(this, "Please enter a valid number",

      float inputValue = Float.parseFloat(text.getText().toString());
      if (celsiusButton.isChecked()) {
      } else {

  // Converts to celsius
  private float convertFahrenheitToCelsius(float fahrenheit) {
    return ((fahrenheit - 32) * 5 / 9);

  // Converts to fahrenheit
  private float convertCelsiusToFahrenheit(float celsius) {
    return ((celsius * 9) / 5) + 32;

10.8. Start Project

To start the Android Application, select your project, right click on it, and select Run-AsAndroid Application. If an emulator is not yet running, it will be started. Be patient, the emulator starts up very slowly.
You should get the following result.

The running application in the emulator

Type in a number, select your conversion and press the button. The result should be displayed and the other option should get selected.

11. Starting an installed application

After you run your application on the virtual device, you can start it again on the device. If you press the "Home" button you can select your application.

How to select your application from the Android home menu

Selecting the application from the application choicer