The trouble with ofCvFloatImage is that its a grayscale image, and in my case I need to have a color float image.
I saved a copy of ofCvFloatImage and renamed it to ofCvFloatColorImage then changed just a few lines
void ofCvFloatColorImage::allocate(int _w, int _h){
....
cvImage = cvCreateImage(cvSize(_w,_h), IPL_DEPTH_32F,3);
cvImageTemp = cvCreateImage(cvSize(_w,_h), IPL_DEPTH_32F,3);
cvImageTemp2 = cvCreateImage(cvSize(_w,_h), IPL_DEPTH_32F,3);
cvImage8U = cvCreateImage(cvSize(_w,_h), IPL_DEPTH_8U,3);
pixels = new unsigned char[_w*_h*3];
floatPixels = new float[_w*_h*3];
....
}
void ofCvFloatColorImage::setFromFloatPixels(float * _pixels, int w, int h){
for (int i = 0; i < h; i++){
memcpy(cvImage->imageData + (i * cvImage->widthStep), _pixels + (i * w * 3), sizeof(float)*w*3);
}
for (int i = 0; i < h; i++){
memcpy(pixels + (i * w * 3), cvImage->imageData + (i * cvImage->widthStep), sizeof(float)*w*3);
}
}
unsigned char * ofCvFloatColorImage::getPixels(){
// copy each line of pixels:
cvConvertScale( cvImage, cvImage8U, 1, 0);
for (int i = 0; i < height; i++){
memcpy(pixels + (i * width * 3), cvImage8U->imageData + (i * cvImage8U->widthStep), width*3);
}
return pixels;
}
Here are those files
[files updated, see posts below]
http://www.chrisoshea.org/storage/ofw/o-…-lorImage.h
http://www.chrisoshea.org/storage/ofw/o-…-rImage.cpp
However it doesn’t work.
Just to confirm, how are the opencv images split, is it rgb or bgr?
are the pixels in the array
rgbrgbrgbrgb
or
rrrrrrr ggggggg bbbbb
if that makes sense? (i forgot which way they worked, havent touched this in a few weeks).
Thanks