Showing
14 changed files
with
43 additions
and
33 deletions
No preview for this file type
No preview for this file type
No preview for this file type
codes/Project/output/3.motorbike.png
deleted
100644 → 0

591 KB
codes/Project/output/4.bicycle.png
deleted
100644 → 0

614 KB
No preview for this file type
codes/Project/output1/person.png
0 → 100644

812 KB
codes/Project/output2/.DS_Store
0 → 100644
No preview for this file type
codes/Project/output2/bicycle.png
0 → 100644

585 KB
codes/Project/output2/motorbike.png
0 → 100644

599 KB
codes/Project/output2/person.png
0 → 100644

649 KB
... | @@ -28,15 +28,15 @@ def get_classes(file): | ... | @@ -28,15 +28,15 @@ def get_classes(file): |
28 | 28 | ||
29 | 29 | ||
30 | if __name__ == '__main__': | 30 | if __name__ == '__main__': |
31 | -# 파일 열기 | 31 | + # 파일 열기 |
32 | camera = cv2.VideoCapture("input/example.mp4") | 32 | camera = cv2.VideoCapture("input/example.mp4") |
33 | 33 | ||
34 | -# Yolo 학습 | 34 | + # Yolo 학습 |
35 | yolo = YOLO(0.6, 0.5) | 35 | yolo = YOLO(0.6, 0.5) |
36 | file = 'data/coco_classes.txt' | 36 | file = 'data/coco_classes.txt' |
37 | all_classes = get_classes(file) | 37 | all_classes = get_classes(file) |
38 | 38 | ||
39 | -# 1 카운트 할 때마다 frame 얻어서 파일로 저장 | 39 | + # 1 카운트 할 때마다 frame 얻어서 파일로 저장 |
40 | success,image = camera.read() | 40 | success,image = camera.read() |
41 | count = 0 | 41 | count = 0 |
42 | while success: | 42 | while success: |
... | @@ -44,7 +44,7 @@ if __name__ == '__main__': | ... | @@ -44,7 +44,7 @@ if __name__ == '__main__': |
44 | success,image = camera.read() | 44 | success,image = camera.read() |
45 | count += 1 | 45 | count += 1 |
46 | 46 | ||
47 | -# 각 프레임 별로 Image Detection 후 프레임 번호, 객체 이름(name)과 객체의 크기(size), 객체가 얼마나 가운데 있는지(coordinatevalue) 저장 | 47 | + # 각 프레임 별로 Image Detection 후 프레임 번호, 객체 이름(name)과 객체의 크기(size), 객체가 얼마나 가운데 있는지(coordinatevalue) 저장 |
48 | detectionInfo = [] | 48 | detectionInfo = [] |
49 | for i in range(count): | 49 | for i in range(count): |
50 | #filename = "mid/frame"+str(i)+"." | 50 | #filename = "mid/frame"+str(i)+"." |
... | @@ -62,56 +62,66 @@ if __name__ == '__main__': | ... | @@ -62,56 +62,66 @@ if __name__ == '__main__': |
62 | a = image.shape[1]/2 - object.width | 62 | a = image.shape[1]/2 - object.width |
63 | b = image.shape[0]/2 - object.height | 63 | b = image.shape[0]/2 - object.height |
64 | coordinatevalue = math.sqrt((a*a)+(b*b)) | 64 | coordinatevalue = math.sqrt((a*a)+(b*b)) |
65 | + # 객체 정보 및 계산 값 저장 | ||
65 | detectionInfo.append([i, name, size, coordinatevalue]) | 66 | detectionInfo.append([i, name, size, coordinatevalue]) |
66 | 67 | ||
67 | for i in range(len(detectionInfo)): | 68 | for i in range(len(detectionInfo)): |
68 | print(detectionInfo[i]) | 69 | print(detectionInfo[i]) |
69 | -# name 별로 크기가 가장 크거나 물체가 프레임의 가운데 있는 프레임 번호 목록 얻어오기 | ||
70 | 70 | ||
71 | - indexlist = [] | ||
72 | # 검출된 물체 리스트(중복 없이) | 71 | # 검출된 물체 리스트(중복 없이) |
73 | - namelist = set() | 72 | + namelist = {} |
74 | for i in range(len(detectionInfo)): | 73 | for i in range(len(detectionInfo)): |
75 | - namelist.add(detectionInfo[i][1]) | 74 | + if not detectionInfo[i][1] in namelist: |
76 | - namelist = list(namelist) | 75 | + namelist[detectionInfo[i][1]] = [] |
77 | - | ||
78 | - print("namelist", namelist) | ||
79 | 76 | ||
80 | # 계획1 : 뒤 두 알고리즘 일정 비율로 합치기 | 77 | # 계획1 : 뒤 두 알고리즘 일정 비율로 합치기 |
81 | - # 검출된 물체 중 가장 크기가 큰 것을 불러옴 | 78 | + # 크기 |
82 | - for i in range(len(namelist)): | 79 | + for objectName in namelist.keys(): |
83 | maxindex = 0 | 80 | maxindex = 0 |
84 | maxvalue = 0 | 81 | maxvalue = 0 |
85 | for j in range(len(detectionInfo)): | 82 | for j in range(len(detectionInfo)): |
86 | - if detectionInfo[j][1] == namelist[i]: # 물체 리스트 중에서 | 83 | + if detectionInfo[j][1] == objectName: |
87 | - if detectionInfo[j][2] > maxvalue: # 가장 큰 값을 갱신한다면 | 84 | + if detectionInfo[j][2] > maxvalue: |
88 | maxvalue = detectionInfo[j][2] | 85 | maxvalue = detectionInfo[j][2] |
89 | maxindex = detectionInfo[j][0] | 86 | maxindex = detectionInfo[j][0] |
90 | - indexlist.append(maxindex) | 87 | + namelist[objectName].append(maxindex) |
91 | - | 88 | + |
92 | - | 89 | + for objectname, framelist in namelist.items(): |
93 | - # 검출된 물체 중 가장 가운데 있는 것을 불러 | 90 | + image = cv2.imread("mid/frame%d.png" % framelist[0]) |
94 | - for i in range(len(namelist)): | 91 | + output1 = cv2.GaussianBlur(image, (5,5), 0) |
92 | + cv2.imwrite("output1/%s.png"% (objectname), output1) | ||
93 | + | ||
94 | + # 가운데 위치 | ||
95 | + for objectName in namelist.keys(): | ||
96 | + namelist[objectName] = [] | ||
97 | + | ||
98 | + for objectName in namelist.keys(): | ||
95 | minindex = 0 | 99 | minindex = 0 |
96 | minvalue = 999999 | 100 | minvalue = 999999 |
97 | for j in range(len(detectionInfo)): | 101 | for j in range(len(detectionInfo)): |
98 | - if detectionInfo[j][1] == namelist[i]: # 물체 리스트 중에서 | 102 | + if detectionInfo[j][1] == objectName: |
99 | - if detectionInfo[j][3] < minvalue: # 가장 큰 값을 갱신한다면 | 103 | + if detectionInfo[j][3] < minvalue: |
100 | minvalue = detectionInfo[j][3] | 104 | minvalue = detectionInfo[j][3] |
101 | minindex = detectionInfo[j][0] | 105 | minindex = detectionInfo[j][0] |
102 | - indexlist.append(minindex) | 106 | + namelist[objectName].append(minindex) |
107 | + | ||
108 | + for objectname, framelist in namelist.items(): | ||
109 | + image = cv2.imread("mid/frame%d.png" % framelist[0]) | ||
110 | + output2 = cv2.GaussianBlur(image, (5,5), 0) | ||
111 | + cv2.imwrite("output2/%s.png"% (objectname), output2) | ||
112 | + | ||
113 | + | ||
114 | +# 계획2 : 프레임별로 나온 객체 겹치는 부분 제외하고 넓이 구해 큰거 Indexlist에 넣기 | ||
115 | + | ||
116 | +# 계획3 : 객체가 특정 위치에 있는 프레임 뽑기 | ||
117 | + | ||
118 | + | ||
119 | + | ||
120 | + | ||
103 | 121 | ||
104 | - print(indexlist) | ||
105 | 122 | ||
106 | - # 계획2 : 프레임별로 나온 객체 겹치는 부분 제외하고 넓이 구해 큰거 Indexlist에 넣기 | ||
107 | 123 | ||
108 | - # 계획3 : 객체가 특정 위치에 있는 프레임 뽑기 | ||
109 | 124 | ||
110 | -#얻어온 프레임 목록 결과값으로 저장, 선명도 높이는 작업 수행 | 125 | +#kernel_sharpen_1 = np.array([[-1,-1,-1],[-1,9,-1],[-1,-1,-1]]) |
111 | - for i in range(len(indexlist)): | 126 | +#output2 = cv2.filter2D(output1,-1,kernel_sharpen_1) |
112 | - image = cv2.imread("mid/frame%d.png" % indexlist[i]) | ||
113 | - output1 = cv2.GaussianBlur(image,(5,5),0) | ||
114 | - #kernel_sharpen_1 = np.array([[-1,-1,-1],[-1,9,-1],[-1,-1,-1]]) | ||
115 | - #output2 = cv2.filter2D(output1,-1,kernel_sharpen_1) | ||
116 | 127 | ||
117 | - cv2.imwrite("output/%d.%s.png"% (i+1,namelist[i]), output1); | ... | ... |
-
Please register or login to post a comment