Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 | 31 |
Tags
- 2003 에러
- 이베이 매각
- 리멤버나우 요약
- 스무고개 Metric
- but how?
- 리멤버나우
- 백준 2193
- git-lfs
- 110 옮기기
- 프로그래머스 여행경로
- 코딩테스트
- 경제 요약
- cs231
- aws rds
- 장영준
- 알고리즘
- 2003 error
- multi-task learning
- 오픈소스
- pytorch-tutorial
- Convolutional Neural Networks
- flask
- git password
- 프로그래머스
- C++
- 미국 이란 전쟁
- 뤼이드
- flaks
- 딥러닝
- 웹 독학
Archives
- Today
- Total
Nam's
[신발검색엔진][Pre] 신발 Image Detection with OpenCV, YOLO 본문
신발 검색 엔진의 이미지 전처리 과정을 위해서 신발을 찾는 모델이 필요하다.
Object Detection을 위해서 OpenCV, YOLO를 설치하고 테스트를 진행했다.
과일, 사람 같이 기본적인 물체는 잘 탐지되는 것 같다.
그런데 예상치 못한 문제가 생겼다. 신발을 못 찾는다..
YOLO에서 학습에 사용하는 COCO dataset과 ImageNet dataset에는 신발 class가 없다. (ImageNet에 러닝화는 있는데 신발은 없다..)
YOLO를 customize 해야 될 것 같다.
[Code]
github: https://github.com/devnjw/ShoeSearch/tree/master/yolo
참고 자료: pysource.com/2019/06/27/yolo-object-detection-using-opencv-with-python/
import cv2
import numpy as np
# Load Yolo
net = cv2.dnn.readNet("yolov4.weights", "yolov4.cfg")
# 클래스 리스트
classes = ["person", "bicycle", "car", "motorcycle",
"airplane", "bus", "train", "truck", "boat", "traffic light", "fire hydrant",
"stop sign", "parking meter", "bench", "bird", "cat", "dog", "horse",
"sheep", "cow", "elephant", "bear", "zebra", "giraffe", "backpack",
"umbrella", "handbag", "tie", "suitcase", "frisbee", "skis",
"snowboard", "sports ball", "kite", "baseball bat", "baseball glove", "skateboard",
"surfboard", "tennis racket", "bottle", "wine glass", "cup", "fork", "knife",
"spoon", "bowl", "banana", "apple", "sandwich", "orange", "broccoli", "carrot", "hot dog",
"pizza", "donut", "cake", "chair", "couch", "potted plant", "bed", "dining table",
"toilet", "tv", "laptop", "mouse", "remote", "keyboard",
"cell phone", "microwave", "oven", "toaster", "sink", "refrigerator",
"book", "clock", "vase", "scissors", "teddy bear", "hair drier", "toothbrush"]
layer_names = net.getLayerNames()
output_layers = [layer_names[i[0] - 1] for i in net.getUnconnectedOutLayers()]
colors = np.random.uniform(0, 255, size=(len(classes), 3))
# Loading image
img = cv2.imread("foods.png")
img = cv2.resize(img, None, fx=0.4, fy=0.4)
height, width, channels = img.shape
# Detecting objects
blob = cv2.dnn.blobFromImage(img, 0.00392, (416, 416), (0, 0, 0), True, crop=False)
net.setInput(blob)
outs = net.forward(output_layers)
# Showing informations on the screen
class_ids = []
confidences = []
boxes = []
for out in outs:
for detection in out:
scores = detection[5:]
class_id = np.argmax(scores)
confidence = scores[class_id]
if confidence > 0.5:
# Object detected
center_x = int(detection[0] * width)
center_y = int(detection[1] * height)
w = int(detection[2] * width)
h = int(detection[3] * height)
# Rectangle coordinates
x = int(center_x - w / 2)
y = int(center_y - h / 2)
boxes.append([x, y, w, h])
confidences.append(float(confidence))
class_ids.append(class_id)
indexes = cv2.dnn.NMSBoxes(boxes, confidences, 0.5, 0.4)
font = cv2.FONT_HERSHEY_PLAIN
for i in range(len(boxes)):
if i in indexes:
x, y, w, h = boxes[i]
label = str(classes[class_ids[i]])
color = colors[i]
cv2.rectangle(img, (x, y), (x + w, y + h), color, 2)
cv2.putText(img, label, (x, y + 30), font, 3, color, 3)
cv2.imshow("Image", img)
cv2.waitKey(0)
cv2.destroyAllWindows()
'개발 > Side Project' 카테고리의 다른 글
[신발검색엔진] 02 개발 1주차 - 웹 구현 (0) | 2021.06.26 |
---|---|
[신발검색엔진] 01 프로젝트 계획 & 시작 (0) | 2021.06.22 |
[신발검색엔진][2차 회의] 0508(토) (0) | 2021.05.08 |
[신발검색엔진][Pre] 신발 이미지 크롤링 (0) | 2021.04.28 |
[신발검색엔진][Pre] 사이드 프로젝트 시작 (0) | 2021.04.28 |
Comments