How to start practicing OpenCV on VC++? Configurations of the VC++ project with OpenCV

In this post, we only take a look at how to config the VC++ project, in order to use the OpenCV. Suppose we have already successfully installed the OpenCV2.3.1. Version name may be different, but the steps are almost the same.


We need 3 steps:
  1. Create a new project.
  2. Make the configurations.
  3. Testing.





1. Create a new project.


    Note. You will need to make the configurations every time create a new project. Make the configurations.
   
Just press  File-->New-->Project, and choose the win32 console application and input a project name,     to create a new project.

2. Make the configurations.

    (1) Open project properties.
          


(2)   Add paths

In the VC++ Directories--Include Direstories
Add "C:\OpenCV2.3.1\build\include\;C:\OpenCV2.3.1\build\include\opencv;C:\OpenCV2.3.1\build\include\opencv2"  

In the VC++ Directories--Include Direstories
Add  "C:\OpenCV2.3.1\build\x86\vc10\lib"


In the C/C++--Additional Include Directories
Add C:\OpenCV2.3.1\build\include\;C:\OpenCV2.3.1\build\include\opencv;C:\OpenCV2.3.1\build\include\opencv2


In the  --Linker--Input--Additional Dependencies, choose Debug and Release then add respectively:


Debug :

opencv_calib3d231d.lib; opencv_contrib231d.lib; opencv_core231d.lib; opencv_features2d231d.lib; opencv_flann231d.lib; opencv_gpu231d.lib; opencv_highgui231d.lib; opencv_imgproc231d.lib; opencv_legacy231d.lib; opencv_ml231d.lib; opencv_objdetect231d.lib; opencv_ts231d.lib; opencv_video231d.lib  

Release:

opencv_calib3d231d.lib; opencv_contrib231d.lib; opencv_core231d.lib; opencv_features2d231d.lib; opencv_flann231d.lib; opencv_gpu231d.lib; opencv_highgui231d.lib; opencv_imgproc231d.lib; opencv_legacy231d.lib; opencv_ml231d.lib; opencv_objdetect231d.lib; opencv_ts231d.lib; opencv_video231d.lib;



       



3. Testing

    Copy this code and run the program, see if the opencv is right configured.


01 #include "stdafx.h"
02 
03 #include <opencv2/opencv.hpp>
04 
05 using namespace std;
06 using namespace cv;
07 
08 int main(int argc, char* argv[])
09 {
10    const char* imagename = "Lena.jpg";
11 
12    //Read an image
13    Mat img = imread(imagename);
14 
15    //If read failed
16    if(img.empty())
17    {
18        fprintf(stderr, "Can not load image %s\n", imagename);
19        return -1;
20    }
21 
22    //Show Image
23    imshow("image", img);
24 
25    //wait a key to return
26    waitKey();
27 
28    return 0;
29 }

Forget the root password? Let's reset the Ubuntu root password!


Many users like me, always are troubling with tons of passwords using computer. Especially somewhere you don't always log in, for example----the other operating system Ubuntu. One of the superior features Ubuntu system bring us is the Authorization Management. However this double-edge sword always make me crazy, when losing the password!!!

I write this post to remember how to reset the Ubuntu password.


You need only 3 easy steps: 

1. Get into the Ubuntu recovery mode.
2. Type some commands to reset the password.
3. Reboot the system.




OK, let's go to a little bit deeper.


1. Get into the Ubuntu recovery mode.

    When you reboot your computer and choose Ubuntu, usually there would be something like this*: 
image
This menu is called 'grub menu'. It is NO PROBLEM if you don't see anything like this but go straight into the system, just reboot again, (if you have the chance to choose windows or Ubuntu, choose Ubuntu) , press  button 'Shift', then you can see the grub menu.

Press enter on the selection of recovery mode, then wait.


2. Type some commands to reset the password.


Once you get into the recovery mode, and see the command line end with '#'. 



Type: grep admin /etc/group

To check the admin user name,  e.g. something like : "admin:x:115:user"


Type: passwd user

To reset the password


Then type your new password twice.



3. Reboot the system.


Type: shutdown -r now 

To reboot the system





*This image used from http://www.howtogeek.com/howto/ubuntu/clean-up-ubuntu-grub-boot-menu-after-upgrades/

Starter 2: Useful tool for fast C++ programming practice under Linux


1. Introduction
2. SciTE
3. g++ compiler
4. HelloWorld.cpp
5. Compile and Run the program




1. Introduction

Last post we talked about the tools Notepad++ and C++ Builder and CMD for programming C++ under Windows system, it is a fast and easy way for starters to practice C++. However, once you have encountered Linux/Unix system, you will find how could this system so beautiful and amazing, especially for our programmers. In this post we try to make an easy way for the programmer rookies even Linux rookies, to start their "Hello World.cpp" under Linux. Let's have a try!

2. SciTE

So, as we use Notepad++ in Windows, a similar test editor(source code editor) called SciTE is that one under Linux system, and also it is FREE! (Barely seen the non-free software under linux, right?). 

Now days, relative newer versions of Ubuntu(one of the famous Linux operating systems) has an easy way to install software named "Ubuntu software Center", instead of the "sudo apt-get install ..." command, this visible, windows-like interface allows you search and install software just like your in windows system. 



