Which algorithm do I apply for this problem? Canny Edges, Segmentation? I tried it but low accuracy.
Just collect some ideas and think of the different szenarios like what indicates you that for a given Pixel (x,y) there will be a neigborhood, connecting between BoxA, BoxB or/and other Boxes. So, it has pretty much to do with edge detection.
So after adding some blur and doing canny edge detection, you'll have a binary image. With the given information inside your binary picture, you'll be able to use segmentation or find contours and fill in the areas of founded contours.
But as always - this is just an idea and there are many ways to reach the point where it's working satisfactorily.