質問

I am capturing camera frames from a DirectShow device and have a callback function which has the raw image bytes inside a buffer and hands it over to a widget.

This widget should be a QtOpenGL widget which contains the live image. (It should be rendered in OpenGL or another fast method)

Is there a way to display the raw image data with the QGLWidget or maybe another type like QSurface? All examples i've found and tried use commands (like glBegin) i'm not able to use because i use the Qt 5.1 version with ANGLE.

At least i'm able to display the image inside a QLabel with QImage (it's upside down but that was just first try to see if the buffer and callback function works).

役に立ちましたか?

解決

To display the image in a QLabel (not upside down):

ui->imageLabel->setPixmap(QPixmap::fromImage(img.mirrored(false, true)));

The problem here is that you are having the image in the GL/Windows format that Qt does not expect. Qt expects the X11 format, being a 180° rotated GL image.

But you could as well go ahead and use a QGLWidget where you draw a square and map the image as texture on it.

How it would work for OpenGL in a QGLWidget:

GLuint texture;
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, image_buffer);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glColor3f(1.0, 1.0, 1.0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glBegin(GL_TRIANGLE_STRIP);
glTexCoord2f(0, 0);
glVertex2f(-1, -1);
glTexCoord2f(1, 0);
glVertex2f(1, -1);
glTexCoord2f(0, 1);
glVertex2f(-1, 1);
glTexCoord2f(1, 1);
glVertex2f(1, 1);
glEnd();
glPopMatrix();
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top