Phaneendrabayi commited on
Commit
4642ed1
·
verified ·
1 Parent(s): 92ea980

Upload Video Handling.ipynb

Browse files
Files changed (1) hide show
  1. Video Handling.ipynb +256 -0
Video Handling.ipynb ADDED
@@ -0,0 +1,256 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 1,
6
+ "id": "856182c8-62ab-4518-81d6-d5560249aa93",
7
+ "metadata": {},
8
+ "outputs": [],
9
+ "source": [
10
+ "import numpy as np\n",
11
+ "import cv2\n",
12
+ "import os"
13
+ ]
14
+ },
15
+ {
16
+ "cell_type": "code",
17
+ "execution_count": null,
18
+ "id": "de553aa5-a3c0-4ad2-aae5-987c34613f67",
19
+ "metadata": {},
20
+ "outputs": [],
21
+ "source": [
22
+ "vid = cv2.VideoCapture(0)\n",
23
+ "while True:\n",
24
+ " succ,img = vid.read()\n",
25
+ "\n",
26
+ " if succ==False:\n",
27
+ " print(\"camera is not working\")\n",
28
+ " break\n",
29
+ "\n",
30
+ " cv2.imshow(\"livestream\",img)\n",
31
+ "\n",
32
+ " if cv2.waitKey(1)&255==ord(\"s\"):\n",
33
+ " break\n",
34
+ "cv2.destroyAllWindows()"
35
+ ]
36
+ },
37
+ {
38
+ "cell_type": "code",
39
+ "execution_count": null,
40
+ "id": "70c605ad-6646-416a-bb11-635db9f14532",
41
+ "metadata": {},
42
+ "outputs": [],
43
+ "source": [
44
+ "vid = cv2.VideoCapture(0)\n",
45
+ "while True:\n",
46
+ " succ,img = vid.read()\n",
47
+ "\n",
48
+ " if succ==False:\n",
49
+ " print(\"camera is not working\")\n",
50
+ " break\n",
51
+ "\n",
52
+ " \n",
53
+ " img1 = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)\n",
54
+ " cv2.imshow(\"livestream\",img)\n",
55
+ " cv2.imshow(\"graystream\",img1)\n",
56
+ " if cv2.waitKey(1)&255==ord(\"s\"):\n",
57
+ " break\n",
58
+ "cv2.destroyAllWindows()"
59
+ ]
60
+ },
61
+ {
62
+ "cell_type": "code",
63
+ "execution_count": null,
64
+ "id": "2d7392d7-9f68-4c85-b1f5-616de8fed9c1",
65
+ "metadata": {},
66
+ "outputs": [],
67
+ "source": [
68
+ "vid = cv2.VideoCapture(0)\n",
69
+ "while True:\n",
70
+ " succ,img = vid.read()\n",
71
+ "\n",
72
+ " if succ==False:\n",
73
+ " print(\"camera is not working\")\n",
74
+ " break\n",
75
+ "\n",
76
+ " b,g,r=cv2.split(img)\n",
77
+ " z = np.zeros(b.shape,dtype=np.uint8)\n",
78
+ " cv2.imshow(\"blue_channel\",cv2.merge([b,z,z]))\n",
79
+ " cv2.imshow(\"green_channel\",cv2.merge([z,g,z]))\n",
80
+ " cv2.imshow(\"red_channel\",cv2.merge([z,z,r]))\n",
81
+ " \n",
82
+ " img1 = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)\n",
83
+ " cv2.imshow(\"livestream\",img)\n",
84
+ " cv2.imshow(\"graystream\",img1)\n",
85
+ " if cv2.waitKey(1)&255==ord(\"s\"):\n",
86
+ " break\n",
87
+ "cv2.destroyAllWindows()"
88
+ ]
89
+ },
90
+ {
91
+ "cell_type": "code",
92
+ "execution_count": 7,
93
+ "id": "dbd0c328-fa32-4634-9b78-d80cc07ab4fe",
94
+ "metadata": {},
95
+ "outputs": [],
96
+ "source": [
97
+ "os.makedirs(r\"C:\\Users\\phanee\\Downloads\\hand_signs\")"
98
+ ]
99
+ },
100
+ {
101
+ "cell_type": "code",
102
+ "execution_count": 11,
103
+ "id": "b9072daf-69fd-475f-b4e9-a0fd02d0313e",
104
+ "metadata": {},
105
+ "outputs": [],
106
+ "source": [
107
+ "vid = cv2.VideoCapture(0)\n",
108
+ "c=0\n",
109
+ "while True:\n",
110
+ " succ,img = vid.read()\n",
111
+ "\n",
112
+ " if succ==False:\n",
113
+ " print(\"camera is not working\")\n",
114
+ " break\n",
115
+ " cv2.imshow(\"livestream\",img)\n",
116
+ "\n",
117
+ " if cv2.waitKey(1)&255==ord(\"s\"):\n",
118
+ " cv2.imwrite(r\"C:\\Users\\phanee\\Downloads\\hand_signs\\{}.jpg\".format(c),img)\n",
119
+ " print(\"images have been captured\")\n",
120
+ " c+=1\n",
121
+ "\n",
122
+ " if cv2.waitKey(1)&255==ord(\"q\"):\n",
123
+ " break\n",
124
+ "cv2.destroyAllWindows()\n",
125
+ " "
126
+ ]
127
+ },
128
+ {
129
+ "cell_type": "code",
130
+ "execution_count": 3,
131
+ "id": "cca05adc-3cec-4bff-a73f-5933a6aa4798",
132
+ "metadata": {},
133
+ "outputs": [],
134
+ "source": [
135
+ "os.makedirs(r\"C:\\Users\\phanee\\Downloads\\hand_signs\\head\")"
136
+ ]
137
+ },
138
+ {
139
+ "cell_type": "code",
140
+ "execution_count": 5,
141
+ "id": "573d4676-2e0b-4c2a-a8f1-51fa5f83b063",
142
+ "metadata": {},
143
+ "outputs": [],
144
+ "source": [
145
+ "os.makedirs(r\"C:\\Users\\phanee\\Downloads\\hand_signs\\smile\")"
146
+ ]
147
+ },
148
+ {
149
+ "cell_type": "code",
150
+ "execution_count": 11,
151
+ "id": "d35a07eb-21af-406a-bec2-f163ef3b4c08",
152
+ "metadata": {},
153
+ "outputs": [],
154
+ "source": [
155
+ "folders = os.listdir(r\"C:\\Users\\phanee\\Downloads\\hand_signs\")"
156
+ ]
157
+ },
158
+ {
159
+ "cell_type": "code",
160
+ "execution_count": 13,
161
+ "id": "a1d723ef-a7b3-426c-b943-f69066d18f3f",
162
+ "metadata": {},
163
+ "outputs": [
164
+ {
165
+ "data": {
166
+ "text/plain": [
167
+ "['0.jpg',\n",
168
+ " '1.jpg',\n",
169
+ " '2.jpg',\n",
170
+ " '3.jpg',\n",
171
+ " '4.jpg',\n",
172
+ " '5.jpg',\n",
173
+ " '6.jpg',\n",
174
+ " '7.jpg',\n",
175
+ " 'head',\n",
176
+ " 'smile']"
177
+ ]
178
+ },
179
+ "execution_count": 13,
180
+ "metadata": {},
181
+ "output_type": "execute_result"
182
+ }
183
+ ],
184
+ "source": [
185
+ "folders"
186
+ ]
187
+ },
188
+ {
189
+ "cell_type": "code",
190
+ "execution_count": 17,
191
+ "id": "437820d0-eca9-41a9-8846-ddbb9eb0cfe4",
192
+ "metadata": {},
193
+ "outputs": [],
194
+ "source": [
195
+ "l =[]\n",
196
+ "for i in folders:\n",
197
+ " if i.endswith(\".jpg\"):\n",
198
+ " l.append(i)"
199
+ ]
200
+ },
201
+ {
202
+ "cell_type": "code",
203
+ "execution_count": 19,
204
+ "id": "fd7eb506-fb1d-41b4-bbe3-b240c9a25174",
205
+ "metadata": {},
206
+ "outputs": [
207
+ {
208
+ "data": {
209
+ "text/plain": [
210
+ "['0.jpg', '1.jpg', '2.jpg', '3.jpg', '4.jpg', '5.jpg', '6.jpg', '7.jpg']"
211
+ ]
212
+ },
213
+ "execution_count": 19,
214
+ "metadata": {},
215
+ "output_type": "execute_result"
216
+ }
217
+ ],
218
+ "source": [
219
+ "l"
220
+ ]
221
+ },
222
+ {
223
+ "cell_type": "code",
224
+ "execution_count": null,
225
+ "id": "f1b3b35e-5627-4ca7-aed3-9b32adc3972d",
226
+ "metadata": {},
227
+ "outputs": [],
228
+ "source": [
229
+ "for i in l:\n",
230
+ " for images in os.listdir(r\"C:\\Users\\phanee\\Downloads\\hand_signs\\{}\".format(i)):\n",
231
+ " img = cv2.imread(r\"C:\\Users\\phanee\\Downloads\\hand_signs\\{}\")"
232
+ ]
233
+ }
234
+ ],
235
+ "metadata": {
236
+ "kernelspec": {
237
+ "display_name": "Python 3 (ipykernel)",
238
+ "language": "python",
239
+ "name": "python3"
240
+ },
241
+ "language_info": {
242
+ "codemirror_mode": {
243
+ "name": "ipython",
244
+ "version": 3
245
+ },
246
+ "file_extension": ".py",
247
+ "mimetype": "text/x-python",
248
+ "name": "python",
249
+ "nbconvert_exporter": "python",
250
+ "pygments_lexer": "ipython3",
251
+ "version": "3.11.7"
252
+ }
253
+ },
254
+ "nbformat": 4,
255
+ "nbformat_minor": 5
256
+ }