Skip to content

Commit b3410ac

Browse files
committed
Open-CV-Implementations
0 parents commit b3410ac

File tree

4 files changed

+510
-0
lines changed

4 files changed

+510
-0
lines changed

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Open-CV-Implementations
2+
3+
4+
This is a repository of code files which can be used to perform some basic tasks & operations using OpenCV.
5+
6+
7+
## Programs
8+
9+
* [Loading & Displaying Images](https://github.com/altruistcoder/Open-CV-Implementations/blob/master/loading_displaying_images.ipynb):
10+
11+
Python Code to load and display an image using OpenCV.
12+
13+
* [Drawing Geometric Figures on Images](https://github.com/altruistcoder/Open-CV-Implementations/blob/master/drawing_figures_on_image.ipynb):
14+
15+
Python Code to draw geometric figures like lines, rectangles, circles and concentric circles on an image using OpenCV.
16+
17+
* [Geometric Transformations on Images](https://github.com/altruistcoder/Open-CV-Implementations/blob/master/geometric_transformations.ipynb):
18+
19+
Python Code to perform Geometric Transformations like Image Translation, Rotation, Resizing, Flipping and Cropping of an image using OpenCV.

drawing_figures_on_image.ipynb

Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"# Drawing different types of Figures on an Image"
8+
]
9+
},
10+
{
11+
"cell_type": "code",
12+
"execution_count": 1,
13+
"metadata": {},
14+
"outputs": [],
15+
"source": [
16+
"import cv2\n",
17+
"import numpy as np"
18+
]
19+
},
20+
{
21+
"cell_type": "markdown",
22+
"metadata": {},
23+
"source": [
24+
"## Drawing Line"
25+
]
26+
},
27+
{
28+
"cell_type": "code",
29+
"execution_count": 2,
30+
"metadata": {},
31+
"outputs": [],
32+
"source": [
33+
"canvas1 = np.zeros((300, 300, 3), dtype=\"uint8\")\n",
34+
"cv2.imshow(\"Canvas 1\", canvas1)\n",
35+
"\n",
36+
"color1 = (255, 0, 0)\n",
37+
"cv2.line(canvas1, (0, 0), (300, 300), color1)\n",
38+
"cv2.imshow(\"Line1\", canvas1)\n",
39+
"\n",
40+
"color2 = (0, 255, 0)\n",
41+
"cv2.line(canvas1, (300, 0), (0, 300), color2, 5)\n",
42+
"cv2.imshow(\"Line2\", canvas1)\n",
43+
"\n",
44+
"cv2.waitKey(0)\n",
45+
"cv2.destroyAllWindows()"
46+
]
47+
},
48+
{
49+
"cell_type": "markdown",
50+
"metadata": {},
51+
"source": [
52+
"## Drawing Rectangle"
53+
]
54+
},
55+
{
56+
"cell_type": "code",
57+
"execution_count": 3,
58+
"metadata": {},
59+
"outputs": [],
60+
"source": [
61+
"canvas2 = np.zeros((300, 300, 3), dtype=\"uint8\")\n",
62+
"cv2.imshow(\"Canvas 2\", canvas2)\n",
63+
"\n",
64+
"color1 = (120, 200, 160)\n",
65+
"cv2.rectangle(canvas2, (10, 10), (60, 60), color1)\n",
66+
"cv2.imshow(\"Rectangle 1\", canvas2)\n",
67+
"\n",
68+
"color2 = (200, 200, 200)\n",
69+
"cv2.rectangle(canvas2, (210, 210), (250, 250), color2, 7)\n",
70+
"cv2.imshow(\"Rectangle 2\", canvas2)\n",
71+
"\n",
72+
"color3 = (255, 255, 255)\n",
73+
"cv2.rectangle(canvas2, (100, 100), (200, 200), color3, -1) # Value '-1' for thickness is used to fill \n",
74+
" # the rectangle with color\n",
75+
"cv2.imshow(\"Color Filled Rectangle\", canvas2)\n",
76+
"\n",
77+
"cv2.waitKey(0)\n",
78+
"cv2.destroyAllWindows()"
79+
]
80+
},
81+
{
82+
"cell_type": "markdown",
83+
"metadata": {},
84+
"source": [
85+
"## Drawing Circle"
86+
]
87+
},
88+
{
89+
"cell_type": "code",
90+
"execution_count": 4,
91+
"metadata": {},
92+
"outputs": [],
93+
"source": [
94+
"canvas3 = np.zeros((300, 300, 3), dtype=\"uint8\")\n",
95+
"cv2.imshow(\"Canvas 3\", canvas3)\n",
96+
"\n",
97+
"color1 = (120, 200, 160)\n",
98+
"center1 = (canvas3.shape[1]//2, canvas3.shape[0]//2)\n",
99+
"cv2.circle(canvas3, center1, 20, color1)\n",
100+
"cv2.imshow(\"Circle 1\", canvas3)\n",
101+
"\n",
102+
"color2 = (200, 100, 100)\n",
103+
"center2 = (250, 250)\n",
104+
"cv2.circle(canvas3, center2, 40, color2)\n",
105+
"cv2.imshow(\"Circle 2\", canvas3)\n",
106+
"\n",
107+
"color3 = (255, 255, 255)\n",
108+
"center3 = (50, 50)\n",
109+
"cv2.circle(canvas3, center3, 30, color3, -1) # Value '-1' for thickness is used to fill \n",
110+
" # the rectangle with color\n",
111+
"cv2.imshow(\"Circle 3\", canvas3) \n",
112+
"\n",
113+
"\n",
114+
"cv2.waitKey(0)\n",
115+
"cv2.destroyAllWindows()"
116+
]
117+
},
118+
{
119+
"cell_type": "markdown",
120+
"metadata": {},
121+
"source": [
122+
"## Concentric Circles"
123+
]
124+
},
125+
{
126+
"cell_type": "code",
127+
"execution_count": 5,
128+
"metadata": {},
129+
"outputs": [],
130+
"source": [
131+
"canvas4 = np.zeros((300, 300, 3), dtype=\"uint8\")\n",
132+
"cv2.imshow(\"Canvas 4\", canvas4)\n",
133+
"\n",
134+
"for r in range(0, 175, 25):\n",
135+
" cv2.circle(canvas4, (150, 150), r, (255, 0, 0))\n",
136+
"\n",
137+
"cv2.imshow(\"Concentric Circles\", canvas4)\n",
138+
"cv2.waitKey(0)\n",
139+
"cv2.destroyAllWindows()"
140+
]
141+
},
142+
{
143+
"cell_type": "code",
144+
"execution_count": null,
145+
"metadata": {},
146+
"outputs": [],
147+
"source": []
148+
},
149+
{
150+
"cell_type": "code",
151+
"execution_count": null,
152+
"metadata": {},
153+
"outputs": [],
154+
"source": []
155+
},
156+
{
157+
"cell_type": "code",
158+
"execution_count": null,
159+
"metadata": {},
160+
"outputs": [],
161+
"source": []
162+
},
163+
{
164+
"cell_type": "code",
165+
"execution_count": null,
166+
"metadata": {},
167+
"outputs": [],
168+
"source": []
169+
}
170+
],
171+
"metadata": {
172+
"kernelspec": {
173+
"display_name": "Python 3",
174+
"language": "python",
175+
"name": "python3"
176+
},
177+
"language_info": {
178+
"codemirror_mode": {
179+
"name": "ipython",
180+
"version": 3
181+
},
182+
"file_extension": ".py",
183+
"mimetype": "text/x-python",
184+
"name": "python",
185+
"nbconvert_exporter": "python",
186+
"pygments_lexer": "ipython3",
187+
"version": "3.6.5"
188+
}
189+
},
190+
"nbformat": 4,
191+
"nbformat_minor": 2
192+
}

