강세희

[UPDATE] 구현 결과

No preview for this file type
This file is too large to display.

726 KB | W: | H:

763 KB | W: | H:

  • 2-up
  • Swipe
  • Onion skin

812 KB | W: | H:

841 KB | W: | H:

  • 2-up
  • Swipe
  • Onion skin

777 KB | W: | H:

440 KB | W: | H:

  • 2-up
  • Swipe
  • Onion skin

804 KB | W: | H:

816 KB | W: | H:

  • 2-up
  • Swipe
  • Onion skin

489 KB | W: | H:

788 KB | W: | H:

  • 2-up
  • Swipe
  • Onion skin

591 KB | W: | H:

599 KB | W: | H:

  • 2-up
  • Swipe
  • Onion skin

1.07 MB | W: | H:

816 KB | W: | H:

  • 2-up
  • Swipe
  • Onion skin

804 KB | W: | H:

816 KB | W: | H:

  • 2-up
  • Swipe
  • Onion skin

415 KB | W: | H:

396 KB | W: | H:

  • 2-up
  • Swipe
  • Onion skin

617 KB | W: | H:

649 KB | W: | H:

  • 2-up
  • Swipe
  • Onion skin

804 KB | W: | H:

816 KB | W: | H:

  • 2-up
  • Swipe
  • Onion skin

637 KB | W: | H:

549 KB | W: | H:

  • 2-up
  • Swipe
  • Onion skin
import math
import time
import cv2
import numpy as np
from copy import deepcopy
......@@ -30,19 +31,27 @@ def get_classes(file):
if __name__ == '__main__':
# 파일 열기
camera = cv2.VideoCapture("input/example.mp4")
if camera.isOpened() == False:
print("Can't open Video.")
# Yolo 학습
yolo = YOLO(0.6, 0.5)
file = 'data/coco_classes.txt'
all_classes = get_classes(file)
# 1 카운트 할 때마다 frame 얻어서 파일로 저장
success,image = camera.read()
# 10 카운트 할 때마다 frame 얻어서 파일로 저장
success, image = camera.read()
count = 0
frameCount = 0
start_time = time.time()
while success:
cv2.imwrite("mid/frame%d.png" % count, image) # save frame as JPEG file
frameCount += 1
if frameCount % 3 == 0:
cv2.imwrite("mid/frame%d.png" % count, image) # save frame as JPEG file
count += 1
success, image = camera.read()
count += 1
camera.release()
# 각 프레임 별로 Image Detection 후 프레임 번호, 객체 이름(name)과 객체의 크기(size), 객체가 얼마나 가운데 있는지(coordinatevalue) 저장
detectionInfo = []
......@@ -50,7 +59,6 @@ if __name__ == '__main__':
#filename = "mid/frame"+str(i)+"."
image = cv2.imread("mid/frame%d.png" % i)
pimage = process_image(image)
boxes, classes, scores = yolo.predict(pimage, image.shape)
for box, score, cl in zip(boxes, scores, classes):
x, y, w, h = box
......@@ -61,7 +69,6 @@ if __name__ == '__main__':
continue
if x <= 0 or x+w >= image.shape[1] or y <= 0 or y+h >= image.shape[0]: # 검출된 객체가 프레임 밖으로 나간 경우
continue
# 얼마나 가운데인지 확인하는 알고리즘
object = Point2D(width= x + w/2, height= y + h/2)
a = image.shape[1]/2 - object.width
......@@ -174,7 +181,8 @@ if __name__ == '__main__':
# 두 객체가 겹쳤는지 좌표 비교를 통해 확인, 겹쳤다면 겹친 부분의 좌표 값 o_xxx 에 저장
isOverlapped = False
if a_top < b_top < a_bottom or b_top < a_top < b_bottom or a_left < b_left < a_right or b_left < a_left < b_right:
if a_top < b_top < a_bottom or b_top < a_top < b_bottom \
or a_left < b_left < a_right or b_left < a_left < b_right:
isOverlapped = True
o_top = max(a_top, b_top)
o_bottom = min(a_bottom, b_bottom)
......@@ -187,11 +195,14 @@ if __name__ == '__main__':
if isOverlapped == True:
a_object = Point2D(width= (a_top + a_bottom)//2, height=(a_left + a_right)//2)
b_object = Point2D(width= (b_top + b_bottom)//2, height=(b_left + b_right)//2)
o_object = Point2D(width=(a_object.width+b_object.width)//2 , height = (a_object.height + b_object.height)//2)
o_object = Point2D(width=(a_object.width+b_object.width)//2 , \
height = (a_object.height + b_object.height)//2)
toTheOrigin_w = image.shape[1] / 2 - o_object.width
toTheOrigin_h = image.shape[0] / 2 - o_object.height
coordiValue_object = int(math.sqrt((toTheOrigin_w ** 2) + (toTheOrigin_h ** 2)))
bestList[key] = [value[0][0] + ", "+ value[1][0], value[0][1]+value[1][1]-o_size, coordiValue_object, min(a_top, b_top), min(a_left, b_left), max(a_right, b_right), max(a_bottom, b_bottom)]
bestList[key] = [value[0][0] + ", "+ value[1][0], value[0][1]+value[1][1]-o_size, \
coordiValue_object, min(a_top, b_top), min(a_left, b_left), \
max(a_right, b_right), max(a_bottom, b_bottom)]
else:
# 겹치지 않았다면 목록에서 삭제
deleteList.append(key)
......@@ -250,7 +261,8 @@ if __name__ == '__main__':
ratio = int((image.shape[1]+padNum)/image.shape[1])
output = cv2.resize(output, dsize=(width, height), interpolation=cv2.INTER_LINEAR)
# 물체가 프레임의 중앙에 있을 경우
elif image.shape[1]//2 - image.shape[1]//20 < (crop_left + crop_right)// 2 <= image.shape[1]//2 + image.shape[1]//20:
elif image.shape[1]//2 - image.shape[1]//20 < (crop_left + crop_right)// 2 \
<= image.shape[1]//2 + image.shape[1]//20:
crop_left = (crop_left + crop_right)//2 - width//2
crop_right = (crop_left + crop_right)//2 + width//2
output = image[crop_top:crop_bottom, crop_left:crop_right].copy()
......