Notice
Recent Posts
Recent Comments
Link
«   2024/05   »
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
Archives
Today
Total
관리 메뉴

0과 1 사이

PYQT를 이용해 UI와 YOLO 연결 시키기 본문

(0, 1)/손마리

PYQT를 이용해 UI와 YOLO 연결 시키기

고후 2022. 1. 27. 18:22

pyqt를 잘 몰라서.. 의외로 이 파트가 어려웠다.
ui는 간단하게 구현하기 위해 pyqt를 이용하였고 환자의 수어를 번역하여 출력하는 yolo 창만 남겨두고 최대한 단순화했다.
또한 내 노트북 상으로는 실행은 잘됐는데, 팀원 노트북에서는 실행도 되지 않았다.
다른 것들은 제외하고 pyqt로 darknet을 이용해 번역한 이미지를 가져오는 방법에 대해 설명해보겠다.


아래는 ui를 실행시키는 sonmari.py 코드이다. 핵심은 3중 쓰레드 마지막 줄에 보면 sonmari_video.drawing을 실행시키도록 되어있는데, self를 전달하여 해당 윈도우 객체를 전달해주는것이다.

width = darknet.network_width(network)
height = darknet.network_height(network)
#웹캠을 이용해 캡처
cap = cv2.VideoCapture(0)

#캡처 쓰레드
Thread(target=sv.video_capture, args=(cap, width, height, frame_queue, darknet_image_queue)).start()
#detect 쓰레드
Thread(target=sv.inference, args=(cap, args, network, class_names, darknet_image_queue, detections_queue, fps_queue)).start()
#출력 쓰레드
Thread(target=sv.drawing, args=(cap, self, args, width, height, class_colors, frame_queue, detections_queue, fps_queue)).start()


이에 따라 sonmari_video 안의 drawing 함수도 자연스레 변경시켰다. window 변수를 매개변수 안에 넣어줌으로써 sonmari window를 받아오도록 한 것이다.

def drawing(cap, window, args, width, height, class_colors, frame_queue, detections_queue, fps_queue):
#detect 결과 출력

random.seed(3)
label = "" #detect 결과(실시간으로 detect된 이미지)
word = "" #최종으로 출력할 단어
sentence=[] #출력할 문장

result = "" #현재 결과
before_result = "" #이전 결과
result_que = Queue(3) #result들을 저장하는 큐 생성. 현재 결과까지 최대 3개 저장


while cap.isOpened():

frame_resized = frame_queue.get()
detections = detections_queue.get()
fps = fps_queue.get()

if frame_resized is not None:


label, image = darknet.draw_boxes(detections, frame_resized, class_colors)
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
#한글을 이미지 위에 출력하기 위해 hand_image로 변환
더 자세한 코드는 깃허브에서 볼 수 있다.

Comments