Skip to content

Commit 14af582

Browse files
committed
LOAD EVERYTHING!!!!!!!
1 parent 4c2c780 commit 14af582

File tree

429 files changed

+19790
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

429 files changed

+19790
-0
lines changed

01 OpenCV Basics and Image Processing.md

Lines changed: 2793 additions & 0 deletions
Large diffs are not rendered by default.

02 OpenCV Feature Detection and Description.md

Lines changed: 939 additions & 0 deletions
Large diffs are not rendered by default.

03 OpenCV Analysis and Object Tracking.md

Lines changed: 1467 additions & 0 deletions
Large diffs are not rendered by default.

04 OpenCV Machine Learning and AI Detectors.md

Lines changed: 1425 additions & 0 deletions
Large diffs are not rendered by default.

05 OpenCV Optimisation.md

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
# OpenCV Python Optimisation Cheatsheet
2+
3+
Author: methylDragon
4+
Contains a syntax reference and code snippets for OpenCV for Python!
5+
Note that this document is more or less based on the tutorials on https://docs.opencv.org
6+
With some personal notes from me!
7+
8+
------
9+
10+
## Pre-Requisites
11+
12+
### Required
13+
14+
- Python knowledge, this isn't a tutorial!
15+
- OpenCV installed
16+
17+
18+
19+
## 1. Introduction
20+
21+
Not much of an introduction here. OpenCV is just really great!
22+
23+
Since this is a work in progress, it's not going to be very well organised.
24+
25+
```python
26+
# These will have been assumed to have been run
27+
28+
import cv2 as cv2, cv
29+
import numpy as np
30+
```
31+
32+
If you need additional help or need a refresher on the parameters, feel free to use:
33+
34+
```python
35+
help(cv.FUNCTION_YOU_NEED_HELP_WITH)
36+
```
37+
38+
39+
40+
## 2. Optimisation
41+
42+
### Enabling Optimisation
43+
44+
```python
45+
cv.useOptimized() # Returns True if optimisation is enabled
46+
cv.setUseOptimized(True) # Set it to True
47+
```
48+
49+
50+
51+
### Measuring Performance
52+
53+
Timing your code is important!
54+
55+
**Tick comparison**
56+
57+
```python
58+
cv.getTickCount() # Current clock cycles
59+
cv.getTickFrequency() # Number of clock cycles per second
60+
61+
# Example use
62+
e1 = cv.getTickCount()
63+
# your code execution
64+
e2 = cv.getTickCount()
65+
time = (e2 - e1)/ cv.getTickFrequency()
66+
```
67+
68+
**Using Timeit**
69+
70+
**Example**
71+
72+
```python
73+
import timeit
74+
75+
def performSearch(array):
76+
array.sort()
77+
78+
arrayTest = ["X"]*1000
79+
80+
if __name__ == "__main__":
81+
print(timeit.timeit("performSearch(arrayTest)",
82+
"from __main__ import performSearch, arrayTest",
83+
repeat=3,
84+
number=10))
85+
```
86+
87+
88+
89+
### Cython
90+
91+
- Cython code compiles to C, making it way faster than just pure Python code!
92+
- Install Cython with `pip install cython` or `conda install cython`
93+
94+
**Note: Using Cython to optimise your OpenCV script will only work generally for the for loops, since the OpenCV Python API is actually a Python wrapper for already fairly optimised C++ code.**
95+
96+
Ok!
97+
98+
So.... You're going to need to check the Cython reference I made, or know how to use Cython. But generally...
99+
100+
You need a
101+
102+
**setup.py**
103+
104+
```cython
105+
from distutils.core import setup
106+
from Cython.Build import cythonize
107+
108+
setup(
109+
ext_modules = cythonize('script_file.pyx'
110+
)
111+
```
112+
113+
**script_file.pyx**
114+
115+
```cython
116+
# Source: https://www.pyimagesearch.com/2017/08/28/fast-optimized-for-pixel-loops-with-opencv-and-python/
117+
118+
import cython
119+
120+
@cython.boundscheck(False)
121+
cpdef unsigned char[:, :] threshold_fast(int T, unsigned char [:, :] image):
122+
# set the variable extension types
123+
cdef int x, y, w, h
124+
125+
# grab the image dimensions
126+
h = image.shape[0]
127+
w = image.shape[1]
128+
129+
# loop over the image
130+
for y in range(0, h):
131+
for x in range(0, w):
132+
# threshold the pixel
133+
image[y, x] = 255 if image[y, x] >= T else 0
134+
135+
# return the thresholded image
136+
return image
137+
```
138+
139+
And then compile it with
140+
141+
```shell
142+
$ python3 setup.py build_ext --inplace
143+
```
144+
145+
Then import it!
146+
147+
```python
148+
from script_file import threshold_fast
149+
150+
# Now you can use it!
151+
```
152+
153+
154+
155+
```
156+
. .
157+
. |\-^-/| .
158+
/| } O.=.O { |\
159+
```
160+
161+
162+
163+
------
164+
165+
[![Yeah! Buy the DRAGON a COFFEE!](assets/COFFEE%20BUTTON%20%E3%83%BE(%C2%B0%E2%88%87%C2%B0%5E).png)](https://www.buymeacoffee.com/methylDragon)
166+

README.md

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,106 @@
11
# opencv-python-reference
22
An (almost) fully comprehensive reference for OpenCV!
3+
4+
**Comes with Code Snippets, Resources, Pictures (Some are animated), Explanations, Parameter Descriptions, and more!**
5+
6+
---
7+
8+
![Image result for opencv logo](assets/OpenCV_Logo_with_text.png)
9+
10+
11+
12+
Sometimes it's just nice to have everything you need, all the bits and pieces of code all easily retrievable from a single source. It's like making lego bricks for your code!
13+
14+
I found that this kind of pre-loading of all the retrieval work makes my workflow a lot more streamlined, and I save a lot of time for the time invested into preparing these references. It also makes it so that I'm forced to read through all the documentation and understand it.
15+
16+
So, here's a reference that covers almost every function and functionality in OpenCV!
17+
18+
**-CH3EERS**
19+
20+
21+
22+
## Support my efforts!
23+
24+
[![Yeah! Buy the DRAGON a COFFEE!](assets/COFFEE%20BUTTON%20%E3%83%BE(%C2%B0%E2%88%87%C2%B0%5E).png)](https://www.buymeacoffee.com/methylDragon)
25+
26+
[Or leave a tip! ヾ(°∇°*)](https://www.paypal.me/methylDragon)
27+
28+
---
29+
30+
## Reference Map
31+
32+
1. **Basics and Image Processing**
33+
- OpenCV Basic Commands
34+
- Windows, Operations, Drawing, Interaction
35+
- Basic Image Operations
36+
- Basic Image Processing
37+
- Transformations, Convolutions, Morphological Transformations, Gradients, Pyramids
38+
- Advanced Image Processing
39+
- Canny, Histogram Equalisation, Hough Lines and Circles, Blob Detection, Denoising, Inpainting, Fourier, HDR, Template Matching, Watershed
40+
- Contours
41+
- Histograms
42+
- Saliency API
43+
2. **Feature Detection and Description**
44+
- Harris Corner
45+
- Shi-Tomasi
46+
- Key Points
47+
- Keypoint Detectors
48+
- FAST
49+
- SIFT
50+
- SURF
51+
- BRIEF
52+
- ORB
53+
- Final Notes
54+
- Feature Matching
55+
- Brute Force
56+
- FLANN
57+
- Homography
58+
3. **Video and Image Analysis, and Object Tracking**
59+
- Optical Flow
60+
- Lucas-Kanade
61+
- Dense
62+
- Background Subtraction
63+
- Camera Calibration
64+
- Camera Properties
65+
- Calibration
66+
- Undistortion
67+
- Pose Estimation
68+
- Depth Map
69+
- Meanshift
70+
- Camshift
71+
- Centroid Tracking
72+
- Single and Multi-Object Tracking
73+
- Single and Multi-Object Tracking with dlib (and Multiprocessing!)
74+
- Footfall Tracking
75+
4. **Machine Learning and AI Detectors**
76+
- k-Nearest Neighbours (With OCR example)
77+
- K-Means Clustering (With Colour Quantisation example)
78+
- Support Vector Machines (With OCR example)
79+
- Non-maximum Suppression
80+
- Haar Cascades
81+
- Facial Landmarks with dlib
82+
- Caffe Face Detection
83+
- Loading Neural Nets with OpenCV
84+
- YOLO
85+
- Mask R-CNN
86+
- Applications
87+
- Face Recognition
88+
- Facial Clustering
89+
5. **Optimisation**
90+
- Enabling optimisation
91+
- Measuring performance
92+
- Cython
93+
94+
95+
96+
## Credits
97+
98+
All credits and sources are listed inside the tutorials and references themselves.
99+
100+
101+
102+
```
103+
. .
104+
. |\-^-/| .
105+
/| } O.=.O { |\
106+
```
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
HERE! https://pjreddie.com/darknet/yolo/

Resources/Models/YOLO/coco.names

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
person
2+
bicycle
3+
car
4+
motorbike
5+
aeroplane
6+
bus
7+
train
8+
truck
9+
boat
10+
traffic light
11+
fire hydrant
12+
stop sign
13+
parking meter
14+
bench
15+
bird
16+
cat
17+
dog
18+
horse
19+
sheep
20+
cow
21+
elephant
22+
bear
23+
zebra
24+
giraffe
25+
backpack
26+
umbrella
27+
handbag
28+
tie
29+
suitcase
30+
frisbee
31+
skis
32+
snowboard
33+
sports ball
34+
kite
35+
baseball bat
36+
baseball glove
37+
skateboard
38+
surfboard
39+
tennis racket
40+
bottle
41+
wine glass
42+
cup
43+
fork
44+
knife
45+
spoon
46+
bowl
47+
banana
48+
apple
49+
sandwich
50+
orange
51+
broccoli
52+
carrot
53+
hot dog
54+
pizza
55+
donut
56+
cake
57+
chair
58+
sofa
59+
pottedplant
60+
bed
61+
diningtable
62+
toilet
63+
tvmonitor
64+
laptop
65+
mouse
66+
remote
67+
keyboard
68+
cell phone
69+
microwave
70+
oven
71+
toaster
72+
sink
73+
refrigerator
74+
book
75+
clock
76+
vase
77+
scissors
78+
teddy bear
79+
hair drier
80+
toothbrush

0 commit comments

Comments
 (0)