def undistort_crop(orig_img): #undistort and crop dst = cv2.undistort(orig_img, mtx, dist, None, newcameramtx) x,y,w,h = roi crop_frame = dst[y:y+h, x:x+w] return crop_frame