can't index 108th element

Hi all,

This has been driving me nuts. There's probably something that already exists to do this function but I'm trying to do it manually to further my understanding.

I have two gray scale images coming from two webcams. I've aligned them using SURF features and perspective warped one to overlay onto the other.

I want to overlay the warped one onto the reference image.
The warped image has black areas that I don't want to overlay...so I'm trying this....

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
int nCols = LeftTrans.cols; //320
int nRows = LeftTrans.rows; //240

Mat OverLay = Mat::zeros(nRows,nCols,CV_8UC1);

int val = 0;
for (int col=0; col < nCols ; col++) {
	for (int row=0; row < nRows ; row++) {
		val = (int)LeftTrans.at<cv::Vec3b>(col,row)[0];

		if (val == 0) {
		//std::cout << "row = "<< row << " col = " << col <<" Val = " << val << std::endl;
		OverLay.at<cv::Vec3b>(row,col)[0] = img_scene.at<cv::Vec3b>(row,col)[0];
		} else {
		//std::cout << "row = "<< row << " col = " << col << " Val = " << val <<std::endl;
		OverLay.at<cv::Vec3b>(row,col)[0] = LeftTrans.at<cv::Vec3b>(row,col)[0];
		}
	}
}


The problem that's driving me nuts is I get "Unhandled exception error"
on the line
val = (int)LeftTrans.at<cv::Vec3b>(col,row)[0];
but only when col == 107 or row == 107

Why can't I index anything from 107 or above?
I have never used OpenCV but some quick googling suggests that CV_8UC1 is just 1 byte data. cv::Vec3b is probably 3 bytes so when you try to access col 107 it probably access data on byte column 3 * 107 = 321 which is more than nCols. I guess you have to use something else than CV_8UC1.
ah cheers for that, I've now replaced
<cv::Vec3b>
with
<uchar>
it works a treat now.

Getting used to C++ when coming from a Matlab background is tough, I'm not used to having to worry about all these little details!
Topic archived. No new replies allowed.