Skip to content

Commit

Permalink
Properly decode labels into utf-8
Browse files Browse the repository at this point in the history
  • Loading branch information
madhawav committed Mar 18, 2021
1 parent 66f3ce4 commit 4b26b3a
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion demo/image_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
for cat, score, bounds in results:
x, y, w, h = bounds
cv2.rectangle(img, (int(x - w / 2), int(y - h / 2)), (int(x + w / 2), int(y + h / 2)), (255, 0, 0), thickness=2)
cv2.putText(img,str(cat.decode("utf-8")),(int(x),int(y)),cv2.FONT_HERSHEY_COMPLEX,1,(255,255,0))
cv2.putText(img, cat, (int(x),int(y)),cv2.FONT_HERSHEY_COMPLEX,1,(255,255,0))

cv2.imshow("output", img)
# img2 = pydarknet.load_image(img)
Expand Down
2 changes: 1 addition & 1 deletion demo/video_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
for cat, score, bounds in results:
x, y, w, h = bounds
cv2.rectangle(frame, (int(x-w/2),int(y-h/2)),(int(x+w/2),int(y+h/2)),(255,0,0))
cv2.putText(frame, str(cat.decode("utf-8")), (int(x), int(y)), cv2.FONT_HERSHEY_COMPLEX, 1, (255, 255, 0))
cv2.putText(frame, cat, (int(x), int(y)), cv2.FONT_HERSHEY_COMPLEX, 1, (255, 255, 0))

cv2.imshow("preview", frame)

Expand Down
2 changes: 1 addition & 1 deletion demo/webcam_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
for cat, score, bounds in results:
x, y, w, h = bounds
cv2.rectangle(frame, (int(x-w/2),int(y-h/2)),(int(x+w/2),int(y+h/2)),(255,0,0))
cv2.putText(frame, str(cat.decode("utf-8")), (int(x), int(y)), cv2.FONT_HERSHEY_COMPLEX, 1, (255, 255, 0))
cv2.putText(frame, cat, (int(x), int(y)), cv2.FONT_HERSHEY_COMPLEX, 1, (255, 255, 0))

cv2.imshow("preview", frame)

Expand Down
2 changes: 1 addition & 1 deletion src/pydarknet.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ cdef class Detector:
for i in range(self.meta.classes):
if dets[j].prob[i] > 0:
b = dets[j].bbox
res.append((self.meta.names[i], dets[j].prob[i], (b.x, b.y, b.w, b.h)))
res.append((self.meta.names[i].decode("utf-8"), dets[j].prob[i], (b.x, b.y, b.w, b.h)))
res = sorted(res, key=lambda x: -x[1])

free_detections(dets, num)
Expand Down
2 changes: 1 addition & 1 deletion test/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def test_image():

results = net.detect(img2)

results_labels = [x[0].decode("utf-8") for x in results]
results_labels = [x[0] for x in results]

assert "bicycle" in results_labels
assert "dog" in results_labels
Expand Down

0 comments on commit 4b26b3a

Please sign in to comment.