Mario.Tapilouw

Friday, April 02, 2010

Copying Euresys EImage into OpenCV IplImage

I tried to find a way to copy Euresys' EImage to OpenCV's IplImage. The reason is that I want to develop my algorithm based on the free OpenCV library so that I can try it anytime in my laptop without having to attach Euresys cards or license key.

Another advantage of doing this is that when I change to another image grabber card, I can still use my algorithm with some data conversion process. Speeding up will be a further issue after the algorithm is proven to work correctly.

So, here it is, by using this piece of code you can copy the EImage data seamlessly into IplImage.

Suppose that we have these objects:
IplImage *GLCVImage;
EImageBW8 GLImage;

We can copy the data directly by passing the pointer;

GLCVImage->imageData = reinterpret_cast < char* >(GLImage.GetImagePtr());



Hope it works with yours. I use this quite often and I post this here to make it easier for me in case I need to do the same thing again.

Labels: , , ,

4 Comments:

  • This didn't work for me, so I put my own solution here just in case someone else may be interested:
    void EImageToCVImage(EImageBW8 eImage, IplImage* cvImage)
    {
    uchar* ptrE;
    uchar* ptrCV;
    for (int i=0; i < eImage.GetHeight(); i++)
    {
    ptrCV = (uchar*) (cvImage->imageData + i*cvImage->widthStep);
    ptrE = (uchar*) (eImage.GetImagePtr() + i*eImage.GetRowPitch());
    for (int j=0; j<eImage.GetWidth(); j++)
    {
    ptrCV[j] = ptrE[j];
    }
    }
    }

    Thanks again for your previous answers on the other topic, it helped me a lot. Now I have my own application that make the acquisition in one thread and the image processing in the main.

    Sebastien

    By Anonymous sebastien, at April 19, 2010 at 10:53 AM  

  • Hi Sebastien,
    Thanks for your comments. Actually, this is another way that you can do to achieve the same goal.

    It seems to be that blogger filtered my post and removed the "<>" marks after the reinterpret_cast, there should be a data type (uchar*) after the reinterpret_cast.

    The correct one should be:

    GLCVImage->imageData = reinterpret_cast< uchar* >(GLImage.GetImagePtr());

    This method works by passing the pointer to the Euresys image data to the OpenCV IplImage pointer so that you don't have to perform a loop for data transfer (sounds complicated...).

    Good then, nice to hear that!

    By Blogger mario, at April 19, 2010 at 11:22 AM  

  • Indeed, the reinterpret_cast works for me too, now. But I use char* instead of uchar*.
    It should save some precious computing time, too.

    Thanks again.

    By Anonymous sebastien, at April 19, 2010 at 7:31 PM  

  • Hi Sebastien, thanks for your correction. Yes, it should be char* instead of uchar*.

    By Blogger mario, at May 4, 2010 at 5:00 PM  

Post a Comment

<< Home