new_w = (new_w * net_h) / new_h new_h = net_h # resize the image to the new size resized = cv2.resize(image[:, :, ::-1] / 255., (int(new_w), int(new_h))) # embed the image into the standard letter box new_image = np.ones((net_h, net_w, 3)) * 0.5 new_image[int((net_h - new_h) // 2):int((net_h + new_h) // 2), int((net_w - new_w) // 2):int((net_w + new_w) // 2), :] = resized new_image = np.expand_dims(new_image, 0) return new_image yolo = yolo3.YoloV3(confThreshold, nmsThreshold) video_path = "0" show = False save_to_disk = False plugin = "hacv.CVMQTTPlugin".split(".") config = None yaml_cfg = None try: argv = sys.argv[1:] opts, args = getopt.getopt(argv, "hsdv:p:c:") except getopt.GetoptError as e: sys.stderr.write(str(e) + '\n') usage() sys.exit(2)
print("PB img: width:",frame_pb.width, "height:", frame_pb.height) nparr = np.frombuffer(frame_pb.imgdata, np.uint8) frame = cv2.imdecode(nparr, cv2.IMREAD_COLOR) showFrame = True client = mqttClient.Client("Python-MQTT-CAM") client.on_connect = on_connect client.connect("localhost") client.on_message = on_message # Should take this a configs... client.subscribe("ha/camera/mqtt", 0) client.subscribe("ha/camera/mqtt_pb", 0) client.loop_start() yolo = yolo3.YoloV3(0.5, 0.4, datapath="../yolov3-ha") while(True): # Capture frame-by-frame if showFrame: # cv2.imshow('Cam-frame', frame) nf = frame.copy() d = yolo.detect(nf) cv2.imshow('Det-frame', nf) showFrame = False if cv2.waitKey(1) & 0xFF == ord('q'): break # When everything done, release the capture cv2.destroyAllWindows()