Skip to content

Commit 2c87142

Browse files
committed
Don't do color conversion twice
1 parent 202a388 commit 2c87142

3 files changed

Lines changed: 9 additions & 14 deletions

File tree

examples/image/classify-image.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,9 @@ def main(argv):
4747
print('Failed to load image', args[1])
4848
exit(1)
4949

50-
# imread returns images in BGR format, so we need to convert to RGB
51-
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
52-
5350
# get_features_from_image also takes a crop direction arguments in case you don't have square images
5451
features, cropped = runner.get_features_from_image(img)
5552

56-
# the image will be resized and cropped, save a copy of the picture here
57-
# so you can see what's being passed into the classifier
58-
cv2.imwrite('debug.jpg', cv2.cvtColor(cropped, cv2.COLOR_RGB2BGR))
59-
6053
res = runner.classify(features)
6154

6255
if "classification" in res["result"].keys():
@@ -70,6 +63,12 @@ def main(argv):
7063
print('Found %d bounding boxes (%d ms.)' % (len(res["result"]["bounding_boxes"]), res['timing']['dsp'] + res['timing']['classification']))
7164
for bb in res["result"]["bounding_boxes"]:
7265
print('\t%s (%.2f): x=%d y=%d w=%d h=%d' % (bb['label'], bb['value'], bb['x'], bb['y'], bb['width'], bb['height']))
66+
cropped = cv2.rectangle(cropped, (bb['x'], bb['y']), (bb['x'] + bb['width'], bb['y'] + bb['height']), (255, 0, 0), 1)
67+
68+
# the image will be resized and cropped, save a copy of the picture here
69+
# so you can see what's being passed into the classifier
70+
cv2.imwrite('debug.jpg', cv2.cvtColor(cropped, cv2.COLOR_RGB2BGR))
71+
7372
finally:
7473
if (runner):
7574
runner.stop()

examples/image/classify-video.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,14 @@ def getFrame(sec):
5757
hasFrames,image = vidcap.read()
5858
if hasFrames:
5959
return image
60-
else:
60+
else:
6161
print('Failed to load frame', args[1])
6262
exit(1)
6363

6464

6565
img = getFrame(sec)
6666

6767
while img.size != 0:
68-
69-
# imread returns images in BGR format, so we need to convert to RGB
70-
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
7168

7269
# get_features_from_image also takes a crop direction arguments in case you don't have square images
7370
features, cropped = runner.get_features_from_image(img)

setup.cfg

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,5 @@ packages = find:
1818
python_requires = >=3.6
1919
install_requires =
2020
numpy>=1.19
21-
opencv-python==4.5.1.48
22-
PyAudio==0.2.11
23-
psutil==5.8.0
21+
opencv-python>=4.5.1.48
22+
psutil>=5.8.0

0 commit comments

Comments
 (0)