Displaying live video feed in openGL 2D
-
I am developing a application that will run only on a Windows 7 machine. It has a split screen with one half of the screen displays an interactive map and the other half displaying the live feed from a camera connected to the computer. I have used QCamera and that works fine. However the map used openGL. When I place buttons over the screen they are rendered differently over the map side than over the video side. I can't change the map side so I need to change the video side to use openGL so I can generate decent looking buttons. Plus any performance improvement that openGL might provide is a desired result.
I am recently new to Qt and C++ and completely new to any of the OpenGL applications. I really could use some example code of displaying video using OpenGL. The vast majority of example code I can find is primarily meant to show how to do 3D graphics programming. And those get caught up in the complexities of generating the objects that are being displayed. Even the 2D examples I have found is so difficult to understand I struggle and mostly just come away understanding less than before.
Any help is definitely appreciated.
-
I tried the following code:
@QByteArray cameraDevice = QCamera::availableDevices()[0];
camera = new QCamera(cameraDevice);QGraphicsScene *scene = new QGraphicsScene(); ui->cameraView->setScene(scene); QGraphicsVideoItem *item = new QGraphicsVideoItem(); camera->setViewfinder(item); ui->cameraView->scene()->addItem(item); ui->cameraView->show(); camera->start();@
cameraView in the ui is a QGraphicsView. I get the error
no video surface, cant start
-
Hi,
Let's go back to your original problem, to avoid the "XY Problem":http://meta.stackexchange.com/questions/66377/what-is-the-xy-problem
So, your root issue is that you can't get the buttons to display the same way on both sides. Can you post your code to show how you tried to do that?
-
I have developed a new solution for the video side. I am now using QGraphicsVideoItem and QGraphicsScene to show the video stream. So that will end up resolving the issue. The video itself is also behaving much better. I also resolved the button issue for now by not overlaying the graphics. They now have their own area at the bottom of the screen. This is not how I want it to end up but it demos much better.
This has created a rather nasty problem. Where the video and map worked appropriately before when using QCamera I now have a problem with performance. The new video works great. I even built a test application where I could place up to 4 instances of the video on a screen and they worked great. When I changed the real application to use the new video player it just doesn't work. The video is blank and the map does not have a steady movement. It will move for a few seconds then freeze for a few seconds before moving again.
I am trying to determine if there is a problem because I have two graphics processes competing for graphics resources or there is a problem with too much processing in the GUI thread. It only started when I changed to the new video player.
Is the first one even a possibility? I don't know how to make that determination. The mapping is being generated by a 3rd party API that I have little control over at that level.
I am in the process of attempting to split up my code so some of it can run in a separate thread. But I can't see that there is a lot I can split out that would really make a difference.
I can provide code but not sure what would help.
-
I have another forum thread regarding another aspect of this project. The issues have begun to merge into related problems. I will be using the other thread to discuss these issues. I appreciate all interest in helping get me through this project. That thread is "Here":http://qt-project.org/forums/viewthread/46241/
-
[quote] I also resolved the button issue for now by not overlaying the graphics. They now have their own area at the bottom of the screen. This is not how I want it to end up but it demos much better.
This has created a rather nasty problem. Where the video and map worked appropriately before when using QCamera I now have a problem with performance.[/quote]Since you are no longer attempting to overlay the buttons, would it be possible now to switch back to QCamera?[quote]Is the first one even a possibility? I don’t know how to make that determination. The mapping is being generated by a 3rd party API that I have little control over at that level.[/quote]I'm not sure. I don't have experience with OpenGL or video-within-QGraphicsView; everything I know so far is from reading basic theory.
If you'd still like help on the graphics performance issue, I recommend starting a new thread and posting a stripped-down version of your code that only contains the map display and the video display. (It's hard to tell what's going on based on high-level descriptions alone)
Good luck!