1 | initial version |
your example code is lacking 2 checks:
int main()
{
namedWindow("Example1");
Mat img = imread("D:/sample.jpg");
if ( img.empty() ) {
cout << "damn, it did not load !" << endl;
return -1;
}
Rect r(170,150,250,100); // desired roi
Rect R(0,0,img.cols, img.rows); // image size
r &= R; // crop if nessecary
Mat roi = img(r);
imshow("Example1",roi);
waitKey(0);
return 0;
}