Showing
1 changed file
with
27 additions
and
20 deletions
1 | - | ||
2 | import time | 1 | import time |
3 | import math | 2 | import math |
4 | import cv2 | 3 | import cv2 |
... | @@ -55,49 +54,58 @@ if __name__ == '__main__': | ... | @@ -55,49 +54,58 @@ if __name__ == '__main__': |
55 | boxes, classes, scores = yolo.predict(pimage, image.shape) | 54 | boxes, classes, scores = yolo.predict(pimage, image.shape) |
56 | for box, score, cl in zip(boxes, scores, classes): | 55 | for box, score, cl in zip(boxes, scores, classes): |
57 | x, y, w, h = box | 56 | x, y, w, h = box |
58 | - name = all_classes[cl] | 57 | + name = all_classes[cl] |
59 | - size = w*h | 58 | + size = w*h |
60 | - # 얼마나 가운데인지 확인하는 알고리즘 | 59 | + |
61 | - | 60 | + # 얼마나 가운데인지 확인하는 알고리즘 |
62 | - object = Point2D(width= x + 0.5 * w , height= y - h * 0.5) | 61 | + object = Point2D(width= x + h/2, height= y + w/2) |
63 | - a = image.shape[1]/2 - object.width | 62 | + a = image.shape[1]/2 - object.width |
64 | - b = image.shape[0]/2 - object.height | 63 | + b = image.shape[0]/2 - object.height |
65 | - coordinatevalue = math.sqrt((a*a)+(b*b)) | 64 | + coordinatevalue = math.sqrt((a*a)+(b*b)) |
66 | - detectionInfo.append([i, name, size, coordinatevalue]) | 65 | + detectionInfo.append([i, name, size, coordinatevalue]) |
67 | - | 66 | + |
67 | + for i in range(len(detectionInfo)): | ||
68 | + print(detectionInfo[i]) | ||
68 | # name 별로 크기가 가장 크거나 물체가 프레임의 가운데 있는 프레임 번호 목록 얻어오기 | 69 | # name 별로 크기가 가장 크거나 물체가 프레임의 가운데 있는 프레임 번호 목록 얻어오기 |
69 | 70 | ||
70 | indexlist = [] | 71 | indexlist = [] |
71 | # 검출된 물체 리스트(중복 없이) | 72 | # 검출된 물체 리스트(중복 없이) |
72 | namelist = set() | 73 | namelist = set() |
73 | - for i in range(count): | 74 | + for i in range(len(detectionInfo)): |
74 | namelist.add(detectionInfo[i][1]) | 75 | namelist.add(detectionInfo[i][1]) |
75 | namelist = list(namelist) | 76 | namelist = list(namelist) |
76 | 77 | ||
78 | + print("namelist", namelist) | ||
77 | 79 | ||
80 | + # 계획1 : 뒤 두 알고리즘 일정 비율로 합치기 | ||
78 | # 검출된 물체 중 가장 크기가 큰 것을 불러옴 | 81 | # 검출된 물체 중 가장 크기가 큰 것을 불러옴 |
79 | for i in range(len(namelist)): | 82 | for i in range(len(namelist)): |
80 | maxindex = 0 | 83 | maxindex = 0 |
81 | maxvalue = 0 | 84 | maxvalue = 0 |
82 | - for j in range(count): | 85 | + for j in range(len(detectionInfo)): |
83 | if detectionInfo[j][1] == namelist[i]: # 물체 리스트 중에서 | 86 | if detectionInfo[j][1] == namelist[i]: # 물체 리스트 중에서 |
84 | if detectionInfo[j][2] > maxvalue: # 가장 큰 값을 갱신한다면 | 87 | if detectionInfo[j][2] > maxvalue: # 가장 큰 값을 갱신한다면 |
85 | maxvalue = detectionInfo[j][2] | 88 | maxvalue = detectionInfo[j][2] |
86 | - maxindex = j | 89 | + maxindex = detectionInfo[j][0] |
87 | indexlist.append(maxindex) | 90 | indexlist.append(maxindex) |
88 | 91 | ||
89 | 92 | ||
90 | - # 검출된 물체 중 가장 가운데 있는 것을 불러 | 93 | + # 검출된 물체 중 가장 가운데 있는 것을 불러 |
91 | for i in range(len(namelist)): | 94 | for i in range(len(namelist)): |
92 | minindex = 0 | 95 | minindex = 0 |
93 | - minvalue = 2000 | 96 | + minvalue = 999999 |
94 | - for j in range(count): | 97 | + for j in range(len(detectionInfo)): |
95 | if detectionInfo[j][1] == namelist[i]: # 물체 리스트 중에서 | 98 | if detectionInfo[j][1] == namelist[i]: # 물체 리스트 중에서 |
96 | if detectionInfo[j][3] < minvalue: # 가장 큰 값을 갱신한다면 | 99 | if detectionInfo[j][3] < minvalue: # 가장 큰 값을 갱신한다면 |
97 | minvalue = detectionInfo[j][3] | 100 | minvalue = detectionInfo[j][3] |
98 | - minindex = j | 101 | + minindex = detectionInfo[j][0] |
99 | indexlist.append(minindex) | 102 | indexlist.append(minindex) |
100 | 103 | ||
104 | + print(indexlist) | ||
105 | + | ||
106 | + # 계획2 : 프레임별로 나온 객체 겹치는 부분 제외하고 넓이 구해 큰거 Indexlist에 넣기 | ||
107 | + | ||
108 | + # 계획3 : 객체가 특정 위치에 있는 프레임 뽑기 | ||
101 | 109 | ||
102 | #얻어온 프레임 목록 결과값으로 저장, 선명도 높이는 작업 수행 | 110 | #얻어온 프레임 목록 결과값으로 저장, 선명도 높이는 작업 수행 |
103 | for i in range(len(indexlist)): | 111 | for i in range(len(indexlist)): |
... | @@ -106,5 +114,4 @@ if __name__ == '__main__': | ... | @@ -106,5 +114,4 @@ if __name__ == '__main__': |
106 | #kernel_sharpen_1 = np.array([[-1,-1,-1],[-1,9,-1],[-1,-1,-1]]) | 114 | #kernel_sharpen_1 = np.array([[-1,-1,-1],[-1,9,-1],[-1,-1,-1]]) |
107 | #output2 = cv2.filter2D(output1,-1,kernel_sharpen_1) | 115 | #output2 = cv2.filter2D(output1,-1,kernel_sharpen_1) |
108 | 116 | ||
109 | - | 117 | + cv2.imwrite("output/%d.%s.png"% (i+1,namelist[i]), output1); |
110 | - cv2.imwrite("output/%d.%s.png"% (i+1,detectionInfo[indexlist[i]][1]), output1); | ... | ... |
-
Please register or login to post a comment