Sometimes this code triggers a critical error. I tried to put every condition I could think of to prevent bad input, but it's still not working sometimes.
if (image.rows < 1 || image.cols < 1 || ![keyframe.camera isInFrame:position withBoundary:0] || image.channels() < 4)
return Vec3f(0,0,0);
Vec4b bgra;
bgra = image.at<Vec4b>(position.x, position.y);
Any clue?