Please see the following blog post for more details about this code Parallel Pixel Access in OpenCV using forEach