geometric_transformations.ipynb

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

loading_displaying_images.ipynb

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"# Loading and Displaying Images Using OpenCV"
8+
]
9+
},
10+
{
11+
"cell_type": "code",
12+
"execution_count": 1,
13+
"metadata": {},
14+
"outputs": [],
15+
"source": [
16+
"import cv2"
17+
]
18+
},
19+
{
20+
"cell_type": "code",
21+
"execution_count": 18,
22+
"metadata": {},
23+
"outputs": [
24+
{
25+
"name": "stdout",
26+
"output_type": "stream",
27+
"text": [
28+
"Height: 1365 pixels\n",
29+
"Width: 2048 pixels\n",
30+
"Channels: 3 pixels\n",
31+
"Code of Key pressed to destroy the window: 122\n"
32+
]
33+
}
34+
],
35+
"source": [
36+
"image = cv2.imread(\"sample_image.jpg\")\n",
37+
"cv2.imshow(\"Image\", image)\n",
38+
"\n",
39+
"print(\"Height: {} pixels\".format(image.shape[0]))\n",
40+
"print(\"Width: {} pixels\".format(image.shape[1]))\n",
41+
"print(\"Channels: {} pixels\".format(image.shape[2]))\n",
42+
"\n",
43+
"a = cv2.waitKey(0) # waitKey() function returns the ASCII Code of the key pressed to destroy the window.\n",
44+
"print(\"Code of Key pressed to destroy the window:\", a)\n",
45+
"cv2.destroyAllWindows()"
46+
]
47+
},
48+
{
49+
"cell_type": "code",
50+
"execution_count": null,
51+
"metadata": {},
52+
"outputs": [],
53+
"source": []
54+
},
55+
{
56+
"cell_type": "code",
57+
"execution_count": null,
58+
"metadata": {},
59+
"outputs": [],
60+
"source": []
61+
}
62+
],
63+
"metadata": {
64+
"kernelspec": {
65+
"display_name": "Python 3",
66+
"language": "python",
67+
"name": "python3"
68+
},
69+
"language_info": {
70+
"codemirror_mode": {
71+
"name": "ipython",
72+
"version": 3
73+
},
74+
"file_extension": ".py",
75+
"mimetype": "text/x-python",
76+
"name": "python",
77+
"nbconvert_exporter": "python",
78+
"pygments_lexer": "ipython3",
79+
"version": "3.6.5"
80+
}
81+
},
82+
"nbformat": 4,
83+
"nbformat_minor": 2
84+
}

0 commit comments

Comments
 (0)