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. OpenCV VideoCapture Failure from QThread
Forum Updated to NodeBB v4.3 + New Features

OpenCV VideoCapture Failure from QThread

Scheduled Pinned Locked Moved Solved General and Desktop
opencvvideocaptureqthreadcrashgui
22 Posts 4 Posters 8.9k Views 2 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.
  • S Offline
    S Offline
    SGaist
    Lifetime Qt Champion
    wrote on 12 Nov 2019, 07:28 last edited by
    #21

    Hi,

    @rtavakko said in OpenCV VideoCapture Failure from QThread:

    void Display::updateImage(const uchar *imageData, int width, int height, int step)
    {
    if(imageData != nullptr)
    {
    displayImage = QImage(imageData, width, height, step, QImage::Format_RGBA8888);
    update();
    }
    }

    The constructor you are using does not make a copy of the data and you have to ensure that the lifetime of the buffer pointed to by imageData stays valid as long as the displayImage is.

    From the looks of it, you should either call copy so that displayImage doesn't depend on the lifetime of imageData or create imageData once with the right dimensions and use memcpy to transfer the data. Re-create displayImage if the size changes at some point.

    Interested in AI ? www.idiap.ch
    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

    1 Reply Last reply
    4
    • R Offline
      R Offline
      rtavakko
      wrote on 12 Nov 2019, 20:11 last edited by rtavakko
      #22

      @JKSH This is how I emit the OpenCV mat data:

      emit processedImage(2, videoFrameOut.ptr(0,0),videoFrameOut.cols, videoFrameOut.rows, videoFrameOut.step);
      

      The first parameter is just used to determine which display should draw the image and the rest are dimensions and stride which I think are ok.

      @SGaist You are correct, I changed the line below to make a copy:

      displayImage = QImage(imageData, width, height, step, QImage::Format_RGBA8888).copy(0,0,width,height);
      

      I think this fixed the issue. I got a couple of crashes in 'memcpy' but that was when loading files a little too quickly. I think most likey resizing the data quickly was the issue. I will do more testing this week and post the results.

      UPDATE: I did a lot more testing and making a local copy fixed the issue. The issue was that I was modifying the array before it was fully copied and this caused crashes when the array was downsized. I will need to revise the overall structure to make sure everything is done sequentially.

      Thanks!

      1 Reply Last reply
      0

      21/22

      12 Nov 2019, 07:28

      • Login

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