강세희

[UPDATE] namelist를 dictionary 형태로 바꾸고 결과 값을 두 개의 파일로 분할

No preview for this file type
No preview for this file type
......@@ -28,15 +28,15 @@ def get_classes(file):
if __name__ == '__main__':
# 파일 열기
# 파일 열기
camera = cv2.VideoCapture("input/example.mp4")
# Yolo 학습
# Yolo 학습
yolo = YOLO(0.6, 0.5)
file = 'data/coco_classes.txt'
all_classes = get_classes(file)
# 1 카운트 할 때마다 frame 얻어서 파일로 저장
# 1 카운트 할 때마다 frame 얻어서 파일로 저장
success,image = camera.read()
count = 0
while success:
......@@ -44,7 +44,7 @@ if __name__ == '__main__':
success,image = camera.read()
count += 1
# 각 프레임 별로 Image Detection 후 프레임 번호, 객체 이름(name)과 객체의 크기(size), 객체가 얼마나 가운데 있는지(coordinatevalue) 저장
# 각 프레임 별로 Image Detection 후 프레임 번호, 객체 이름(name)과 객체의 크기(size), 객체가 얼마나 가운데 있는지(coordinatevalue) 저장
detectionInfo = []
for i in range(count):
#filename = "mid/frame"+str(i)+"."
......@@ -62,56 +62,66 @@ if __name__ == '__main__':
a = image.shape[1]/2 - object.width
b = image.shape[0]/2 - object.height
coordinatevalue = math.sqrt((a*a)+(b*b))
# 객체 정보 및 계산 값 저장
detectionInfo.append([i, name, size, coordinatevalue])
for i in range(len(detectionInfo)):
print(detectionInfo[i])
# name 별로 크기가 가장 크거나 물체가 프레임의 가운데 있는 프레임 번호 목록 얻어오기
indexlist = []
# 검출된 물체 리스트(중복 없이)
namelist = set()
namelist = {}
for i in range(len(detectionInfo)):
namelist.add(detectionInfo[i][1])
namelist = list(namelist)
print("namelist", namelist)
if not detectionInfo[i][1] in namelist:
namelist[detectionInfo[i][1]] = []
# 계획1 : 뒤 두 알고리즘 일정 비율로 합치기
# 검출된 물체 중 가장 크기가 큰 것을 불러옴
for i in range(len(namelist)):
# 크기
for objectName in namelist.keys():
maxindex = 0
maxvalue = 0
for j in range(len(detectionInfo)):
if detectionInfo[j][1] == namelist[i]: # 물체 리스트 중에서
if detectionInfo[j][2] > maxvalue: # 가장 큰 값을 갱신한다면
if detectionInfo[j][1] == objectName:
if detectionInfo[j][2] > maxvalue:
maxvalue = detectionInfo[j][2]
maxindex = detectionInfo[j][0]
indexlist.append(maxindex)
# 검출된 물체 중 가장 가운데 있는 것을 불러
for i in range(len(namelist)):
namelist[objectName].append(maxindex)
for objectname, framelist in namelist.items():
image = cv2.imread("mid/frame%d.png" % framelist[0])
output1 = cv2.GaussianBlur(image, (5,5), 0)
cv2.imwrite("output1/%s.png"% (objectname), output1)
# 가운데 위치
for objectName in namelist.keys():
namelist[objectName] = []
for objectName in namelist.keys():
minindex = 0
minvalue = 999999
for j in range(len(detectionInfo)):
if detectionInfo[j][1] == namelist[i]: # 물체 리스트 중에서
if detectionInfo[j][3] < minvalue: # 가장 큰 값을 갱신한다면
if detectionInfo[j][1] == objectName:
if detectionInfo[j][3] < minvalue:
minvalue = detectionInfo[j][3]
minindex = detectionInfo[j][0]
indexlist.append(minindex)
namelist[objectName].append(minindex)
for objectname, framelist in namelist.items():
image = cv2.imread("mid/frame%d.png" % framelist[0])
output2 = cv2.GaussianBlur(image, (5,5), 0)
cv2.imwrite("output2/%s.png"% (objectname), output2)
# 계획2 : 프레임별로 나온 객체 겹치는 부분 제외하고 넓이 구해 큰거 Indexlist에 넣기
# 계획3 : 객체가 특정 위치에 있는 프레임 뽑기
print(indexlist)
# 계획2 : 프레임별로 나온 객체 겹치는 부분 제외하고 넓이 구해 큰거 Indexlist에 넣기
# 계획3 : 객체가 특정 위치에 있는 프레임 뽑기
#얻어온 프레임 목록 결과값으로 저장, 선명도 높이는 작업 수행
for i in range(len(indexlist)):
image = cv2.imread("mid/frame%d.png" % indexlist[i])
output1 = cv2.GaussianBlur(image,(5,5),0)
#kernel_sharpen_1 = np.array([[-1,-1,-1],[-1,9,-1],[-1,-1,-1]])
#output2 = cv2.filter2D(output1,-1,kernel_sharpen_1)
#kernel_sharpen_1 = np.array([[-1,-1,-1],[-1,9,-1],[-1,-1,-1]])
#output2 = cv2.filter2D(output1,-1,kernel_sharpen_1)
cv2.imwrite("output/%d.%s.png"% (i+1,namelist[i]), output1);
......