Probably because you're asking for 3 uchar values. Look at the lines with .at<Vec3b>. The type between the < and > is the type it returns. In as grayscale image, the type is uchar, but you're asking for a vector of 3 uchar. Try replacing the Vec3b with uchar.