Detecting shapes in an image

Thanks for the detailed code snippet @Micka. Since Python is currently being used, had translated the code snippet you posted. After resolving some basic issues, I am currently looking to implement the masking you implemented. Below error is thrown.

cv2.error: OpenCV(4.5.4) :-1: error: (-5:Bad argument) in function 'resize'
> Overload resolution failed:
>  - src data type = 0 is not supported
>  - Expected Ptr<cv::UMat> for argument 'src'

Post masking all values on the combined array become false. Would be great if you could add clarity for implementing the masking portion of your algorithm.