Results 1 to 8 of 8

Thread: firewire camera displaying problem from a new QTer

  1. #1
    Join Date
    Jan 2008
    Posts
    14
    Thanks
    5

    Question firewire camera displaying problem from a new QTer

    Hi All,

    I am new to Qt and I am using Qt4 to develop an application to display video from SONY iidc camera.

    Currently, I managed to show the image frames on a label's pixmap attribute. But, the speed of display is slow. Well, should be very slow - like 2frames/s. What I've actually done is:

    1. read the data from the camera to a unsignech char buffer.
    2. create a QImage object using that data
    3. create a QPixmap object using the above QImage
    4. Put is on the Label to display.

    Qt Code:
    1. //gray image 8-bit
    2. QImage *frameImage;
    3. QPixmap bPixmap;
    4. QBuffer buffer( &ba );
    5. // this is the data buffer from the firewire camera
    6. pImageBuff = (unsigned char *)iidc_lockdata(hCamera, -1);
    7. frameImage = new QImage(pImageBuff, iWidth, iHeight, QImage::Format_Indexed8);
    8. frameImage->setNumColors(256);
    9. for (int icol = 0; icol< 256; icol++){
    10. frameImage->setColor(icol, colorTableData[icol]);
    11. }
    12. buffer.open( IO_WriteOnly );
    13. frameImage->save( &buffer, "PNG" );
    14. bPixmap.loadFromData(ba);
    15. LabelCam1->setPixmap(bPixmap);
    16. LabelCam1->repaint();
    To copy to clipboard, switch view to plain text mode 

    Does anyone has any idea of speeding up this displaying thing? Or using other methods?

  2. #2
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: firewire camera displaying problem from a new QTer

    Hi,

    for (int icol = 0; icol< 256; icol++){[/font]
    frameImage->setColor(icol, colorTableData[icol]);[/font]
    You are using indexed color, but I'm sure that you are taking gray scale images, I'm right? so why you are filling the color index for every frame?
    Make a QImage pointer that will mantain the color index table and only set the image buffer to it.

    The other one:
    bPixmap.loadFromData(ba);
    You take the image buffer, load to a QImage and finally you don't use the QImage to QPixmap conversion that maybe will be faster than loading from data(the data is in the QImage yet).

    I had done this a little time ago and I used canvas instead of label. I don't know if the speed is better. You also could paint the image into a QGLWidget.
    Òscar Llarch i Galán

  3. The following user says thank you to ^NyAw^ for this useful post:

    Ran (14th January 2008)

  4. #3
    Join Date
    Jan 2008
    Posts
    14
    Thanks
    5

    Default Re: firewire camera displaying problem from a new QTer

    Thank you, NyAw!

    Quote Originally Posted by ^NyAw^ View Post
    You are using indexed color, but I'm sure that you are taking gray scale images, I'm right? so why you are filling the color index for every frame? Make a QImage pointer that will mantain the color index table and only set the image buffer to it.
    You are right. I am using gray scale images. I will try as you suggested!

    I am using QPainter's method drawImage to paint onto the window and looks faster now (not fast enough though). QGLWidget could be an alternative too, I will have a look! Thank you again.

    One more question: I found that during the period of my video show code is running, my mainwindow stops responding to event like menu click or even close. All you can do is to wait ... until video displaying part is completed. Am I doing something else wrong?

    My main.cpp is very simple like this.
    Qt Code:
    1. QApplication app(argc, argv);
    2.  
    3. firewireCamera mainWdn;
    4.  
    5. mainWdn.show();
    6.  
    7. return app.exec();
    To copy to clipboard, switch view to plain text mode 

  5. #4
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: firewire camera displaying problem from a new QTer

    Hi,

    Have you any Thread?
    In Qt applications there is the main Thread that is who controls the GUI, keyboard, mouse, ... the events.
    So you have to create a Thread that grabbs images from the camera and then send them by SIGNALs and SLOTs mechanism to the main thread who have to paint them.
    Òscar Llarch i Galán

  6. #5
    Join Date
    Jan 2008
    Posts
    14
    Thanks
    5

    Default Re: firewire camera displaying problem from a new QTer

    Thanks again NyAw, I think I have a main thread to control the running of the image capturing stuff. I guess that I should have something to check the status/event between each circle of capturing loop and do whatever it should do. In this way, my code could probably have some response to events. Am I on the right way?

  7. #6
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: firewire camera displaying problem from a new QTer

    Hi,

    Don't realy understand you.
    The main thread is that display GUI objects, take mouse and keyboard events, etc.. If you are going to capture the images from the main thread, this will be blocked to response this events untl your code has been executed. So, if grabbing an image takes very much time, all this time the application window will be frozen.
    Take a look at "mandelbrot" example in Qt examples. It makes a thread that do something and when the image is prepared to be shown, it is sended to the main thread that display it.
    Òscar Llarch i Galán

  8. #7
    Join Date
    Jan 2008
    Posts
    14
    Thanks
    5

    Default Re: firewire camera displaying problem from a new QTer

    Yes. I am trying to change my code into multi-threaded. One thing I don't understand is how to design a thread which shows its own Widget. I try to inherit a QWidget as well as a QThread. Obviously it failed. But if I want to show videos for from multi cameras at the same time in their own widget or child-window, how could I do that?

  9. #8
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: firewire camera displaying problem from a new QTer

    Hi,
    If you read about QThread you will see that the main thread is the only one who can do graphics(draw, paint, ...). So, taking the mandlebrot example you will see that the worker thread do something(load image, transform it, apply any filter,...) and then it sends a reference of the image to the main thread that will paint it on a Widget.

    So, create your own class inherited from QThread. This class is the class that will take the image of the camera and convert it to a QImage. Then, when the image will be a QImage, you can use "emit" to let the main thread take the image and paint it on a widget.
    Òscar Llarch i Galán

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.