I am very new to C++ and image processing in general.
I want to create a new unsigned char*
which represents an array of pixels for use with ofTexture. I currently have two similar arrays which are both from ofVideoGrabber objects.
I was hoping to achieve this by processing line by line, pixels of the first VideoGrabber followed by the pixels of the second. So that one video will be on the right and the other on the left.
The final texture will be the width of the combined videoGrabber arrays. where as the height will be the same as a single videoGrabber.
As far as I can tell my logic is sound but my code produces strange results.
unsigned char* videoSample::createSample(unsigned char* left, unsigned char* right)
{
texture = new unsigned char[((vidWidth*2)*vidHeight)*3];
int totalSize = ((vidWidth*2)*vidHeight)*3;
bool drawLeft=true; //flag for indicating which video grabber to draw from
int l=0; //for counting the pixels of the left video
int r=0; //for counting the pixels of the right video
for(int i = 0; i < totalSize; i++)
{
if(i%vidWidth==0)
{
drawLeft=!drawLeft;
}
if(drawLeft)
{
l++;
}
else
{
r++;
}
if(drawLeft)
{
texture[i] = left[l];
}
else
{
texture[i] = right[r];
}
}
return texture;
}
If anyone could suggest to me a better way of doing this or point out a flaw in my code I'd be pleased to hear it, thank you.