answered Oct 4 '0
you need to be sure if the Rect roi is inside the image bounds
Rect roi
roi = roi & Rect(0, 0, image.cols, image.rows); Mat crop = image(roi);