1 / 15

Practical Session 4

Practical Session 4. Preparation for Assignment 2 Topics: C++ Eclipse – On Windows. MinGW, msys, OpenCV C++ Compilation Process dos2unix, unix2dos utility makefile. Setting up our programing environment. At Home, Windows: IDE: Eclipse for C++ Compiler: MinGW, contains g++

sonora
Download Presentation

Practical Session 4

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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: • http://www.cs.bgu.ac.il/~spl121/PracticalSession04

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

  4. g++ • We need a compiler to compile our programs! • Download MinGW: • http://sourceforge.net/projects/mingw/files/latest/download • 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? • 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: • http://opencv.willowgarage.com/wiki/ • 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: • http://sourceforge.net/projects/opencvlibrary/files/opencv-win/2.3.1/OpenCV-2.3.1-win-superpack.exe/download • Install path: C:\eclipse\ • It will make a directory named “opencv” under eclipse path. • API: • http://opencv.itseez.com/ • http://opencv.itseez.com/modules/refman.html

  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: • CoreOpenCV libraries: • opencv_core231 • opencv_highgui231 • OtherOpenCVlibraries : • 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’sdll 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: http://www.assembly.happycodings.com/code1.html • 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? • 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 usingmsys shell. • Note: • Your file format must be suitable for Linux testing environment.

  14. makefile • What is makefile? • 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. • makecan 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, … 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 shell: @echo ‘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 # 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.oimageloader.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) # Depends on the source and header files run.o: src/run.cpp $(CC) $(CFLAGS) $< -c -o $@ $(INCLUDE_LIBRARIES) $(SHARED_LIBRARIES) $(OPENCV_LIBS) #Clean the build directory clean: rm-rf *.o run

More Related