'how to change the color in grabcut mask based on a class

here's my image:

enter image description here

i have 2 classes dog and truck i also have their bbox coordinates so i want to create a mask for this image so i applied grapcut algorithm here's my code

img=cv2.imread('dog.jpg')
mask=np.zeros(img.shape[:2],np.uint8)

bgModel=np.zeros((1,65),np.float64)
fgModel=np.zeros((1,65),np.float64)
tmpimage=image
masks=[]
for i in recs:
    cv2.grabCut(img,mask,i,bgModel,fgModel,10,cv2.GC_INIT_WITH_RECT)
    mask2=np.where((mask==2)|(mask==0),0,1).astype('uint8')
    masks.append(mask2)
    #img=image*mask2[:,:,np.newaxis]
finalmask=np.zeros(img.shape[:2],np.uint8)
for i in range(len(masks)):
   finalmask=finalmask+masks[i]
plt.imshow(finalmask)
# plt.colorbar()
#plt.xticks([]),plt.yticks([])
plt.show()

here's the final mask:

enter image description here

what i want to do is i want the area of the dog to have different color than area of the truck in this image both are having the same yellow color



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source