My code is:
import gluoncv as gcv
net = gcv.model_zoo.get_model('ssd_512_mobilenet1.0_voc', pretrained=True)
windowName = "ssdObject"
cv2.namedWindow(windowName, cv2.WINDOW_NORMAL)
cv2.resizeWindow(windowName, 1280, 720)
cv2.moveWindow(windowName, 0, 0)
cv2.setWindowTitle(windowName, "SSD Object Detection")
while True:
# Check to see if the user closed the window
if cv2.getWindowProperty(windowName, 0) < 0:
# This will fail if the user closed the window; Nasties get printed to the console
break
ret_val, frame = video_capture.read()
frame = mx.nd.array(cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)).astype('uint8')
rgb_nd, frame = gcv.data.transforms.presets.ssd.transform_test(frame, short=512, max_size=700)
# # Run frame through network
class_IDs, scores, bounding_boxes = net(rgb_nd)
displayBuf = frame
cv2.imshow(windowName, displayBuf)
cv2.waitKey(0)
I somehow need to draw the bounding_codes
, class_IDs
, and scores
onto the image and output it via imshow
.
How can I accomplish this?
class_IDs, scores, bounding_boxes
are 3 arrays of the same length, tied together by index ids? i.e. each bounding box has an associated class_ID and score? | If so (unless there's some pre-made rendering function for this in gluoncv).... maybe just loop over the arrays and use the primitive drawing functions to draw the rectangle and two texts, maybe with randomized colours... – StenopetalousOpenCV
window @DanMašek – Windyimshow
... although that seems a bit over the top. Drawing it yourself should be so bad... the worst thing I can see there is fiddling about with positioning/size of the text to make it look reasonable with various sizes of bounding boxes. – Stenopetalousclass_IDs, scores, bounding_boxes
values? Then I can cook up a solution without installing mxnet and finding/figuring out what video to use. | BTW, you probably should store the originalframe
in BGR format, if you want to use it for the visualization. (or, how doesgcv.data.transforms.presets.ssd.transform_test
modify the frame?) – Stenopetalous