Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to convert an OpenCV IplImage to an SDL_Surface?
    primarykey
    data
    text
    <p>I'm trying to write a program which takes an <code>SDL_Surface</code>, converts it to an <code>IplImage</code>, uses the cvBlobsLib to find blobs, paints the blobs as spots back over the image, then converts the output <code>IplImage</code> back to an <code>SDL_Surface</code>.</p> <p>I'm almost done: only converting the <code>IplImage</code> back to an <code>SDL_Surface</code> hasn't been done yet. This IplImage has 3 image channels and is 8 bits per pixel. I think I have two calls I can use:</p> <pre><code>SDL_Surface *SDL_CreateRGBSurface(Uint32 flags, int width, int height, int depth, Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask); SDL_Surface *SDL_CreateRGBSurfaceFrom(void *pixels, int width, int height, int depth, int pitch, Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask); </code></pre> <p>I'm currently trying with <code>SDL_CreateRGBsurfaceFrom</code>. I have no idea, however, what the correct values of pitch, Rmask, Gmask and Bmask are. (Amask is 0, because there is no alpha channel.)</p> <p>Could anybody help me out by explaining how to do this?</p> <p>Thanks!</p> <p><b>Edit</b>: For example, this is code I tried to use:</p> <pre><code>SDL_Surface *ipl_to_surface (IplImage *opencvimg) { int pitch = opencvimg-&gt;nChannels*opencvimg-&gt;width; printf("Depth %d, nChannels %d, pitch %d\n", opencvimg-&gt;depth, opencvimg-&gt;nChannels, pitch); SDL_Surface *surface = SDL_CreateRGBSurfaceFrom((void*)opencvimg-&gt;imageData, opencvimg-&gt;width, opencvimg-&gt;height, opencvimg-&gt;depth, pitch, 0x0000ff, 0x00ff00, 0xff0000, 0 ); return surface; } </code></pre> <p>(SDL Documentation writes "Pitch is the size of the scanline of the surface, in bytes, i.e. widthInPixels*bytesPerPixel.") This outputs "Depth 8, nChannels 3, pitch 1920" and displays a completely red image. I <em>think</em> a solution would be to convert my 8-bits image to 24-bits (1 byte per channel), but I don't know how to do that. Any ideas?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload