Skip to content

Commit 1d6a8b6

Browse files
committed
init
0 parents  commit 1d6a8b6

File tree

455 files changed

+584212
-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.

455 files changed

+584212
-0
lines changed

.DS_Store

14 KB
Binary file not shown.

2021 Vision system midterm.pdf

576 KB
Binary file not shown.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Created on Fri May 28 16:05:58 2021
4+
5+
@author: 이병화
6+
"""
7+
8+
import cv2
9+
10+
face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades +"haarcascade_frontalface_default.xml")
11+
12+
img = cv2.imread('Lena.jpg')
13+
14+
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
15+
16+
faces = face_cascade.detectMultiScale(gray, 1.1,4)
17+
18+
for (x,y,w,h) in faces:
19+
cv2.rectangle(img, (x,y),(x+w, y+h), (255,0,0), 2)
20+
21+
cv2.imshow('img',img)
22+
cv2.waitKey()
23+
cv2.destroyAllWindows()

Face detection 예제/Lena.jpg

26.8 KB

Face detection 예제/haarcascade_frontalface_default.xml

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

Face detection 예제/haarcascade_fullbody.xml

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

Light and color/cube.png

8.19 KB

Light and color/example.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Created on Sat Jun 12 13:25:00 2021
4+
5+
@author: 이병화
6+
"""
7+
8+
import cv2
9+
import matplotlib.pyplot as plt
10+
11+
imgRGB = cv2.imread('cube.png')
12+
cv2.imshow('cube',imgRGB)
13+
14+
b,g,r=cv2.split(imgRGB)
15+
16+
cv2.imshow('b',b)
17+
cv2.imshow('g',g)
18+
cv2.imshow('r',r)
19+
20+
imgHSV = cv2.cvtColor(imgRGB, cv2.COLOR_BGR2HSV)
21+
22+
h,s,v = cv2.split(imgHSV)
23+
24+
cv2.imshow('h',h)
25+
cv2.imshow('s',s)
26+
cv2.imshow('v',v)
27+
28+
cv2.waitKey(0)
29+
cv2.destroyAllWindows()

README.md

Lines changed: 1 addition & 0 deletions

Term Project/.DS_Store

12 KB
Binary file not shown.
204 KB
382 KB
204 KB
382 KB
204 KB
381 KB
204 KB
382 KB
195 KB
395 KB
201 KB
392 KB
204 KB
399 KB
202 KB
398 KB
202 KB
376 KB
202 KB
388 KB
202 KB
391 KB
204 KB
389 KB
201 KB
392 KB
199 KB
397 KB
202 KB
398 KB
201 KB
398 KB
200 KB
404 KB
200 KB
405 KB
200 KB
406 KB
200 KB
403 KB
199 KB
393 KB
198 KB
405 KB
200 KB
406 KB
200 KB
406 KB
199 KB
405 KB
200 KB
385 KB
198 KB
385 KB
197 KB
382 KB
198 KB
379 KB
203 KB
370 KB
200 KB
369 KB
200 KB
367 KB
199 KB
362 KB
195 KB
366 KB
199 KB
366 KB
199 KB
364 KB
199 KB
363 KB
196 KB
350 KB
195 KB
366 KB
196 KB
367 KB
197 KB
367 KB
198 KB
367 KB
195 KB
337 KB
195 KB
357 KB
190 KB
356 KB
186 KB
384 KB
184 KB
394 KB
180 KB
385 KB
181 KB
390 KB
170 KB
388 KB
166 KB
389 KB
154 KB
393 KB
145 KB
401 KB
141 KB
399 KB
128 KB
399 KB
122 KB
406 KB
114 KB
398 KB
111 KB
400 KB
112 KB
412 KB
110 KB
411 KB
111 KB
401 KB
129 KB
404 KB
157 KB
400 KB
155 KB
402 KB
182 KB
379 KB
191 KB
387 KB
196 KB
401 KB
218 KB
404 KB
229 KB
496 KB
233 KB
545 KB
232 KB
363 KB
236 KB
361 KB
232 KB
376 KB
234 KB
383 KB
234 KB
389 KB
235 KB
393 KB
234 KB
392 KB
234 KB
394 KB
234 KB
394 KB
234 KB
394 KB

Term Project/JJ.gif

609 KB

Term Project/Term Project.hwp

3.31 MB
Binary file not shown.

Term Project/Term Project.pdf

742 KB
Binary file not shown.

Term Project/Term Project.py