Installation. 
My Ubuntu is 10.04LTS, just click "Applications" in the menu bar above the desktop, and find the "Ubuntu Software Center", search the "SciTE" in search bar and click "install". Well done! Then you can find and open the SciTE editor from the "Applications"-->"Programming"-->"SciTE Text Editor".






3. g++ Compiler


g++ is one of the GNU compilers, which is totally FREE and widely used in Linux systems. There is another c/c++ compiler gcc, which is also commonly used in Linux and for most cases it is same as g++. So choose one you like and don't care more about it.

g++/gcc is usually installed once you finished your installation of Linux system. So, you DON'T have to install the compilers on your own. An easy way to check the version of g++/gcc is to use command "--version". Go  into the terminal, type command "g++ --version" or "gcc --version", you can see the version information.





4. HelloWorld.cpp

We still use the code from the last post. Save it anywhere you like, and give a name with extension .cpp to make it a C++ file. 


#include <iostream>

int main(){
 using namespace std;
 char ch;

 cout << "Type, and I shall repeat.\n";
 cin.get(ch);

 while (ch != '.')
   {
     if (ch == '\n')
       cout << ch; // done if newline
     else
       cout << ch;
 
     cin.get(ch);
   }
 return 0;
}
  


5. Compile and Run the program

There are two ways to compile the program. One is using the SciTE eidtor and one use terminal command.

To compile the program in SciTE, just click "Tools"-->"Compile". There will be a command window showed. If there is no error, you can run the program. Because the input stream is ignored in the command window, where only output stream can be showed, you can only run the program in the terminal if your program needs input. (I don't know why, but it happens only under Linux system)



To compile the program in terminal, open terminal, go into the folder where you save your cpp file. Type "g++ HelloWorld.cpp -o HelloWorld" to finish the compiling. If no error occurs, type "./HelloWorld" to run the program. 






Starter: Useful tool for fast C++ programming practice



1. Introduction
2. Notepad++
3. C++ Builder compiler
4. Test.cpp
5. Compile and Run the program




1. Introduction

As a graduate student in Computer Science, I'm always looking for an easy tool for practicing programming or coding in Windows system. It is so boring and time-wasting to use the 'famous' IDEs, e.g. VS, Eclipse, Code:Blocks, NetBeans, etc. You will find such IDE like Visual Stdio is so complicated and slow when you just need a small piece of code running, or just practicing some classic algorithms like quick sort or Dijkstra shortest route. Some say that you can use turbo C++, which was a very good tool for starters, and which is published in 1990s. However for now first you should know if you can find one which can run on your computer, then make sure you'll get used to the "old fashion"---- blue screen and yellow characters.
   
So, when I started to re-learn the programming language by myself these days, facing C++, I recommend the Notepad++ and C++ Builder and CMD as the C++ practicing tool. Such an easy way to read, write, compile and run your cpp program. Let's have a try!

2. Notepad++ (for windows)

    Notepad++ is a free source code editor which support many languages.
    You can download the latest version here: 


    
Just like the notepad in windows, Notepad++ is very easy to use and very suitable for C++ practice.
I choose Notepad++ because: 
    1. It is Free!
    2. It is 
    3. It is Fast and Simple.
    4. It has many useful Shortcuts.

    Install: Just click 'next' all the way down and finish the installing. 


3. C++ Builder compiler

    This the Borland C++ compiler v5.5 free version.
    You can download from:

   
    Install: Just click 'next' all the way down and finish the installing. 

   Important Steps:
   1.After the installing is completed, go into the folder where you install (My is C:\Borland\BCC55\).
   2.Create a new folder (My named CP). 
   3.COPY all the files in folder Bin, Include and Lib to the new folder you just created (My is folder CP).
   

 4. Test.cpp

Here we are! After the previous steps, we can now start our C++ programming and enjoy the convenience of this tool!
Below is my test code named Test.cpp (modified from the book 'C++ Primer plus') :

#include <iostream>

int main(){
 using namespace std;
 char ch;

 cout << "Type, and I shall repeat.\n";
 cin.get(ch);

 while (ch != '.')
   {
     if (ch == '\n')
       cout << ch; // done if newline
     else
       cout << ch;
   
     cin.get(ch);
   }
 return 0;
}
    

When you have the code in the notepad++ editor, save this as a  .cpp file and save it in the folder you just created. (My is C:\Borland\BCC55\CP) 

Note: Don't forget to choose language in your Notepad++ editor, for highlighting the keywords. (Click Language button in the menu bar and choose C and find the C++).



5. Compile and Run the program.

        Now we have the Notepad++ to read and write the C++ code,
        the C++ Builder Compiler to compile the C++ code,
        the windows cmd to run the code.

        So, the final four steps, 
        which are also the steps we'll use in the future to practice the c++ programming :

                   1. Click start in windows run 'cmd' and open the command line.
                   2. Go into the folder where you just created (my is C:\Borland\BCC55\CP).
                   3. Type command 'bcc32 Test.cpp'. This command 'bcc32' is used to compile the cpp files.
                   4. If there is no error, you'll have a file named Test.exe in the same folder. 
                       Just type 'Test' to run the program. 

If there is no error when compiling:


If errors occur, errors would be shown like this: 


Run the program :