Hello Dusty,
Thank you for your support till now.
I need some more support.
My project requirement is changed. They have asked me to take image or video from opencv , apply jetson utils to segment video, convert it back to opencv and display or save.
I was able to do it successfully, but what we have observed is that the segmented output is not as fine as it is without opencv. As a result there many pockets inside individual frames in the video where it is unable to detect the floor correctly. So robot may stop thinking that there is an obstacle, where as it should have moved ahead.
I would really appreciate your help. What we have observed is that final output opencv image contains grids of larger size due to which there are many open areas which is not captured as floor. You can think of as small sized stones fill up the glass properly or more dense than large size stones in a glass.
Here is my code below:
cap = cv2.VideoCapture(0)
ret, frame = cap.read()
frame_rgba = cv2.cvtColor(frame, cv2.COLOR_BGR2RGBA)
cuda_frame = jetson.utils.cudaFromNumpy(frame_rgba)
# process the segmentation network
net.Process(cuda_frame)
num_classes = net.GetNumClasses()
jetson.utils.cudaDeviceSynchronize()
img = jetson.utils.cudaToNumpy(cuda_frame, img_width, img_height, 4)
img = cv2.cvtColor(img, cv2.COLOR_RGBA2RGB).astype(np.uint8)
img = cv2.cvtColor(img, cv2.COLOR_RGB2BGR)
# Allocate buffer for mask
class_mask = jetson.utils.cudaAllocMa`Preformatted text`pped(width=img_width, height=img_height, format="gray8")
class_mask_np = jetson.utils.cudaToNumpy(class_mask)
# get the class mask (each pixel contains the classID for itself)
net.Mask(class_mask, img_width, img_height)
class_mask_np = jetson.utils.cudaToNumpy(class_mask)
# compute the number of times each class occurs in the mask
arr = np.array(class_mask_np)
img = cv2.resize(img, (img_width, img_height), interpolation = cv2.INTER_LINEAR)
output = img.copy()
# Color the pixel with green for those representing a class_id
if args.classid == 99:
for n in range(num_classes):
valid = np.all(arr == n, axis = -1)
rs, cs = valid.nonzero()
colorCode = net.GetClassColor(n)
output[rs, cs, :] = [colorCode[0],colorCode[1],colorCode[2]]
else:
valid = np.all(arr == args.classid, axis = -1)
rs, cs = valid.nonzero()
colorCode = net.GetClassColor(args.classid)
output[rs, cs, :] = [colorCode[0],colorCode[1],colorCode[2]]
overlayed_image = cv2.addWeighted(img,0.5,output,0.5,0)
cv2.imshow("overlayed_image", overlayed_image)