Skip to content

Commit 14c5a0f

Browse files
committed
init commit
1 parent 8318255 commit 14c5a0f

File tree

3 files changed

+320
-0
lines changed

3 files changed

+320
-0
lines changed

excelProces/excel.py

Whitespace-only changes.

imageProcess/img.jpg

12.3 KB
Loading

imageProcess/python_study.ipynb

+320
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,320 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"OpenCV 이미지 처리\n",
8+
"다양한 이미지 동영상처리에 사용되는 오픈소스"
9+
]
10+
},
11+
{
12+
"cell_type": "markdown",
13+
"metadata": {},
14+
"source": [
15+
"## 빈 이미지 생성하기"
16+
]
17+
},
18+
{
19+
"cell_type": "code",
20+
"execution_count": 2,
21+
"metadata": {},
22+
"outputs": [],
23+
"source": [
24+
"import cv2\n",
25+
"img = cv2.imread('img.jpg')\n",
26+
"cv2.imshow('img',img)\n",
27+
"cv2.waitKey(0)\n",
28+
"cv2.destroyAllWindows()"
29+
]
30+
},
31+
{
32+
"cell_type": "markdown",
33+
"metadata": {},
34+
"source": [
35+
"읽기 옵션\n"
36+
]
37+
},
38+
{
39+
"cell_type": "code",
40+
"execution_count": 3,
41+
"metadata": {},
42+
"outputs": [],
43+
"source": [
44+
"import cv2 \n",
45+
"img1 = cv2.imread('img.jpg', cv2.IMREAD_COLOR)\n",
46+
"img2 = cv2.imread('img.jpg', cv2.IMREAD_GRAYSCALE)\n",
47+
"img3 = cv2.imread('img.jpg', cv2.IMREAD_UNCHANGED)\n",
48+
"\n",
49+
"cv2.imshow('img',img1)\n",
50+
"cv2.imshow('img',img2)\n",
51+
"cv2.imshow('img',img3)\n",
52+
"\n",
53+
"cv2.waitKey(0)\n",
54+
"cv2.destroyAllWindows()"
55+
]
56+
},
57+
{
58+
"cell_type": "markdown",
59+
"metadata": {},
60+
"source": [
61+
"## 동영상파일에서 동열상 가져오기 "
62+
]
63+
},
64+
{
65+
"cell_type": "code",
66+
"execution_count": null,
67+
"metadata": {},
68+
"outputs": [],
69+
"source": [
70+
"import cv2\n",
71+
"cap = cv2.VideoCapture('video.mp4')\n",
72+
"while cap.isOpened()\n",
73+
" ret, frame = cap.read()\n",
74+
" if not ret:\n",
75+
" print ('끝')\n",
76+
" break\n",
77+
" \n",
78+
" cv2. imshow('video',frame)\n",
79+
"\n",
80+
" if cv.waitKey(1) == ord('q'):\n",
81+
" print ('종료')\n",
82+
" break\n",
83+
"cap.release()\n",
84+
"cv2.destroyAllWindows()"
85+
]
86+
},
87+
{
88+
"cell_type": "markdown",
89+
"metadata": {},
90+
"source": [
91+
"## 카메라에서 동영상 가져오기 \n"
92+
]
93+
},
94+
{
95+
"cell_type": "code",
96+
"execution_count": 4,
97+
"metadata": {},
98+
"outputs": [],
99+
"source": [
100+
"import cv2\n",
101+
"cap = cv2.VideoCapture(0)\n",
102+
"\n",
103+
"if not cap.isOpened():\n",
104+
" print('카메라 없음')\n",
105+
" exit()\n",
106+
"\n",
107+
"while True:\n",
108+
" ret, frame = cap.read()\n",
109+
" if not ret:\n",
110+
" break\n",
111+
"\n",
112+
" cv2.imshow('camera',frame)\n",
113+
" if cv2.waitKey(1) == ord ('q'):\n",
114+
" break\n",
115+
"\n",
116+
"cap.release()\n",
117+
"cv2.destroyAllWindows()"
118+
]
119+
},
120+
{
121+
"cell_type": "markdown",
122+
"metadata": {},
123+
"source": [
124+
"## 도형그리기"
125+
]
126+
},
127+
{
128+
"cell_type": "code",
129+
"execution_count": 8,
130+
"metadata": {},
131+
"outputs": [],
132+
"source": [
133+
"\n",
134+
"import cv2\n",
135+
"import numpy as np\n",
136+
"\n",
137+
"img = np.zeros((480,640,3), dtype=np.uint8)\n",
138+
"img[:]=(0,0,0) # B, G, R\n",
139+
"cv2.imshow('img',img)\n",
140+
"cv2.waitKey(0)\n",
141+
"\n",
142+
"cv2.destroyAllWindows()"
143+
]
144+
},
145+
{
146+
"cell_type": "markdown",
147+
"metadata": {},
148+
"source": [
149+
"## 일부영역 색칠"
150+
]
151+
},
152+
{
153+
"cell_type": "code",
154+
"execution_count": 10,
155+
"metadata": {},
156+
"outputs": [],
157+
"source": [
158+
"\n",
159+
"import cv2\n",
160+
"import numpy as np\n",
161+
"\n",
162+
"img = np.zeros((480,640,3), dtype=np.uint8)\n",
163+
"img[:]=(0,0,0) # B, G, R\n",
164+
"\n",
165+
"img[100:200, 200:300] = (255,255,255)\n",
166+
"cv2.imshow('img',img)\n",
167+
"cv2.waitKey(0)\n",
168+
"\n",
169+
"cv2.destroyAllWindows()"
170+
]
171+
},
172+
{
173+
"cell_type": "markdown",
174+
"metadata": {},
175+
"source": [
176+
"## 직선 그리기\n",
177+
"1. cv2.LINE_4\n",
178+
"1. cv2.LINE_8 : 기본값\n",
179+
"1. cv2.LINE_AA"
180+
]
181+
},
182+
{
183+
"cell_type": "code",
184+
"execution_count": 20,
185+
"metadata": {},
186+
"outputs": [],
187+
"source": [
188+
"import cv2\n",
189+
"import numpy as np\n",
190+
"\n",
191+
"img = np.zeros((480,640,3), dtype=np.uint8)\n",
192+
"\n",
193+
"COLOR = (0,255,255) # BGR\n",
194+
"THICKNESS = 3 \n",
195+
"\n",
196+
"cv2.line(img,(50,100),(400,50),COLOR,3,cv2.LINE_4)\n",
197+
"cv2.line(img,(50,200),(400,150),COLOR,3,cv2.LINE_8)\n",
198+
"cv2.line(img,(50,300),(400,250),COLOR,3,cv2.LINE_AA)\n",
199+
"\n",
200+
"cv2.circle(img,(200,200),50,(255,255,0),3,cv2.LINE_AA)\n",
201+
"\n",
202+
"cv2.imshow('img',img)\n",
203+
"cv2.waitKey(0)\n",
204+
"cv2.destroyAllWindows()"
205+
]
206+
},
207+
{
208+
"cell_type": "markdown",
209+
"metadata": {},
210+
"source": [
211+
"## 원 그리기\n"
212+
]
213+
},
214+
{
215+
"cell_type": "code",
216+
"execution_count": 21,
217+
"metadata": {},
218+
"outputs": [],
219+
"source": [
220+
"import cv2\n",
221+
"import numpy as np\n",
222+
"\n",
223+
"img = np.zeros((480,640,3), dtype=np.uint8)\n",
224+
"\n",
225+
"COLOR = (255,255,0) # BGR\n",
226+
"\n",
227+
"cv2.circle(img,(200,200),50,(255,255,0),3,cv2.LINE_AA)\n",
228+
"\n",
229+
"cv2.imshow('img',img)\n",
230+
"cv2.waitKey(0)\n",
231+
"cv2.destroyAllWindows()"
232+
]
233+
},
234+
{
235+
"cell_type": "markdown",
236+
"metadata": {},
237+
"source": [
238+
"## 텍스트 쓰기"
239+
]
240+
},
241+
{
242+
"cell_type": "code",
243+
"execution_count": 23,
244+
"metadata": {},
245+
"outputs": [],
246+
"source": [
247+
"import cv2\n",
248+
"import numpy as np\n",
249+
"\n",
250+
"img = np.zeros((480,640,3), dtype=np.uint8)\n",
251+
"\n",
252+
"\n",
253+
"cv2.putText(img,'Hello ',(20,50),cv2.FONT_HERSHEY_PLAIN, 1, (255,0,255),1)\n",
254+
"\n",
255+
"\n",
256+
"cv2.imshow('img',img)\n",
257+
"cv2.waitKey(0)\n",
258+
"cv2.destroyAllWindows()"
259+
]
260+
},
261+
{
262+
"cell_type": "markdown",
263+
"metadata": {},
264+
"source": [
265+
"## 한글 텍스트 쓰기 (PIL 사용)"
266+
]
267+
},
268+
{
269+
"cell_type": "code",
270+
"execution_count": 27,
271+
"metadata": {},
272+
"outputs": [],
273+
"source": [
274+
"import cv2\n",
275+
"import numpy as np\n",
276+
"from PIL import ImageFont, ImageDraw, Image\n",
277+
"\n",
278+
"def myPutText(src, text, pos, font_size, font_color):\n",
279+
" img_pil = Image.fromarray(src)\n",
280+
" draw = ImageDraw.Draw(img_pil)\n",
281+
" font = ImageFont.truetype('fonts/gulim.ttc', font_size)\n",
282+
" draw.text(pos,text,font=font, fill=font_color)\n",
283+
" return np.array(img_pil)\n",
284+
" \n",
285+
" \n",
286+
"img = np.zeros((480,640,3), dtype=np.uint8)\n",
287+
"img = myPutText(img,'안녕하세요 ',(20,50),30,(255,255,0))\n",
288+
"\n",
289+
"cv2.imshow('img',img)\n",
290+
"cv2.waitKey(0)\n",
291+
"cv2.destroyAllWindows()"
292+
]
293+
}
294+
],
295+
"metadata": {
296+
"interpreter": {
297+
"hash": "b89b5cfaba6639976dc87ff2fec6d58faec662063367e2c229c520fe71072417"
298+
},
299+
"kernelspec": {
300+
"display_name": "Python 3.10.1 64-bit",
301+
"language": "python",
302+
"name": "python3"
303+
},
304+
"language_info": {
305+
"codemirror_mode": {
306+
"name": "ipython",
307+
"version": 3
308+
},
309+
"file_extension": ".py",
310+
"mimetype": "text/x-python",
311+
"name": "python",
312+
"nbconvert_exporter": "python",
313+
"pygments_lexer": "ipython3",
314+
"version": "3.10.1"
315+
},
316+
"orig_nbformat": 4
317+
},
318+
"nbformat": 4,
319+
"nbformat_minor": 2
320+
}

0 commit comments

Comments
 (0)