Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Using QThread to display live camera feed

Using QThread to display live camera feed

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 2.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    prerna1
    wrote on last edited by
    #1

    I am trying to write an application which takes frames from a web camera and displays them on screen. Since I will be processing the frames (using OpenCV, etc), I want to improve the speed of the application using threads. How can I do this? I believe it involves 2 steps: (i) fetching frames from the camera, and (ii) refreshing GUI to display them.

    1 Reply Last reply
    0
    • C Offline
      C Offline
      code_fodder
      wrote on last edited by
      #2

      Hi prerna,

      This is quite a broad question, so I will try to give a general answer:

      You can create separate threads using:
      @
      QThread* thread1 = new QThread;
      QThread* thread2 = new QThread;
      @

      You can move objects without parents into the threads using:
      @
      MyObj myObj = new MyObj(0); // 0 = no parent
      myObj->moveToThread(thread);
      @

      In your case, I am not sure how your project is setup, but you can create and put an "imageProcessing" object into a thread (e.g. called imageProcessingThread). Then to start that thread you can do the following to start it:

      @
      QObject::connect(imageProcessingThread, SIGNAL(started()), imageProcessing, SLOT(run()));
      thread->start();
      @

      Note: that once the object is moved into the thread you should not call members of the object directly from outside the thread. Only use sockets and slots to communicate to it from any other thread or from the main application thread. So you may have to pass in your image data via socket / slot etc...

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved