Results 1 to 9 of 9

Thread: Display the camera frame in real time

  1. #1
    Join Date
    Jul 2007
    Posts
    5
    Thanks
    3

    Default Display the camera frame in real time

    I use a FireWire-Camera and i want to display the frame in real time (15 ~ 30fps) by Qt. I have tried to display it by QGraphicsview, e.g.:
    Qt Code:
    1. graphicsview->scene()->addPixmap(pixmap);
    To copy to clipboard, switch view to plain text mode 
    But it is too slow. And i have tried to use "setBackgroundBrush", e.g.:
    Qt Code:
    1. graphicsview->scene()->setBackgroundBrush(QBrush::QBrush(qimage));
    To copy to clipboard, switch view to plain text mode 
    This is faster, but not real time.
    Can anyone tell me some advices how to solve the tempo problem?

    Thanks!

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Display the camera frame in real time

    I think someone tried this before...
    How do you acquire the frames in the GUI thread? Do you have a separate thread that communicates with the camera?
    Perhaps the communication between the worker thread and the GUI can be improved...

    If you can post the code for this part, the do it.

    Regards

  3. #3
    Join Date
    Jul 2007
    Posts
    5
    Thanks
    3

    Default Re: Display the camera frame in real time

    Here is my code:

    Qt Code:
    1. QImage camImage;
    2. ........
    3. .......
    4. // Loop ...
    5. while(camSwitch != false)
    6. {
    7. // Wait 5000 MillSeconds for a frame
    8. if(Ret == FCE_NOERROR)
    9. Ret = FGGetFrame(hCamera, &Frame, 5000);
    10.  
    11. if(Ret == FCE_NOERROR)
    12. Ret = FGPutFrame(hCamera, &Frame);
    13.  
    14. cvNamedWindow("1", CV_WINDOW_AUTOSIZE);
    15.  
    16. camImage = QImage::QImage(Frame.pData, 640, 480, QImage::Format_Indexed8);
    17. camImage.setColorTable(grayscales);
    18.  
    19. Display->scene()->setBackgroundBrush(QBrush::QBrush(camImage));
    20. Display->fitInView(0,0,640,480);
    21. cvWaitKey(50);
    22. }
    To copy to clipboard, switch view to plain text mode 

    Frame.pData is the real time frame with type unsigned char *
    Line 14 & 21 are 2 functions of OpenCv(I hope you know that.) Line 14 made a new window. And line 21 ist a wait function. When i don't use these 2 functions, the program run to crash. This is comic.
    Display is the object of QGraphicsview. Although i have set up the size of Display in 640*480 in QtDesigner, but wenn i don't use fitInView(0,0,640,480), the frame is not displayed automatically. So i have to use fitInView.
    Have i too many error?

    Thanks!

  4. #4
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Display the camera frame in real time

    Probably the delay is because you fetch the frames in the GUI thread.
    The camera interface may give you the frames in real time, but displaying them is not done in real time.

    I suggest using a worker thread(producer) to fetch and store frames in a buffer. The GUI thread just takes out the frames as it needs to display them. This way (hopefully) no delay will be noticed.

    Regards

  5. The following user says thank you to marcel for this useful post:

    alex_lue (27th July 2007)

  6. #5
    Join Date
    Jul 2007
    Posts
    5
    Thanks
    3

    Default Re: Display the camera frame in real time

    Thank you for your fast reply.

    Do you mean i should use QThread or QBuffer?? Is there other method to display the fram? (e.g.: QImage or QPixmap)?

  7. #6
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Display the camera frame in real time

    I think QImage is OK.
    You should use a QThread that will only acquire camera frames and store them somewhere( a data structure you find suitable, even QBuffer, but you should research a bit the speed ).

    The location in which you store the frames must be accessible to the GUI thread.(maybe a getter in the worker thread?, or a static object - not recommended, since you only have to threads)

    The GUI thread just has to read the worker thread's frame store.

    Regards

  8. The following user says thank you to marcel for this useful post:

    alex_lue (27th July 2007)

  9. #7
    Join Date
    Jul 2007
    Posts
    5
    Thanks
    3

    Default Re: Display the camera frame in real time

    I have only a little experiences to use Multithreading. Is there also in Qt such function as _beginthread(....) in VC++ 6.0? Or must i new define an object von QThread ?

  10. #8
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Display the camera frame in real time

    Threads in Qt are really easy to use.

    See first the QThread documentation. You can also learn a lot from the Qt Examples.

    You will have to subclass QThread and reimplement the run() method.
    You should have a loop there that acquires frames and puts them in the buffer.

    To start a thread just call its start() method.

    Regards

  11. The following user says thank you to marcel for this useful post:

    alex_lue (27th July 2007)

  12. #9
    Join Date
    Jul 2007
    Posts
    5
    Thanks
    3

    Default Re: Display the camera frame in real time

    I try to write.
    Thanks.

Similar Threads

  1. Displaying real time images
    By Sheetal in forum Qt Programming
    Replies: 9
    Last Post: 22nd February 2007, 12:29

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.