The way you do it the system will depend on stable lighting conditions very much (the threshold variable in findContours) which is unlikely to happen in agriculture. This is a classic use case for Deep Learning. Haven’t tried yet the inference of opencv but we could you provide a professional training set or neural network.