From: Pedro M. S. <psh...@dc...> - 2007-03-16 19:40:25
|
Hello, I've changed imageseq driver to support color images. I've tested with PPM rawbit and jpeg images but it should work with others formats. Following is the diff output (for player-2.0.3). Bests, Pedro -------------------------------------------------- --- imageseq.cc.old 2007-03-16 16:08:30.000000000 -0300 +++ imageseq.cc 2007-03-16 16:16:55.000000000 -0300 @@ -227,15 +227,52 @@ IplImage *image; // Load image; currently forces the image to mono - image = cvLoadImage(filename, 0); - + image = cvLoadImage(filename, -1); + /* + printf("IPL: Size = %d width x %d height\n" + " Channels = %d [1 : (bw), 2 , 3 : (rgb), 4 : (rgba)]\n" + " Depth = %d bits [8u 8s 16s 32s 32f 64f]\n" + " Origin = %d [0: top-left; 1: bottom-left]\n" + " Align = %d [alignment of image rows = 4 or 8]\n" + " Img size = %d [height * width step]\n" + " W. step = %d size of a row = width*channels*depth/8\n", + image->width, image->height, image->nChannels, image->depth, image->origin, + image->align, image->imageSize, image->widthStep); + */ this->data.width = image->width; this->data.height = image->height; - this->data.bpp = 8; - this->data.format = PLAYER_CAMERA_FORMAT_MONO8; this->data.compression = PLAYER_CAMERA_COMPRESS_RAW; - this->data.image_count = this->data.width * this->data.height; - + this->data.image_count = image->imageSize; + + switch (image->depth) + { + case IPL_DEPTH_8U: + case IPL_DEPTH_8S: + if (image->nChannels == 1) + { + this->data.bpp = 8; + this->data.format = PLAYER_CAMERA_FORMAT_MONO8; + } + else if (image->nChannels == 3) + { + this->data.bpp = 24; + this->data.format = PLAYER_CAMERA_FORMAT_RGB888; + } + break; + case IPL_DEPTH_16S: + if (image->nChannels == 1) + { + this->data.bpp = 16; + this->data.format = PLAYER_CAMERA_FORMAT_MONO16; + } + break; + case IPL_DEPTH_32S: + case IPL_DEPTH_32F: + case IPL_DEPTH_64F: + default: + break; + } + // Check image size if (this->data.image_count > PLAYER_CAMERA_IMAGE_SIZE) { @@ -244,13 +281,28 @@ } // Copy the pixels - for (i = 0; i < image->height; i++) + if (image->nChannels == 1) + for (i = 0; i < image->height; i++) + { + src = image->imageData + i * image->widthStep; + dst = this->data.image + i * image->widthStep; + memcpy(dst, src, image->widthStep); + } + else if (image->nChannels == 3) { - src = image->imageData + i * image->widthStep; - dst = this->data.image + i * this->data.width; - memcpy(dst, src, this->data.width); + for (int i = 0; i < image->height; i++) + for (int j = 0; j < image->width; j++) + { + // Convert BGR to RGB + this->data.image[i*image->widthStep+3*j +0]=image->imageData[i*image->widthStep+3*j+2]; + this->data.image[i*image->widthStep+3*j +1]=image->imageData[i*image->widthStep+3*j+1]; + this->data.image[i*image->widthStep+3*j +2]=image->imageData[i*image->widthStep+3*j+0]; + + } } - + + cvReleaseImage(&image); + return 0; } |