Modern C ++ For Computer Vision and Image Processing Lecture 0: The Basics
Modern C ++ For Computer Vision and Image Processing Lecture 0: The Basics
1
Course structure
2
Workload
180 − 60 ℎ
≈8
16 𝑤𝑒𝑒𝑘
3
What you will learn in course
4
How is the course structured?
Part I: C++ basics tools.
Part II: The C++ core language.
Part III: Modern C++.
Part IV: Final project.
5
Course Content
6
Course Philosophy
7
What you will do in this course
8
Please stop me!
9
Why?
Why C++? Why Linux? Why?
0
Image taken from https://circuitdigest.com/
11
Companies that use C++
0
The following slides are adapted from Avery Wang
0
More info at http://www.stroustrup.com/applications.html
12
Browsers written in C++
0
Slides adapted from Avery Wang
13
Software written in C++
14
Games written in C++
15
C++ History: assembly
Benefits:
Unbelievably simple instructions
Extremely fast (when well-written)
Complete control over your program
0
The following slides are adapted from Avery Wang
16
C++ History: assembly
1 main: # @main
2 push rax
3 mov edi , offset std :: cout
4 mov esi , offset .L.str
5 mov edx , 13
6 call std :: basic_ostream <char , std ::
char_traits <char > >& std :: __ostream_insert <char , std
:: char_traits <char > >(std :: basic_ostream <char , std ::
char_traits <char > >&, char const*, long)
7 xor eax , eax
8 pop rcx
9 ret
10 _GLOBAL__sub_I_example.cpp : #
@_GLOBAL__sub_I_example.cpp
11 push rax
12 mov edi , offset std :: __ioinit
13 call std :: ios_base :: Init :: Init () [ complete
object constructor ]
14 mov edi , offset std :: ios_base :: Init ::~ Init
() [ complete object destructor ]
15 mov esi , offset std :: __ioinit
16 mov edx , offset __dso_handle
17 pop rax
18 jmp __cxa_atexit # TAILCALL
19 .L.str :
20 .asciz "Hello , world \n"
17
C++ History: assembly
Drawbacks:
A lot of code to do simple tasks
Hard to understand
Extremely unportable
18
C++ History: Invention of C
Problem:
Computers only understand assembly
language.
Idea:
Source code can be written in a more
intuitive language
An additional program can convert it into
assembly [compiler]
19
C++ History: Invention of C
Cross-platform
20
C++ History: Invention of C
21
C++ History: Welcome to C++
In 1983, the first vestiges of C++ were
created by Bjarne Stroustrup.
22
C++ History: Welcome to C++
23
Evolution of C++
0
Image taken from https://www.modernescpp.com/
24
Design Philosophy of C++
Multi-paradigm
Express ideas and intent directly in code.
Safety
Efficiency
Abstraction
25
0
Icon taken from Wikipedia
What is GNU/Linux?
Linux is a free Unix-like OS
Linux kernel implemented by Linus Torvalds
Extremely popular: Android, ChromeOS,
servers, supercomputers, etc.
Many Linux distributions available
Use any distribution if you have preference
Examples will be given in Ubuntu
26
Linux directory tree
/
SYSTEM USER
Special folders:
/ — root folder
~ — home folder
. — current folder
.. — parent folder
30
Structure of Linux commands
Typical structure
${PATH}/command [ options ] [ parameters ]
31
Use help with Linux programs
Example:
1 [/home/ student ]$ cd D [TAB] [TAB]
2 Desktop / Documents / Downloads /
33
Files and folders
Placeholder Meaning
* Any set of characters
? Any single character
[a-f] Characters in [abcdef]
[ ̂ a-c] Any character not in [abc]
35
1 [/home/ student / Examples / placeholders ]$ ls
2 u01.tex v01.pdf v01.tex
3 u02.tex v02.pdf v02.tex
4 u03.tex v03.pdf v03.tex
5
6 [/home/ student / Examples / placeholders ]$ ls *. pdf
7 v01.pdf v02.pdf v03.pdf
8
9 [/home/ student / Examples / placeholders ]$ ls u*
10 u01.tex u02.tex u03.tex
11
12 [/home/ student / Examples / placeholders ]$ ls ?01*
13 u01.tex v01.pdf v01.tex
14
15 [/home/ student / Examples / placeholders ]$ ls [uv]01*
16 u01.tex v01.pdf v01.tex
17
18 [/home/ student / Examples / placeholders ]$ ls u0[^12].tex
19 u03.tex
36
Standard input/output channels
Single input channel:
stdin: Standard input: channel 0
Two output channels:
stdout: Standard output: channel 1
stderr: Standard error output: channel 2
37
Standard input/output channels
$ program
38
Redirecting stdout
$ program 1>cout.txt
39
Redirecting stderr
$ program 2>cerr.txt
40
Redirect stdout and stderr
$ program 1>stdout.txt 2>stderr.txt
41
Redirect stdout and stderr
progamm 1>out.txt 2>&1
42
Working with files
more/less/cat <filename>
Print the contents of the file
Most of the time using cat if enough
find <in-folder> -name <filename>
Search for file <filename> in folder
<in-folder>, allows wildcards
locate <filename>
Search for file <filename> in the entire
system!
just remember to sudo updatedb often
grep <what> <where>
Search for a string <what> in a file <where>
ag <what> <where>
Search for a string <what> in a dir <where>
43
Chaining commands
https://youtu.be/mV_8GbzwZMM
45
Canceling commands
CTRL + C
Cancel currently running command
kill -9 <pid>
Kill the process with id pid
killall <pname>
Kill all processes with name pname
htop (top)
Shows an overview of running processes
Allows to kill processes by pressing k
46
Command history
47
Installing software
https://youtu.be/oxuRxtrO2Ag
49
0
Icon taken from Wikipedia
We won’t teach you everything
about C++
0
Most icons are from Paper Icon Set: https://snwh.org/paper
51
Hello World!
52
Comments and any whitespace:
completely ignored
A comment is text:
On one line that follows //
Between /* and */
All of these are valid C++:
1 int main () { return 0;} // Ignored comment .
1 int main ()
2
3 { return 0;
4 }
1 int main () {
2 return /* Ignored comment */ 0;
3 }
53
Good code style is important
Programs are meant to be read
by humans and only incidentally
for computers to execute.
-Donald Knuth
Use clang_format to format your code
use cpplint to check the style
Following a style guide will save you time
and make the code more readable
We use Google Code Style Sheet
Naming and style recommendations will be
marked by GOOGLE-STYLE tag in slides
0
https://google.github.io/styleguide/cppguide.html
54
Everything starts with main
1 int main () {
2 return 1; // Program finished with error code 1.
3 }
55
#include directive
Two variants:
#include <file> — system include files
#include "file" — local include files
Copies the content of file into the current file
1 # include " some_file .hpp"
2 // We can use contents of file " some_file .hpp" now.
3 int main () { return 0; }
56
I/O streams for simple
input and output
Handle stdin, stdout and stderr:
std::cin — maps to stdin
std::cout — maps to stdout
std::cerr — maps to stderr
#include <iostream> to use I/O streams
Part of C++ standard library
1 # include <iostream >
2 int main () {
3 int some_number ;
4 std :: cout << " please input any number " << std :: endl;
5 std :: cin >> some_number ;
6 std :: cout << " number = " << some_number << std :: endl;
7 std :: cerr << " boring error message " << std :: endl;
8 return 0;
9 }
57
Compile and run Hello World!
We understand text
Computer understands machine code
Compilation is translation
from text to machine code
Compilers we can use on Linux:
Clang [*] [used in examples]
GCC
58
Credits to Igor the great
https://bit.ly/2JmIqGs [shortened]
59
Suggested Video
”You Should Learn to Program” by
Christian Genco at TEDxSMU
https://youtu.be/xfBWk4nw440
60
C++ Programming Language
Website:
http://www.stroustrup.com/4th.html
61
Best reference
https://en.cppreference.com/w/cpp
62
References
C++ Reference:
https://en.cppreference.com/w/cpp
C++ Tutorial:
http://www.cplusplus.com/doc/tutorial/
63