Skip to content

Commit 76d3461

Browse files
Fixed display problem. Was getting bad colors. Enabled ability to run using either PSG or PSG-Qt by only changing import.
1 parent ccfd556 commit 76d3461

1 file changed

Lines changed: 14 additions & 23 deletions

File tree

YoloObjectDetection/yolo.py

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
# USAGE
22
# python yolo.py --image images/baggage_claim.jpg --yolo yolo-coco
33
"""
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]
58
[-t THRESHOLD]
69
"""
710

8-
911
# import the necessary packages
1012
import numpy as np
1113
import argparse
1214
import time
1315
import cv2
1416
import os
15-
import PySimpleGUI as sg
16-
from PIL import Image
17-
import io
17+
import PySimpleGUIQt as sg
1818

1919
layout = [
2020
[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()]
2626
]
2727

2828
win = sg.Window('YOLO',
@@ -45,8 +45,8 @@
4545
# args = vars(ap.parse_args())
4646

4747
# 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)
5050

5151
labelsPath = os.path.sep.join([args["yolo"], "coco.names"])
5252
LABELS = open(labelsPath).read().strip().split("\n")
@@ -66,6 +66,7 @@
6666

6767
# load our input image and grab its spatial dimensions
6868
image = cv2.imread(args["image"])
69+
6970
(H, W) = image.shape[:2]
7071

7172
# determine only the *output* layer names that we need from YOLO
@@ -143,19 +144,9 @@
143144
0.5, color, 2)
144145

145146
# show the output image
147+
imgbytes = cv2.imencode('.png', image)[1].tobytes() # ditto
146148

147149

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-
159150
layout = [
160151
[sg.Text('Yolo Output')],
161152
[sg.Image(data=imgbytes)],

0 commit comments

Comments
 (0)