Skip to content

Commit 3535606

Browse files
authored
Add files via upload
1 parent d602847 commit 3535606

18 files changed

+66893
-0
lines changed

Haarcascades/haarcascade_car.xml

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

Haarcascades/haarcascade_eye.xml

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

Haarcascades/haarcascade_frontalface_default.xml

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

Haarcascades/haarcascade_fullbody.xml

Lines changed: 17030 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 258 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,258 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"## Hi and welcome to your first code along lesson!\n",
8+
"\n",
9+
"#### Reading, writing and displaying images with OpenCV"
10+
]
11+
},
12+
{
13+
"cell_type": "markdown",
14+
"metadata": {},
15+
"source": [
16+
"Let's start by importing the OpenCV libary "
17+
]
18+
},
19+
{
20+
"cell_type": "code",
21+
"execution_count": 1,
22+
"metadata": {},
23+
"outputs": [],
24+
"source": [
25+
"# Press CTRL + ENTER to run this line\n",
26+
"# You should see an * between the [ ] on the left\n",
27+
"# OpenCV takes a couple seconds to import the first time\n",
28+
"\n",
29+
"import cv2"
30+
]
31+
},
32+
{
33+
"cell_type": "code",
34+
"execution_count": null,
35+
"metadata": {},
36+
"outputs": [],
37+
"source": []
38+
},
39+
{
40+
"cell_type": "code",
41+
"execution_count": 2,
42+
"metadata": {},
43+
"outputs": [],
44+
"source": [
45+
"# Now let's import numpy\n",
46+
"# We use as np, so that everything we call on numpy, we can type np instead\n",
47+
"# It's short and looks neater\n",
48+
"\n",
49+
"import numpy as np "
50+
]
51+
},
52+
{
53+
"cell_type": "markdown",
54+
"metadata": {},
55+
"source": [
56+
"Let's now load our first image"
57+
]
58+
},
59+
{
60+
"cell_type": "code",
61+
"execution_count": 3,
62+
"metadata": {},
63+
"outputs": [],
64+
"source": [
65+
"# We don't need to do this again, but it's a good habit\n",
66+
"import cv2 \n",
67+
"\n",
68+
"# Load an image using 'imread' specifying the path to image\n",
69+
"input = cv2.imread('./image_examples/elephant.jpg')\n",
70+
"\n",
71+
"# Our file 'input.jpg' is now loaded and stored in python \n",
72+
"# as a varaible we named 'image'\n",
73+
"\n",
74+
"# To display our image variable, we use 'imshow'\n",
75+
"# The first parameter will be title shown on image window\n",
76+
"# The second parameter is the image varialbe\n",
77+
"cv2.imshow('Test Elephant Image', input)\n",
78+
"\n",
79+
"# 'waitKey' allows us to input information when a image window is open\n",
80+
"# By leaving it blank it just waits for anykey to be pressed before \n",
81+
"# continuing. By placing numbers (except 0), we can specify a delay for\n",
82+
"# how long you keep the window open (time is in milliseconds here)\n",
83+
"cv2.waitKey()\n",
84+
"\n",
85+
"# This closes all open windows \n",
86+
"# Failure to place this will cause your program to hang\n",
87+
"cv2.destroyAllWindows()"
88+
]
89+
},
90+
{
91+
"cell_type": "code",
92+
"execution_count": 7,
93+
"metadata": {},
94+
"outputs": [],
95+
"source": [
96+
"\n",
97+
"\n",
98+
"import cv2 \n",
99+
"\n",
100+
"input = cv2.imread('./image_examples/elephant.jpg')\n",
101+
"\n",
102+
"cv2.imshow('Test Elephant Image', input)\n",
103+
"cv2.waitKey()\n",
104+
"cv2.destroyAllWindows()"
105+
]
106+
},
107+
{
108+
"cell_type": "markdown",
109+
"metadata": {},
110+
"source": [
111+
"### Let's take a closer look at how images are stored"
112+
]
113+
},
114+
{
115+
"cell_type": "code",
116+
"execution_count": 8,
117+
"metadata": {},
118+
"outputs": [],
119+
"source": [
120+
"# Import numpy\n",
121+
"import numpy as np"
122+
]
123+
},
124+
{
125+
"cell_type": "code",
126+
"execution_count": 9,
127+
"metadata": {},
128+
"outputs": [
129+
{
130+
"name": "stdout",
131+
"output_type": "stream",
132+
"text": [
133+
"(519, 778, 3)\n"
134+
]
135+
}
136+
],
137+
"source": [
138+
"print(input.shape)"
139+
]
140+
},
141+
{
142+
"cell_type": "markdown",
143+
"metadata": {},
144+
"source": [
145+
"#### Shape gives the dimensions of the image array\n",
146+
"\n",
147+
"The 2D dimensions are 830 pixels in high bv 1245 pixels wide.\n",
148+
"The '3L' means that there are 3 other components (RGB) that make up this image."
149+
]
150+
},
151+
{
152+
"cell_type": "code",
153+
"execution_count": 10,
154+
"metadata": {},
155+
"outputs": [
156+
{
157+
"name": "stdout",
158+
"output_type": "stream",
159+
"text": [
160+
"Height of Image: 519 pixels\n",
161+
"Width of Image: 778 pixels\n"
162+
]
163+
}
164+
],
165+
"source": [
166+
"# Let's print each dimension of the image\n",
167+
"\n",
168+
"print('Height of Image:', int(input.shape[0]), 'pixels')\n",
169+
"print('Width of Image: ', int(input.shape[1]), 'pixels')"
170+
]
171+
},
172+
{
173+
"cell_type": "markdown",
174+
"metadata": {},
175+
"source": [
176+
"### How do we save images we edit in OpenCV?"
177+
]
178+
},
179+
{
180+
"cell_type": "code",
181+
"execution_count": 11,
182+
"metadata": {},
183+
"outputs": [
184+
{
185+
"data": {
186+
"text/plain": [
187+
"True"
188+
]
189+
},
190+
"execution_count": 11,
191+
"metadata": {},
192+
"output_type": "execute_result"
193+
}
194+
],
195+
"source": [
196+
"# Simply use 'imwrite' specificing the file name and the image to be saved\n",
197+
"cv2.imwrite('output.jpg', input)\n",
198+
"cv2.imwrite('output.png', input)"
199+
]
200+
},
201+
{
202+
"cell_type": "code",
203+
"execution_count": null,
204+
"metadata": {},
205+
"outputs": [],
206+
"source": []
207+
},
208+
{
209+
"cell_type": "code",
210+
"execution_count": null,
211+
"metadata": {},
212+
"outputs": [],
213+
"source": []
214+
},
215+
{
216+
"cell_type": "code",
217+
"execution_count": null,
218+
"metadata": {},
219+
"outputs": [],
220+
"source": []
221+
},
222+
{
223+
"cell_type": "code",
224+
"execution_count": null,
225+
"metadata": {},
226+
"outputs": [],
227+
"source": []
228+
},
229+
{
230+
"cell_type": "code",
231+
"execution_count": null,
232+
"metadata": {},
233+
"outputs": [],
234+
"source": []
235+
}
236+
],
237+
"metadata": {
238+
"kernelspec": {
239+
"display_name": "Python 3",
240+
"language": "python",
241+
"name": "python3"
242+
},
243+
"language_info": {
244+
"codemirror_mode": {
245+
"name": "ipython",
246+
"version": 3
247+
},
248+
"file_extension": ".py",
249+
"mimetype": "text/x-python",
250+
"name": "python",
251+
"nbconvert_exporter": "python",
252+
"pygments_lexer": "ipython3",
253+
"version": "3.7.1"
254+
}
255+
},
256+
"nbformat": 4,
257+
"nbformat_minor": 1
258+
}

0 commit comments

Comments
 (0)