How do you integrate VisualApplets with OpenCV ?

  • Hi Mike

    welcome to the forum and thank you for the question. Others might have this question, too. I don't have my own example right now but let me share the example of a collegue. Maybe he can add some more information.


    Files

    • GrabToCV.zip

      (5.84 kB, downloaded 9 times, last: )


    Johannes Trein
    Group Leader R&D
    frame grabber

    Basler AG



  • Thank you for providing the OpenCV code. I am using the C# wrapper and am having trouble converting the SisoImage data type into a Mat or a Bitmap Image type.


    C++ Code: (your code works)

    char* dataBuffer = (char*)Fg_getImagePtrEx(fg,lastPicNr,0,pMem0); //getBufferOfPhoto();

    Mat any_img(Size(width, height), CV_8UC1, dataBuffer, Mat::AUTO_STEP);

    imshow( "Display window raw", any_img );


    C# Code: (my code which does not work)

    SisoImage sisoImage = SiSoCsRt.Fg_getImagePtrEx( data.fg, (int)( imgNr ), data.port, data.mem);

    IntPtr dataBuffer = sisoImage.asPtr();

    Image<Gray, Byte> imgToDisplay = new Image<Gray, Byte>( 512, 2048 );

    imgToDisplay.Ptr = dataBuffer;

    CvInvoke.imshow( "Display window raw", imgToDisplay);


    I also tried this to get a Bitmap but this also did not work as it is not able to convert the SisoImage type:

    Image img = (Bitmap)(new ImageConverter()).ConvertFrom(dataBuffer);


    Also, the SisoCsRt.DrawBuffer() is able to write images to the created display (i.e. SisoCsRt.CreateDisplay() ) but is it possible to draw directly to a panel object on a Form?

  • Here in the C# wrapper documentation it is mentioned that the void* type is changed to SisoImage.


    SisoImage.toByteArray(uint imageSize)


    The above function is mentioned at the end of the page, but will give you the byte array representation.

    Based on the byte array it should be possible to create a openCV Mat / Image without copy.

  • You are correct. I am using the Matrox Imaging Library (MIL) and was able to convert it to a MIL_ID format as well using this command:

    MIL.MbufPut( data.displayimg, sisoImage.toByteArray( DEFAULT_IMAGE_SIZE_X * DEFAULT_IMAGE_SIZE_Y ) );