|
1 | 1 | # USAGE |
2 | 2 | # python yolo.py --image images/baggage_claim.jpg --yolo yolo-coco |
3 | 3 | """ |
4 | | -usage: yolo_video.py [-h] -i INPUT -o OUTPUT -y YOLO [-c CONFIDENCE] |
| 4 | +A Yolo image processor with a GUI front-end |
| 5 | +The original code was command line driven. Now these parameters are collected via a GUI |
| 6 | +
|
| 7 | +old usage: yolo_video.py [-h] -i INPUT -o OUTPUT -y YOLO [-c CONFIDENCE] |
5 | 8 | [-t THRESHOLD] |
6 | 9 | """ |
7 | 10 |
|
8 | | - |
9 | 11 | # import the necessary packages |
10 | 12 | import numpy as np |
11 | 13 | import argparse |
12 | 14 | import time |
13 | 15 | import cv2 |
14 | 16 | import os |
15 | | -import PySimpleGUI as sg |
16 | | -from PIL import Image |
17 | | -import io |
| 17 | +import PySimpleGUIQt as sg |
18 | 18 |
|
19 | 19 | layout = [ |
20 | 20 | [sg.Text('YOLO')], |
21 | | - [sg.Text('Path to image'), sg.In(r'A:\Dropbox\Camera Uploads\2018-11-16 17.35.15.jpg',size=(40,1), key='image'), sg.FileBrowse()], |
22 | | - [sg.Text('Yolo base path'), sg.In(r'C:\Python\PycharmProjects\yolo-object-detection\yolo-coco',size=(40,1), key='yolo'), sg.FolderBrowse()], |
23 | | - [sg.Text('Confidence'), sg.Slider(range=(0,1),orientation='h', resolution=.1, default_value=.5, size=(15,15), key='confidence')], |
24 | | - [sg.Text('Threshold'), sg.Slider(range=(0,1), orientation='h', resolution=.1, default_value=.3, size=(15,15), key='threshold')], |
25 | | - [sg.OK(), sg.Cancel()] |
| 21 | + [sg.Text('Path to image'), sg.In(r'C:/Python/PycharmProjects/YoloObjectDetection/images/baggage_claim.jpg',size=(40,1), key='image'), sg.FileBrowse()], |
| 22 | + [sg.Text('Yolo base path'), sg.In(r'yolo-coco',size=(40,1), key='yolo'), sg.FolderBrowse()], |
| 23 | + [sg.Text('Confidence'), sg.Slider(range=(0,10),orientation='h', resolution=1, default_value=5, size=(15,15), key='confidence')], |
| 24 | + [sg.Text('Threshold'), sg.Slider(range=(0,10), orientation='h', resolution=1, default_value=3, size=(15,15), key='threshold')], |
| 25 | + [sg.OK(), sg.Cancel(), sg.Stretch()] |
26 | 26 | ] |
27 | 27 |
|
28 | 28 | win = sg.Window('YOLO', |
|
45 | 45 | # args = vars(ap.parse_args()) |
46 | 46 |
|
47 | 47 | # load the COCO class labels our YOLO model was trained on |
48 | | -args['threshold'] = float(args['threshold']) |
49 | | -args['confidence'] = float(args['confidence']) |
| 48 | +args['threshold'] = float(args['threshold']/10) |
| 49 | +args['confidence'] = float(args['confidence']/10) |
50 | 50 |
|
51 | 51 | labelsPath = os.path.sep.join([args["yolo"], "coco.names"]) |
52 | 52 | LABELS = open(labelsPath).read().strip().split("\n") |
|
66 | 66 |
|
67 | 67 | # load our input image and grab its spatial dimensions |
68 | 68 | image = cv2.imread(args["image"]) |
| 69 | + |
69 | 70 | (H, W) = image.shape[:2] |
70 | 71 |
|
71 | 72 | # determine only the *output* layer names that we need from YOLO |
|
143 | 144 | 0.5, color, 2) |
144 | 145 |
|
145 | 146 | # show the output image |
| 147 | +imgbytes = cv2.imencode('.png', image)[1].tobytes() # ditto |
146 | 148 |
|
147 | 149 |
|
148 | | -# let img be the PIL image |
149 | | -img = Image.fromarray(image) # create PIL image from frame |
150 | | -size = img.size |
151 | | -size = (size[0]//4, size[1]//4) |
152 | | -img = img.resize(size) |
153 | | -bio = io.BytesIO() # a binary memory resident stream |
154 | | -img.save(bio, format='PNG') # save image as png to it |
155 | | -imgbytes = bio.getvalue() # this can be used by OpenCV hopefully |
156 | | - |
157 | | -# imgbytes = cv2.imencode('.png', image)[1].tobytes() # ditto |
158 | | - |
159 | 150 | layout = [ |
160 | 151 | [sg.Text('Yolo Output')], |
161 | 152 | [sg.Image(data=imgbytes)], |
|
0 commit comments