segmentation refactoring and testing (with opencv)