Conversion from ColorFrame to OpenCV Mat


I’m attempting to convert a ColorFrame from the AstraSDK to an OpenCV Mat using a ColorListener with an Astra Mini S. When accessing the BGR values from the data array, I get an access violation at array index 77136 (x=336, y = 120).

I’ve successfully done this with a DepthFrame and DepthListener and the array iterates correctly to 307200 as expected.

I’m at a a loss as to why I can only access the pixels of the colour image up to a certain index. Any help greatly appreciated.

cv::Mat colourframe2mat(ColorFrame colourFrame)
	int width = colourFrame.width();
	int height = colourFrame.height();
	RgbPixel colourvals;
	cv::Mat image(height, width, CV_8UC3);

	for (int y = 0; y < height -1; y++)
		for (int x = 0; x < width -1 ; x++)
			colourvals =[x + y*width]; //breaks at this line

			RGB& rgb = image.ptr<RGB>(y)[x]; //pre configured strut = colourvals.b; = colourvals.g; = colourvals.r;
	return image;

For anyone else experiencing this problem, upgrading to Beta 2.0.8 fixed this issue.