Problems rendering an image in gtk - c++

I'm programming an application in c++ with a GUI in GTK3 that will show the images obtained from a genicam camera. I've got the official API of the camera that deals with it and extract returns an unsigned char* to the buffer where the image is contained.
The problem comes when I try to convert the image to a GTK format to render it in the GUI. I've tried with cairo and pixbuf, but I've problems in both of them, as the image is in MONO8 format, and pixbuf only deals with RGB. Cairo can deal with 8bit images, but only if they have an alpha channel, which is not the case.
Does someone know a way to approach this issue?
Thanks in advance

Related

Why is my Qt5 QPixmap not showing correctly frames processed with some OpenCV algorithms?

Thank you in advance for your support.
I am using OpenCV for processing video frames taken by a video camara, and showing the processed frames in a simple GUI implemented in Qt5. In the GUI, the images are shown using QPixmap in a label. The OpenCV algorithms should be right, since if I write the outputs are right, and they are basically some examples provided by OpenCV.
I have implemented different processings: For a conversion from color to grey scale, and for binary threshold (see image 1) the results are fine (this "view" of the camera is right). Nevertheless, when trying to display ("in real time") Keypoints detections (using SURF -see image 2-) and contours detections (using Canny -see image 3-), the images displayed are strange.
The main problem is they seem to be at the same time "much closer" (see 2) and double (see 3).
In the Qt code I am using:
ui->labelView->setScaledContents(true);
I do the conversion from the processed OpenCV frame to QImage using:
QImage output((const unsigned char*) _frameProcessed.data, _frameProcessed.cols, _frameProcessed.rows, QImage::Format_Indexed8);
And I display the image using:
ui->labelView->setPixmap(QPixmap::fromImage(frame));
The GUI and the OpenCV processing are running in different threads: I move the image processing to a thread in an initial setup.
If you needed further information please just let me know.
Thank you very much in advance!
Best regards,
As #Micka pointed out, it had to do with the formats of the images. I found this handy code providing functions for an automatic transformation between OpenCv and Qt formats.

WebRTC Video Renderer

We're busy trying to render the frames we get from WebRTC, but we are having problems showing the video correctly.
Does anyone have experience in this or is there an guide online that shows how to render frames from WebRTC in win32?
We are building out application in Visual Studio 2013. We used OpenGL for an previous attempt and we use Direct3D now, a guide with either is fine for us.
What's the problem exactly? It's just a block of I420 format pixel data.
With any YUV -> RGB conversion method(even WebRTC library provide one), remain work to do is just drawing RGB bitmap to a window.
In my personal experience, conversion was really fast, and drawing to the buffer(memory DC, backbuffer) was sufficiently fast. Only issue was actual screen presentation. For this, Direct2D was most convenient.

Imaging library to display yuv data in C++ and Qt

I was wondering is there any C++ imaging libraries so that I can take a yuv file and display it, I will be able to pass the resolution of the file and Ycbcr info(usually at 4:2:2) I need this to turn the yuv into jpegs if possible or to display it in rgb mode to be built on a QPixmap. If anyone could point me in the right direction I'd be most grateful.
I just looked around, did you tried the following ?
http://code.google.com/p/yuvtoolkit
http://code.google.com/p/yuvplayer

How to play a movie with alpha channel on Qt?

I'm trying to load and view a video with an alpha channel in Qt. The video was encoded using Quicktime Animation set to RGB + Alpha and Millions of Colors+. I'm sure the video has transparency working as I loaded it into After Effects and checked.
I tried using the Phonon module with no success. The video loads alright but without the alpha channel, it just shows a black background. I tried setting WA_TranslucentBackground attribute but that didn't work either. GIF is not an option since the graphics are quite complex.
Is there any way to do this?
I'm not sure if it's possible (don't know the export options for After Effects) but did you try converting the movie to the MNG format? Then you can load it with QMovie, and it supports alpha channel (may be quite heavy in size, though).
Maybe this link will help: http://www.libpng.org/pub/mng/mngapcv.html

C++ Spin Image Resources

Does anyone know of a good resource that will show me how to load an image with C++ and spin it?
What I mean by spin is to do an actual animation of the image rotating and not physically rotating the image and saving it.
If I am not clear on what I am asking, please ask for clarification before downvoting.
Thanks
I would definitely default to OpenGL for this type of task, you can load the image into a Texture, then either redraw the image at different angles, or better yet you can just spin the 'camera' in the OpenGL engine. There are loads of OpenGL tutorials around, a quick google search will get you everything you need.
You could use SDL and the extension sdl_image and/or sdl_gfx
In Windows using GDI+ you could show rotated image in the following way:
Graphics graphics( GetSafeHwnd() ); // initialize from window handle
// You can construct Image objects from a variety of
// file types including BMP, ICON, GIF, JPEG, Exif, PNG, TIFF, WMF, and EMF.
Image image( L"someimage.bmp" );
graphics.RotateTransform( 30.0f ); // 30 - angle, in degrees.
graphics.DrawImage( &image, 0, 0 ); // draw rotated image
You could read here more detailed explanation.
Second solution is to use DirectX. You could create texture from file and later render it. It is not trivial solution, but it'll use hardware acceleration and will give you the best performance.
On Windows 7 there is available new API called Direct2D. I have not used it yet, but it looks promising.
Direct2D provides Win32 developers with the ability to perform 2-D graphics rendering tasks with superior performance and visual quality.
i agree with DeusAduro. OpenGL is a good way of doing this.
you can also do this with Qt
The "roll-your-own" solution is difficult.
I'd suggest looking into WPF - it might have some nice options in an image control.