Hi @jacklin123
So when i set the image resolution to 12MP and try to access the passthrough output of the NN node it gets stuck there itself. However, then I printed the output queue of the ISP and Manip node and both showed me None before getting stuck at passthrough.
I tried the same with setting up 1080P resolution. The very first initial output of the ISP and Manip nodes do show None but the passthrough shows an actual depthai image frame. In the following iterations ISP, Manip and passthrough outputs do show a depthai image frame. Still trying to figure out what might be the issue.
Also, thanks for the input on enclosing this code. I am again enclosing the entire code here for your reference.
with configPath.open() as f:
config = json.load(f)
nnConfig = config.get("nn_config", {})
# parse input shape
if "input_size" in nnConfig:
W, H = tuple(map(int, nnConfig.get("input_size").split('x')))
# extract metadata
metadata = nnConfig.get("NN_specific_metadata", {})
classes = metadata.get("classes", {})
coordinates = metadata.get("coordinates", {})
anchors = metadata.get("anchors", {})
anchorMasks = metadata.get("anchor_masks", {})
iouThreshold = metadata.get("iou_threshold", {})
confidenceThreshold = metadata.get("confidence_threshold", {})
print(metadata)
# parse labels
nnMappings = config.get("mappings", {})
labels = nnMappings.get("labels", {})
print("Labels: ", labels)
# get model path
nnPath = args.model
if not Path(nnPath).exists():
print("No blob found at {}. Looking into DepthAI model zoo.".format(nnPath))
nnPath = str(blobconverter.from_zoo(args.model, shaves = 6, zoo_type = "depthai", use_cache=True))
# sync outputs
syncNN = True
# Create pipeline
pipeline = dai.Pipeline()
# Define sources and outputs
camRgb = pipeline.create(dai.node.ColorCamera)
detectionNetwork = pipeline.create(dai.node.YoloDetectionNetwork)
#xoutRgb = pipeline.create(dai.node.XLinkOut)
nnOut = pipeline.create(dai.node.XLinkOut)
# By Yishu
xoutISP = pipeline.create(dai.node.XLinkOut)
manip = pipeline.create(dai.node.ImageManip)
xoutManip = pipeline.create(dai.node.XLinkOut)
# Passthrough to debug
# Send passthrough frames to the host, so frames are in sync with bounding boxes
passthroughOut = pipeline.create(dai.node.XLinkOut)
passthroughOut.setStreamName("pass")
detectionNetwork.passthrough.link(passthroughOut.input)
#xoutRgb.setStreamName("rgb")
xoutISP.setStreamName("ISP")
nnOut.setStreamName("nn")
xoutManip.setStreamName("Manip")
# Properties
camRgb.setPreviewSize(W, H)
camRgb.setResolution(dai.ColorCameraProperties.SensorResolution.THE_1080_P) #THE_1080_P
camRgb.setInterleaved(False)
camRgb.setColorOrder(dai.ColorCameraProperties.ColorOrder.RGB)
camRgb.setFps(25) #40
# By Yishu
manip.initialConfig.setKeepAspectRatio(False) #True
manip.initialConfig.setResize(W, H)
# Change to RGB image than BGR - Yishu
#manip.initialConfig.setFrameType(dai.ImgFrame.Type.RGB888p) #dai.ImgFrame.Type.BGR888p
manip.initialConfig.setFrameType(dai.ImgFrame.Type.BGR888p) #dai.ImgFrame.Type.RGB888p
# setMaxOutputFrameSize to avoid image bigger than max frame size error - Yishu
manip.setMaxOutputFrameSize(1228800)
# By Yishu
nnOut.input.setBlocking(False)
xoutISP.input.setBlocking(False)
xoutManip.input.setBlocking(False)
# By Yishu
nnOut.input.setQueueSize(10)
xoutISP.input.setQueueSize(10)
xoutManip.input.setQueueSize(10)
detectionNetwork.input.setQueueSize(10)
# Network specific settings
detectionNetwork.setConfidenceThreshold(confidenceThreshold)
detectionNetwork.setNumClasses(classes)
detectionNetwork.setCoordinateSize(coordinates)
detectionNetwork.setAnchors(anchors)
detectionNetwork.setAnchorMasks(anchorMasks)
detectionNetwork.setIouThreshold(iouThreshold)
detectionNetwork.setBlobPath(nnPath)
detectionNetwork.setNumInferenceThreads(2)
detectionNetwork.input.setBlocking(False)
# Linking
#camRgb.preview.link(detectionNetwork.input)
#detectionNetwork.passthrough.link(xoutRgb.input)
#detectionNetwork.out.link(nnOut.input)
camRgb.isp.link(manip.inputImage)
#camRgb.still.link(manip.inputImage)
manip.out.link(detectionNetwork.input)
# By Yishu
manip.out.link(xoutManip.input)
#detectionNetwork.passthrough.link(xoutISP.input)
detectionNetwork.out.link(nnOut.input)
camRgb.isp.link(xoutISP.input)
device_info = dai.DeviceInfo("192.168.220.10")
# Connect to device and start pipeline
with dai.Device(pipeline, device_info) as device:
print("1")
# Output queues will be used to get the rgb frames and nn data from the outputs defined above
#qRgb = device.getOutputQueue(name="rgb", maxSize=4, blocking=False)
#qDet = device.getOutputQueue(name="nn", maxSize=4, blocking=False)
qDet = device.getOutputQueue("nn", 4, blocking=False) #device.getOutputQueue("nn", 1, blocking=False)
qISP = device.getOutputQueue("ISP", 4, blocking=False)
qManip = device.getOutputQueue("Manip", 4, blocking=False)
# Passthrough to debug
qPass = device.getOutputQueue(name="pass")
frame = None
detections = []
startTime = time.monotonic()
counter = 0
color2 = (255, 255, 255)
# nn data, being the bounding box locations, are in <0..1> range - they need to be normalized with frame width/height
def frameNorm(frame, bbox):
normVals = np.full(len(bbox), frame.shape[0])
normVals[::2] = frame.shape[1]
return (np.clip(np.array(bbox), 0, 1) * normVals).astype(int)
def displayFrame(name, frame, detections, i):
color_spool = (255, 0, 0)
color_person = (0, 255, 0)
color = ''
text_output_path = "D:\\Cameras_Live\\PayOff\\" + "label_{}".format(j) + ".txt"
print("Detections: ", [[d.label, d.confidence *100, d.xmin, d.ymin, d.xmax, d.ymax] for d in detections])
text_file = open(text_output_path, 'w')
for detection in detections:
bbox = frameNorm(frame, (detection.xmin, detection.ymin, detection.xmax, detection.ymax))
if labels[detection.label] == 'person':
color = color_person
else:
color = color_spool
cv2.putText(frame, labels[detection.label], (bbox[0] + 10, bbox[1] + 20), cv2.FONT_HERSHEY_TRIPLEX, 0.5, (255,255,255))
cv2.putText(frame, f"{int(detection.confidence * 100)}%", (bbox[0] + 10, bbox[1] + 40), cv2.FONT_HERSHEY_TRIPLEX, 0.5, (255,255,255))
cv2.rectangle(frame, (bbox[0], bbox[1]), (bbox[2], bbox[3]), color, 2)
# Write detections to a text file
text_file.write(f'{labels[detection.label]} {bbox[0]} {bbox[1]} {bbox[2]} {bbox[3]} {detection.confidence}\n') # Add a separator between entries
text_file.close()
# Show the frame
#cv2.namedWindow("Model Inference", cv2.WND_PROP_FULLSCREEN)
cv2.namedWindow(name, cv2.WINDOW_NORMAL)
#cv2.setWindowProperty(name, cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_FULLSCREEN)
cv2.imshow(name, frame)
print("2")
j=1
###Create the folder that will contain capturing
folder_name = "D:\\Cameras_Live\\PayOff"
path = Path(folder_name)
while True:
###Create the folder that will contain capturing
path.mkdir(parents=True, exist_ok=True)
print("3")
# By Yishu
inISP = qISP.tryGet()
print("4")
inManip = qManip.tryGet()
print("Manip: ", inManip)
print("5")
frame_pass = qPass.get() #.getCvFrame()
print('passthrough: ', frame_pass)
inDet = qDet.get()
print("6")
if inISP is not None:
print("inISP not None")
frame = inISP.getCvFrame()
cv2.imwrite("D:\\Cameras_Live\\PayOff\\RGB_Manip_{}.png".format(j), frame)
nn_fps =counter / (time.monotonic() - startTime)
print("nn_fps: ", nn_fps)
cv2.putText(frame, "NN fps: {:.2f}".format(nn_fps),
(2, frame.shape[0] - 4), cv2.FONT_HERSHEY_TRIPLEX, 0.4, color2)
print("7")
if inDet is not None:
detections = inDet.detections
counter += 1
print("8")
if frame is not None:
print("Frame not None")
displayFrame("manip", frame, detections, j)
print("9")
if cv2.waitKey(1) == ord('q'):
break
j=j+1
if j==5:
j=1
print("10")
Thanks,
Yishu