Lines changed: 221 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,221 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Created on Wed Jun 9 14:22:21 2021
4+
5+
@author: 이병화
6+
"""
7+
8+
import numpy as np
9+
import cv2
10+
import glob
11+
import sys
12+
import os
13+
import cv2.aruco
14+
15+
16+
'''
17+
criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 30, 0.001)
18+
19+
objp = np.zeros((6*7,3), np.float32)
20+
objp[:,:2] = np.mgrid[0:7,0:6].T.reshape(-1,2)
21+
22+
objpoints = []
23+
imgpoints = []
24+
25+
images = glob.glob('./chess/*.jpg')
26+
#images = glob.glob('./calibration/*.png')
27+
28+
29+
for fname in images:
30+
img = cv2.imread(fname)
31+
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
32+
ret, corners = cv2.findChessboardCorners(gray, (7,6), None)
33+
34+
if ret == True:
35+
objpoints.append(objp)
36+
corners2 = cv2.cornerSubPix(gray,corners, (11,11), (-1,-1), criteria)
37+
imgpoints.append(corners)
38+
39+
img = cv2.drawChessboardCorners(img, (7,6), corners2, ret)
40+
cv2.imshow('img', img)
41+
cv2.waitKey(500)
42+
43+
cv2.destroyAllWindows()
44+
45+
ret, mtx, dist, rvecs, tvecs = cv2.calibrateCamera(objpoints, imgpoints, gray.shape[::-1], None, None)
46+
47+
img = cv2.imread('./chess/KakaoTalk_20210512_224651717_15.jpg')
48+
#img = cv2.imread('./calibration/00010.png')
49+
h, w = img.shape[:2]
50+
newcameramtx, roi = cv2.getOptimalNewCameraMatrix(mtx, dist, (w,h), 1, (w,h))
51+
52+
dst = cv2.undistort(img, mtx, dist, None, newcameramtx)
53+
54+
x, y, w, h = roi
55+
dst = dst[y:y+h, x:x+w]
56+
cv2.imwrite('calibresult.png', dst)
57+
58+
tot_error = 0
59+
for i in range(len(objpoints)):
60+
imgpoints2, _ = cv2.projectPoints(objpoints[i], rvecs[i], tvecs[i], mtx, dist)
61+
error = cv2.norm(imgpoints[i],imgpoints2, cv2.NORM_L2)/len(imgpoints2)
62+
tot_error += error
63+
print("total error: ", tot_error/len(objpoints))
64+
'''
65+
66+
# linedetection and following
67+
68+
# edge검출 ROI처리
69+
# 카메라 사용
70+
#cap1 = cv2.VideoCapture(0)
71+
72+
#if not cap1.isOpened():
73+
#print('Camera open failed!')
74+
#sys.exit()
75+
76+
#mtx = np.load('mtx.npy')
77+
#dist = np.load('dist.npy')
78+
79+
#img = cv2.imread('./Inteld435i/00006_image.png')
80+
#h, w = img.shape[:2]
81+
#newcameramtx, roi = cv2.getOptimalNewCameraMatrix(mtx, dist, (w,h), 1, (w,h))
82+
83+
#dst = cv2.undistort(img, mtx, dist, None, newcameramtx)
84+
85+
#x, y, w, h = roi
86+
#dst = dst[y:y+h, x:x+w]
87+
#cap1 = cv2.imwrite('calibresult.png', dst)
88+
89+
90+
cap1 = cv2.imread('./Inteld435i/00070_image.png')
91+
#cap1 = cv2.imread('./image/image_018.jpg')
92+
93+
caphsv = cv2.cvtColor(cap1, cv2.COLOR_BGR2HSV)
94+
h,s,v = cv2.split(caphsv)
95+
96+
edges = cv2.Canny(s,100,200)
97+
98+
roi_h = edges.shape[0]
99+
roi_w = edges.shape[1]
100+
101+
region = np.array([
102+
[[60, roi_h], [285, 240],[330, 230], [roi_w, 430]]
103+
], dtype = np.int32)
104+
105+
mask = np.zeros_like(s)
106+
cv2.fillPoly(mask, region, 255)
107+
region = np.array([
108+
[[140, roi_h], [290, 230],[350, 230], [600, 480]]
109+
], dtype = np.int32)
110+
cv2.fillPoly(mask,region, 0)
111+
112+
roimg = cv2.bitwise_and(edges, mask)
113+
114+
cv2.imshow('Canny',edges)
115+
cv2.imshow('ROI',roimg)
116+
117+
#hought transform 차선검출
118+
lines = cv2.HoughLines(roimg, 1, np.pi/180, 180)
119+
#lines = cv2.HoughLinesP(roimg, 1,np.pi/180,50,100,10)
120+
cap2 = cap1
121+
122+
if lines is not None:
123+
for line in lines :
124+
#x1,y1,x2,y2 = line[0]
125+
r, theta = line[0]
126+
tx, ty = np.cos(theta), np.sin(theta)
127+
x0, y0 = tx*r, ty*r
128+
x1, y1 = int(x0 + 1000*(-ty)), int(y0 + 1000 * tx)
129+
x2, y2 = int(x0 - 1000*(-ty)), int(y0 - 1000 * tx)
130+
print(theta*(180/3.14))
131+
cap2 = cv2.line(cap2, (x1,y1), (x2,y2), (0,0,255), 1)
132+
133+
134+
#cv2.circle(cap1,(310,210),5,(0,0,255),-1)
135+
cv2.imshow('roimg',cap2)
136+
137+
138+
#object detection and localization
139+
140+
#hog = cv2.HOGDescriptor((48,96),(16,16),(8,8),(8,8),9)
141+
142+
143+
#hog=cv2.HOGDescriptor()
144+
#hog.setSVMDetector(cv2.HOGDescriptor_getDefaultPeopleDetector())
145+
146+
#detected, _ = hog.detectMultiScale(cap1)
147+
148+
#for (x,y,w,h) in detected:
149+
# cv2.rectangle(cap1, (x,y),(x+w,y+h), (50,200,50),3)
150+
#cv2.imshow('HOG', cap2)
151+
152+
153+
154+
net = cv2.dnn.readNet("yolov3.weights", "yolov3.cfg")
155+
classes = []
156+
with open("coco.names", "r") as f:
157+
classes = [line.strip() for line in f.readlines()]
158+
layer_names = net.getLayerNames()
159+
output_layers = [layer_names[i[0] - 1] for i in net.getUnconnectedOutLayers()]
160+
colors = np.random.uniform(0, 255, size=(len(classes), 3))
161+
162+
cap3 = cv2.resize(cap1, None, fx=0.4, fy=0.4)
163+
height, width, channels = cap3.shape
164+
165+
blob = cv2.dnn.blobFromImage(cap3, 0.00392, (416, 416), (0, 0, 0), True, crop=False)
166+
net.setInput(blob)
167+
outs = net.forward(output_layers)
168+
169+
class_ids = []
170+
confidences = []
171+
boxes = []
172+
for out in outs:
173+
for detection in out:
174+
scores = detection[5:]
175+
class_id = np.argmax(scores)
176+
confidence = scores[class_id]
177+
if confidence > 0.5:
178+
# Object detected
179+
center_x = int(detection[0] * width)
180+
center_y = int(detection[1] * height)
181+
w = int(detection[2] * width)
182+
h = int(detection[3] * height)
183+
# Rectangle coordinates
184+
x = int(center_x - w / 2)
185+
y = int(center_y - h / 2)
186+
boxes.append([x, y, w, h])
187+
confidences.append(float(confidence))
188+
class_ids.append(class_id)
189+
190+
indexes = cv2.dnn.NMSBoxes(boxes, confidences, 0.5, 0.4)
191+
192+
font = cv2.FONT_HERSHEY_PLAIN
193+
for i in range(len(boxes)):
194+
if i in indexes:
195+
x, y, w, h = boxes[i]
196+
label = str(classes[class_ids[i]])
197+
#color = colors[i]
198+
color = colors[10]
199+
x = round(x*2.5)
200+
y = round(y*2.5)
201+
w = round(w*2.5)
202+
h = round(h*2.5)
203+
cv2.rectangle(cap2, (x, y), ((x + w), (y + h)), color, 2)
204+
205+
206+
cv2.imshow("Image", cap2)
207+
# Markerdetection
208+
209+
#독자기능
210+
211+
pts1 = np.float32([[285, 240],[380, 260],[60, 480], [640, 450]])
212+
pts2 = np.float32([[160,0],[480,0],[160,480],[480,480]])
213+
214+
M = cv2.getPerspectiveTransform(pts1,pts2)
215+
216+
dst = cv2.warpPerspective(cap1,M,(640,480))
217+
218+
cv2.imshow("birdeye",dst)
219+
220+
cv2.waitKey()
221+
cv2.destroyAllWindows()
247 KB
Binary file not shown.

0 commit comments

Comments
 (0)