Presentation is loading. Please wait.

Presentation is loading. Please wait.

Preparation for Assignment 2

Similar presentations


Presentation on theme: "Preparation for Assignment 2"— Presentation transcript:

1 Preparation for Assignment 2
Practical Session 4 Preparation for Assignment 2 Topics: C++ Eclipse – On Windows. MinGW, msys, OpenCV C++ Compilation Process dos2unix, unix2dos utility makefile

2 Setting up our programing environment
At Home, Windows: IDE: Eclipse for C++ Compiler: MinGW, contains g++ Optional: Unix Like Shell: msys For Assignment 2: OpenCV (external library) At Labs, Linux:

3 C++ Eclipse Eclipse is just an IDE: Download:
Integrated Development Environment Does not provide a compiler! Download: Eclipse IDE for C/C++ Developers Install to C:\eclipse for ease of use.

4 g++ We need a compiler to compile our programs! Download MinGW:
Install: Preferred place: c:\eclipse\MinGW\ While installing select these components: C++ Compiler MinGW Development Toolkit (contains msys)

5 Unix like shell for Windows
Name: msys Why use it? Useful when testing your makefiles! Installation: Already done with MinGW installation. Program path: C:\eclipse\MinGW\msys\1.0\ Exactly like a Linux shell. Can cp, rm, mkdir, and make.

6 Eclipse, MinGW, msys, and $PATH
What is $PATH: Environment variable. Contains paths of certain programs. Why should I care? To let Eclipse know where is the compiler at. Eclipse checks the $PATH variable. Not there? No compiler for eclipse! Where is it? Control Panel\System and Security\System\Advanced System Settings\Environment Variables\PATH How do I change it? Just add “C:\eclipse\MinGW\bin\;c:\eclipse\msys” to its end. Note: Each program path must be separated by “;”.

7 New C++ Project Run Eclipse File -> New -> C++ Project
Project Name: Name of project. Project Type: Executable -> Empty Project Toolchains: MinGW GCC Click on Finish. Create three directories: (good programming style!) “src” for .cpp files. “include” for .h files. “bin” folder for binary (.o and .a) files.

8 OpenCV What is it? Homepage: Note:
Open (Source) Computer Vision Library. An external library. A graphical library. Contains around 500 functions especially made for image processing. Made originally by Intel, maintained today by willowgarage. Homepage: Note: You need to use it as a Black box. You don’t need to understand its code. You don’t need to understand why it works. All you need to know is how to use it! Work with the API only! Learn what the function needs as input. Learn what it returns. Learn what it does! Not how it does it!

9 OpenCV Download: Install path: API:
Install path: C:\eclipse\ It will make a directory named “opencv” under eclipse path. API:

10 Adding OpenCV to project
After creating your project. Goto Project -> Properties C/C++ Build -> Settings GCC C++ Compiler -> Includes Under Include Path we add: c:\eclipse\opencv\build\include MinGW C++ Linker -> Libraries Under Libraries we add: Core OpenCV libraries: opencv_core231 opencv_highgui231 Other OpenCV libraries : opencv_imgproc231 opencv_calib3d231 opencv_feature2d231 opencv_video231 opencv_objdetect231 opencv_ml231 opencv_gpu231 Note: 231 is the library version. In this case: 2.3.1 Under Libraries search path we add: C:\eclipse\opencv\build\x86\mingw\lib

11 Windows and OpenCV If you wish to run the executable file as a standalone, and not from eclipse. You need OpenCV’s dll files. Copy the dll files from: C:\eclipse\opencv\build\x86\mingw\bin To your Windows system directory: C:\Windows\system\ Then you can run any executable program that includes OpenCV code.

12 C++ Compilation Process
Input: C++ Code, .h and .cpp files. Preprocessor: Removes comments interpreting special preprocessor directives denoted by #: #include <math.h> – paste in the standard library math file. #include "My.h" – paste in the file My.h from the same directory (relative path) C++ Compiler: Converts C++ code to Assembly code What is Assembler? Programming language. Lower level than C++ Example code: Assembler: Converts the Assembly code to object code – “.o” files. – this is machine code. Not executable until linking is done! Linker: Takes several object code files, and links them together into an executable “.a” files. Output: Executable file.

13 dos2unix Why? Why should I care? Solution?
Linux and Windows text files are not the same! Windows new line is \r\n Linux new line is \n Why should I care? Work at home? Windows? Work at labs? Unix? Allows you to test your files at the Linux labs if you solved your assignment at home. Solution? Utility that changes the format of text files from DOS format (Windows) to Unix format (Linux). What about the other way around? unix2dos: converts from Linux to DOS format. Usage: dos2unix input.txt output.txt Run this under using msys shell. Note: Your file format must be suitable for Linux testing environment.

14 makefile What is makefile? Why makefile? How do we run it?
It is a text file called “makefile”. Contains functions that allows us to compile c++ programs. Why makefile? Allows us to compile c++ programs with a single command. How do we run it? You use “make” program. make can read the makefile and run the appropriate function depending on user request. Example: make clean This line runs a function named “clean”.

15 makefile example Comment: # All Targets Define Variables: CC, FLAGS, …
# define some Makefile variables for the compiler and compiler flags # to use Makefile variables later in the Makefile: $() CC = g++ CFLAGS = -g -Wall OBJECT_FILES = run.o imageloader.o INCLUDE_LIBRARIES = -I/usr/local/include/opencv -I/usr/local/include SHARED_LIBRARIES = -L/usr/local/lib OPENCV_LIBS = -lopencv_core -lopencv_highgui # All Targets all: run # Tool invocations # Executable "run" depends on the files imageloader.o and run.o. run: $(OBJECT_FILES) @echo 'Building target: run' @echo 'Invoking: C++ Linker' $(CC) $(CFLAGS) $(OBJECT_FILES) -o $(INCLUDE_LIBRARIES) $(SHARED_LIBRARIES) $(OPENCV_LIBS) @echo 'Finished building target: run' @echo ' ' # Depends on the source and header files imageloader.o: src/imageloader.cpp include/imageloader.h $(CC) $(CFLAGS) $< -c -o $(INCLUDE_LIBRARIES) $(SHARED_LIBRARIES) $(OPENCV_LIBS) run.o: src/run.cpp #Clean the build directory clean: rm -rf *.o run Comment: # All Targets Define Variables: CC, FLAGS, … Use Variables: $(CC), $(FLAGS) Function definition: clean: Function with dependencies: all: run Dependencies mean that you run the functions that your function depends on, then your function after. Printing to ‘Building target: run’ $<: the first item in the dependencies list for this function: 1st $< is src/imageloader.cpp 2nd $< is src/run.cpp -o the output file name is the function name. 1st –o is run 2nd –o is imageloader.o 3rd -o is run.o


Download ppt "Preparation for Assignment 2"

Similar presentations


Ads by Google