Someone might help, if you help them help:
- Remove the screenshot and post your code as text
- Debug the code and find the exact place that fails
- Report the exact problem, software context - data, variable values etc…
- Tell what you have tried already to solve the problem
- Tell what environment you have - OS, OpenCV version etc