Menu

save a cbyteimage with opencv as tiff

Help
2010-05-06
2013-05-09
  • Nobody/Anonymous

    Hello,

    I'm trying to save an edited Image with opencv as an tiff file.
    Here my sample code:

    void FileHelper::saveAsTiff(CByteImage *image, string filename){
        string file;
        IplImage* imageToSave;
        file.append("/images/");
        file.append(filename);
        imageToSave  IplImageAdaptor::Adapt(image,false);
        cvSaveImage(file.c_str(),imageToSave);
    }
    

    Now my problem is, the file will be created but the color is wrong. It's in blue…

    What's wrong with my sample?

    Thanks for any help :)

     
  • Pedram Azad

    Pedram Azad - 2010-05-07

    Hi,

    that is a known issue of OpenCV, it often uses BGR instead of RGB.

    You have to switch the B and R. You can copy code from IVT/Image/ImageAccessCV.cpp, which does exactly the same for loading an image with the aid of OpenCV. I'll add ImageAccessCV::SaveToFile in the next version.

    Pedram

     
  • Pedram Azad

    Pedram Azad - 2010-05-12

    Hi,

    take a look at the new version 1.3.9 of the IVT. I added the function ImageAccessCV::SaveToFile and also updated the example application IVT/examples/SimpleAppCV (resp. IVT/win32/SimpleAppCV) to show the use of ImageAccessCV::LoadFromFile and ImageAccessCV::SaveToFile.

    Pedram

     
  • Nobody/Anonymous

    Hi,

    I've tried this new version of IVT.
    I used this code here:

    //store image as tiff
    void FileHelper::saveAsTiff(CByteImage *image, string filename){
        string file;
        file.append("/images/");
        file.append(filename);
        if(!ImageAccessCV::SaveToFile(image,file.c_str())){
    //        printf("Fehler: konnte Bild (%s) nicht speichern \n",file.c_str());
        }
    }
    

    The image wil be saved but it's return the message "segmentation failure".

    I read in the code, this is a message from OpenCV.  How I can prevent this error?
    I saw in the new function code that the error message of the new function has the wrong message.

    printf("error: CByteImage::eRGB24Split not supported by ImageAccessCV::LoadFromFile\n");
    

    should be:

    printf("error: CByteImage::eRGB24Split not supported by ImageAccessCV::SaveToFile\n");
    

    Thanks for your help :)

     

Log in to post a comment.