Page 1 of 2 12 LastLast
Results 1 to 20 of 29

Thread: Webcam Video Capture

  1. #1
    Join Date
    May 2011
    Location
    Indonesia, Surabaya
    Posts
    24
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Windows

    Default Webcam Video Capture

    Hello everybody..

    I'm new in Qt, and new in OpenCV..

    I want to make a program to capture a video from USB webcam, then save it to the server..

    For now, i have download a source code that use Qt and OpenCV to view images from webcam.. i download it here, http://qt-apps.org/content/show.php/...?content=89995

    do you have any suggestion, how should i modifiy this source code, so that it can record the video, and save it ?

    i really appreciate your help.. thanks before

    P.S : sorry for my bad english

  2. #2
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Webcam Video Capture

    do you have any suggestion
    Yes, read OpenCV documentation, for example:
    CvVideoWriter
    CvWriteFrame
    Post again if you have specific problems with your code.

  3. The following 2 users say thank you to stampede for this useful post:

    bajoelkid12 (5th May 2011), thaihoangluu (28th December 2011)

  4. #3
    Join Date
    May 2011
    Location
    Indonesia, Surabaya
    Posts
    24
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Webcam Video Capture

    thank you for your respond stampede.. i'm now working on how to integrate OpenCV video writing and reading function in Qt framework.. . maybe you have some advice ?

  5. #4
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Webcam Video Capture

    You mean you are having some problems with using OpenCv in your code, or just thinking how to do that nicely ? If its the latter, then I'd create a wrapper class(es) with nice interface, which will hide all the OpenCV stuff from client classes. What I mean is something like:
    Qt Code:
    1. class VideoReader : public QObject{
    2. Q_OBJECT
    3. public:
    4. VideoReader( const QString& file, QObject * parent = NULL );
    5. ... /// information
    6. int frameCount() const;
    7. QSize frameSize() const;
    8. ... // other methods, like video fps etc
    9. /// capture methods
    10. QImage getFrame( int frameNumber ) const; // or return QPixmap, or your own Image class
    11. ...
    12. };
    To copy to clipboard, switch view to plain text mode 
    It's always better to have class with good interface, than C-style OpenCv api calls all over the code. I think you get the idea.

  6. The following user says thank you to stampede for this useful post:

    bajoelkid12 (10th May 2011)

  7. #5
    Join Date
    May 2011
    Location
    Indonesia, Surabaya
    Posts
    24
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Webcam Video Capture

    actually yes.. i have some problems with using OpenCV in my code.. this is what i've done so far..

    mycamerawindow.cpp
    Qt Code:
    1. #include "MyCameraWindow.h"
    2.  
    3. MyCameraWindow::MyCameraWindow(CvCapture *cam, QWidget *parent) : QWidget(parent) {
    4. camera = cam;
    5. QVBoxLayout *layout = new QVBoxLayout;
    6. cvwidget = new QOpenCVWidget(this);
    7. layout->addWidget(cvwidget);
    8. setLayout(layout);
    9. resize(500, 400);
    10.  
    11. startTimer(100); // 0.1-second timer
    12. }
    13.  
    14. void MyCameraWindow::timerEvent(QTimerEvent*) {
    15. IplImage *image=cvQueryFrame(camera);
    16. cvwidget->putImage(image);
    17. }
    To copy to clipboard, switch view to plain text mode 

    i get this code from http://qt-apps.org/content/show.php/...?content=89995

    btw thank you for the algorithm, now i'll try to implement it to my code.. but if you don't mind, may i send my project file to you ?
    Last edited by bajoelkid12; 10th May 2011 at 06:17.

  8. #6
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Webcam Video Capture

    actually yes.. i have some problems with using OpenCV in my code..
    What kind of problems ? Image is not displayed ? Displayed but incorrect ? Other ?
    but if you don't mind, may i send my project file to you ?
    What for ? I think you can get all the help you need by asking specific questions on this forum.

  9. #7
    Join Date
    May 2011
    Location
    Indonesia, Surabaya
    Posts
    24
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Webcam Video Capture

    actually.. i don't know how to start it.. i'm new in programming.. new in Qt and OpenCV..i've think about some algorithm that i'll use in my work, it's somewhat like :

    1. Detect camera
    2. If there is a camera, then initialize the camera
    3. (the images from the camera are displayed)
    4. then there will be some buttons for recording, pause, and stop functions
    5. if the recording button is clicked, then save the recorded video into a spesific place and certain format.

    that's all, and i just don't know how to implement those algorithm into codes..i don't know how to write them.. actually, this is my first experience..

    Any advice Mr.Stampede ? i'm so sorry for the silly question from me..i really appreciate your help


    Added after 6 minutes:


    oh yes, for the basic need of integration (OpenCV2.2 and QtCreator 2010.05), i have read it here

    http://www.barbato.us/2011/03/18/usi...s-2/#more-1625

    now it's just "how to write the code" problems
    Last edited by bajoelkid12; 10th May 2011 at 12:02.

  10. #8
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Webcam Video Capture

    If you are new both to Qt and OpenCV, then in my opinion best for you would be to write some simple separate applications using Qt and OpenCV, and start combining the two when you gain some experience with those libraries.
    i'm new in programming..
    In that case, I'd start with basic C/C++ before trying to code using Qt.

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

    bajoelkid12 (10th May 2011)

  12. #9
    Join Date
    May 2011
    Location
    Indonesia, Surabaya
    Posts
    24
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Webcam Video Capture

    In that case, I'd start with basic C/C++ before trying to code using Qt
    Do you mean TURBO C++ application ? or there is anyother ?

  13. #10
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Webcam Video Capture

    Yes, there is standard C++.

    You can use Qt Creator to build C++ applications as well as Qt application. I would advise to learn C++ before Qt.

  14. #11
    Join Date
    May 2011
    Location
    Indonesia, Surabaya
    Posts
    24
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Webcam Video Capture

    hello guys, i'm a bit confused on how to understand a following code
    Qt Code:
    1. #include "QOpenCVWidget.h"
    2.  
    3. // Constructor
    4. QOpenCVWidget::QOpenCVWidget(QWidget *parent) : QWidget(parent) {
    5. layout = new QVBoxLayout;
    6. imagelabel = new QLabel;
    7. QImage dummy(100,100,QImage::Format_RGB32);
    8. image = dummy;
    9. layout->addWidget(imagelabel);
    10. for (int x = 0; x < 100; x ++) {
    11. for (int y =0; y < 100; y++) {
    12. image.setPixel(x,y,qRgb(x, y, y));
    13. }
    14. }
    15. imagelabel->setPixmap(QPixmap::fromImage(image));
    16.  
    17. setLayout(layout);
    18. }
    19.  
    20. QOpenCVWidget::~QOpenCVWidget(void) {
    21.  
    22. }
    23.  
    24. void QOpenCVWidget::putImage(IplImage *cvimage) {
    25. int cvIndex, cvLineStart;
    26. // switch between bit depths
    27. switch (cvimage->depth) {
    28. case IPL_DEPTH_8U:
    29. switch (cvimage->nChannels) {
    30. case 3:
    31. if ( (cvimage->width != image.width()) || (cvimage->height != image.height()) ) {
    32. QImage temp(cvimage->width, cvimage->height, QImage::Format_RGB32);
    33. image = temp;
    34. }
    35. cvIndex = 0; cvLineStart = 0;
    36. for (int y = 0; y < cvimage->height; y++) {
    37. unsigned char red,green,blue;
    38. cvIndex = cvLineStart;
    39. for (int x = 0; x < cvimage->width; x++) {
    40. // DO it
    41. red = cvimage->imageData[cvIndex+2];
    42. green = cvimage->imageData[cvIndex+1];
    43. blue = cvimage->imageData[cvIndex+0];
    44.  
    45. image.setPixel(x,y,qRgb(red, green, blue));
    46. cvIndex += 3;
    47. }
    48. cvLineStart += cvimage->widthStep;
    49. }
    50. break;
    51. default:
    52. printf("This number of channels is not supported\n");
    53. break;
    54. }
    55. break;
    56. default:
    57. printf("This type of IplImage is not implemented in QOpenCVWidget\n");
    58. break;
    59. }
    60. imagelabel->setPixmap(QPixmap::fromImage(image));
    61. }
    To copy to clipboard, switch view to plain text mode 

    Can you help me ?

  15. #12
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Webcam Video Capture

    Its quite a bit of code, with which part of it do you have trouble exactly?
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  16. #13
    Join Date
    May 2011
    Location
    Indonesia, Surabaya
    Posts
    24
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Webcam Video Capture

    thank you for the response.. .

    first of all, what is the function of this code in your opinion ?

    in my opinion, this code is to draw an image wrapped in Qimage, with RGB32 format.. but i don't know actually the drawing process based on that code.. .

  17. #14
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Webcam Video Capture

    in my opinion, this code is to draw an image wrapped in Qimage, with RGB32 format..
    yes, but not only, it seems to convert BGR to RGB as well.
    Qt Code:
    1. for (int x = 0; x < cvimage->width; x++) {
    2. // DO it
    3. red = cvimage->imageData[cvIndex+2];
    4. green = cvimage->imageData[cvIndex+1];
    5. blue = cvimage->imageData[cvIndex+0];
    6.  
    7. image.setPixel(x,y,qRgb(red, green, blue));
    8. cvIndex += 3;
    9. }
    To copy to clipboard, switch view to plain text mode 
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  18. The following user says thank you to high_flyer for this useful post:

    bajoelkid12 (24th May 2011)

  19. #15
    Join Date
    May 2011
    Location
    Indonesia, Surabaya
    Posts
    24
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Webcam Video Capture

    Hello guys, now i want to ask about video compression.. .is there any library that can support video compression method ? such as mpeg, or avi ? i'm using OpenCV2.2 right now. does it support video compression too ? thanks

  20. #16
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Webcam Video Capture

    Why do you ask it here?
    This is a Qt forum, not OpenCV froum.
    Try reading the OpenCV documentation first.
    http://opencv.willowgarage.com/wiki/VideoCodecs

    Ans ask OpenCV related question on their forum. you are more likely to get better answers there for OpenCV related questions.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  21. The following user says thank you to high_flyer for this useful post:

    bajoelkid12 (26th May 2011)

  22. #17
    Join Date
    May 2011
    Location
    Indonesia, Surabaya
    Posts
    24
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Webcam Video Capture

    hello guys.. now i want to ask, how to build a client - server application to transfer images that captured by webcam to another part of the network ? any suggestion ? thanks.. .

  23. #18
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Webcam Video Capture

    Maybe QNetworkAccessManager, or just plain old QTcpSocket, depending on what your server requires.

  24. The following user says thank you to squidge for this useful post:

    bajoelkid12 (30th May 2011)

  25. #19
    Join Date
    May 2011
    Location
    Indonesia, Surabaya
    Posts
    24
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Webcam Video Capture

    my server require to read the video stream that was sent by client.. .what do you suggest, QTcpSocket or QUdpSocket ? thank you

  26. #20
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Webcam Video Capture

    Which does your server support?

Similar Threads

  1. How to get video streaming from USB webcam
    By sanket.mehta in forum Qt Programming
    Replies: 4
    Last Post: 15th July 2011, 06:45
  2. capture iamge form webcam
    By bibhukalyana in forum Newbie
    Replies: 8
    Last Post: 29th April 2011, 09:43
  3. capture video from DV camera
    By ekkondela in forum Newbie
    Replies: 1
    Last Post: 7th March 2010, 09:38
  4. Replies: 3
    Last Post: 5th July 2009, 17:22
  5. synchronise QLabel display and webcam capture
    By fbmfbm in forum Qt Programming
    Replies: 2
    Last Post: 24th February 2009, 11:10

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.