// // libRT2opencv.c - Used to convert an image from libRT format to opencv format. // #include "cv.h" #include "cxcore.h" #include "highgui.h" #include #include #include "ImageMagicKSource.h" #include "Image.h" #include "ImageBase.h" #include "ImageRGB.h" #include "PixelRGB.h" #include typedef ImageDisplay< ImageWindow > ImageDisplayWindow; int procMain(int argc, char** argv) //int main (int argc, char *argv[]) { char file[100]; if (argc == 2) sprintf(file, "%s", argv[1]); else if (argc != 2) { printf("Usage: ./libRT2opencv \n"); return -1; } // Load image with ImageMagicK ImageMagicKSource src(file); if(!src.InitOK()) { printf("Could not load image.\n"); return -1; } unsigned int w, h; src.get_size(w, h); ImageRGB lib(w,h); src >> lib; // Change format CvSize size; size.width = w; size.height = h; IplImage *ocv = cvCreateImage(size, IPL_DEPTH_8U, 3); int pix, pos = 0, max = w * h, t; PixelRGB p; // If the image is a jpg, add one to imageData position otherwise the colour // channels are transposed. BMPs don't need this.) char *ext = strchr(file, '.'); if (strcmp(ext, ".jpg") == 0) ++pos; for (pix = 0; pix < max; pix++) { p = lib.data[pix]; ocv->imageData[pos++] = p[2]; ocv->imageData[pos++] = p[1]; ocv->imageData[pos++] = p[0]; // Account for picture padding in bmp's if (pix % w == 0) pos += (w % 4); } // Display image in window cvNamedWindow("result", -1); cvShowImage("result", ocv); cvWaitKey(0); cvDestroyWindow("result"); cvReleaseImage(&ocv); return (0); }