Hi
I’ve got an ofImage type=OF_IMAGE_ALPHA that I want to put into an ofCvColor image.
Are there any functions within ofw that can do this? Or whats the least processor heavy method?
This is from capturing a pointgrey cam.
Many thanks
Hi
I’ve got an ofImage type=OF_IMAGE_ALPHA that I want to put into an ofCvColor image.
Are there any functions within ofw that can do this? Or whats the least processor heavy method?
This is from capturing a pointgrey cam.
Many thanks
This is my code, which works, but im sure it could be quicker, possibly using memcpy and less looping?
unsigned char * rgbaPixels = rgbaImage.getPixels();
for(int i=0; i<rawHeight; i++){
for(int j=0; j<rawWidth; j++){
colorRawPixels[(i*rawWidth+j)*3 + 0] = rgbaPixels[(i*rawWidth+j)*4 + 0]; // red
colorRawPixels[(i*rawWidth+j)*3 + 1] = rgbaPixels[(i*rawWidth+j)*4 + 1]; // green
colorRawPixels[(i*rawWidth+j)*3 + 2] = rgbaPixels[(i*rawWidth+j)*4 + 2]; // blue
}
}
colorRaw.setFromPixels(colorRawPixels, rawWidth, rawHeight);
Here is the same with one loop.
Less calculations for where in the array you are.
unsigned char * rgbaPixels = rgbaImage.getPixels();
//total rgb pixels
int totalPixels = rawWidth * rawHeight * 3;
int k = 0; //for stepping through the the rgba image
for(int i = 0; i < totalPixels; i+= 3){
colorRawPixels[i] = rgbaPixels[k];
colorRawPixels[i+1] = rgbaPixels[k+1];
colorRawPixels[i+2] = rgbaPixels[k+2];
k+=4; //go to the next pixel for the rgba array
}
colorRaw.setFromPixels(colorRawPixels, rawWidth, rawHeight);
Technically you can make things faster by using pointers to move through the pixels - but any decent compiler will do similar optimizations to your code in the compile process, so it is best to stick with arrays and keep things readable!
I once spent the time re-writing all my image processing operations using pointers only to find 0% performance improvement - the compiler was doing the same thing behind the scenes.
Theo
hi cris you can make this, i have the same problem, i want to put of_image_alpha in ofcvColor, and use cvColor for many things, i use open cv and OF 0.06… thx Crish
[quote author=“chrisoshea”]Hi
I’ve got an ofImage type=OF_IMAGE_ALPHA that I want to put into an ofCvColor image.
Are there any functions within ofw that can do this? Or whats the least processor heavy method?
This is from capturing a pointgrey cam.
Many thanks[/quote]