Necesito convertir una IplImage de 8 bits a una imagen Ipl de 32 bits. Utilizando la documentación de toda la web He intentado lo siguiente:¿Cómo convertir una imagen IplImage * OpenCV de 8 bits a una IplImage * de 32 bits?
// general code
img2 = cvCreateImage(cvSize(img->width, img->height), 32, 3);
int height = img->height;
int width = img->width;
int channels = img->nChannels;
int step1 = img->widthStep;
int step2 = img2->widthStep;
int depth1 = img->depth;
int depth2 = img2->depth;
uchar *data1 = (uchar *)img->imageData;
uchar *data2 = (uchar *)img2->imageData;
for(h=0;h<height;h++) for(w=0;w<width;w++) for(c=0;c<channels;c++) {
// attempt code...
}
// attempt one
// result: white image, two red spots which appear in the original image too.
// this is the closest result, what's going wrong?!
// see: http://files.dazjorz.com/cache/conversion.png
((float*)data2+h*step2+w*channels+c)[0] = data1[h*step1+w*channels+c];
// attempt two
// when I change float to unsigned long in both previous examples, I get a black screen.
// attempt three
// result: seemingly random data to the top of the screen.
data2[h*step2+w*channels*3+c] = data1[h*step1+w*channels+c];
data2[h*step2+w*channels*3+c+1] = 0x00;
data2[h*step2+w*channels*3+c+2] = 0x00;
// and then some other things. Nothing did what I wanted. I couldn't get an output
// image which looked the same as the input image.
Como se puede ver que no se sabe muy bien lo que estoy haciendo. Me encantaría saberlo, pero me gustaría más si pudiera hacer esto correctamente. ¡Gracias por cualquier ayuda que reciba!
Hay algo de información interesante en esa página, piezas de código que explican lo que he ya lo intenté. Sin embargo, los resultados son los mismos. Consulte el siguiente enlace para ver un ejemplo de lo que va mal todo el tiempo: http://files.dazjorz.com/cache/conversion.png – sgielen
Whoa, sí, eso es un bueno, tienes razón! Así que da la siguiente pista: para los puntos rojos, R es 1.0 y GB son 0.0, y para el blanco, los tres son 1.0. Por lo tanto, al convertir, los valores RGB deberían d se convertirá de 0 a 255 a 0.0 a 1.0. Cambiar el valor a b/255 hace que la imagen sea negra + roja. – sgielen
¡Entendido! int b = ((uchar *) (img-> imageData + h * img-> widthStep)) [w * img-> nChannels + 0]; // B ((float *) (img2-> imageData + h * img2-> widthStep)) [w * img2-> nChannels + 0] = ((float) b)/255.0; – sgielen