Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Qt_Camera crash on Jetson Nano
Forum Updated to NodeBB v4.3 + New Features

Qt_Camera crash on Jetson Nano

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
21 Posts 2 Posters 2.7k 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
    Pranav_nc
    wrote on last edited by
    #7

    @SGaist ,

    My main intention for this example , I just want to capture video frame as a QImage.
    Once I have QImage then I want to do some processing on it and display.
    I went through the default camera example as I am new to QT GUI framework and not able to understand it completely .

    Also as you mentioned asynchronous I have added wait and signal and still I am facing same issue, please have a look at the below code:

    mainwindow.cpp:

    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include<qwindow.h>
    #include<qscreen.h>
    #include<iostream>
    #include<unistd.h>

    MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , stop(false),ui(new Ui::MainWindow)
    {
    ui->setupUi(this);
    mThread = new MyThread(this);
    m_camera = new QCamera;

    m_camera->setCaptureMode(QCamera::CaptureStillImage);
    
    QCameraViewfinder *viewfinder = new QCameraViewfinder;
    
    const QList<QCameraInfo> cameras = QCameraInfo::availableCameras();
    for (const QCameraInfo &cameraInfo : cameras)
        qDebug() << cameraInfo.deviceName();
    
    
    m_imageCapture = new QCameraImageCapture(m_camera);
    m_imageCapture->setCaptureDestination(QCameraImageCapture::CaptureToBuffer);
    m_camera->setViewfinder(viewfinder);
    connect(mThread, SIGNAL(valueChanged(int)),this, SLOT(onValueChanged(int)));
    QObject::connect(m_imageCapture, &QCameraImageCapture::imageCaptured, [=] (int id, QImage img) {
        std::cout<<"img.width"<<img.width()<<"img.height"<<img.height()<<std::endl;
        mThread->condition.wakeOne();
    
        processCapturedImage(id,img);
    
    });
    
    m_camera->start();
    mThread->start();
    

    }
    void MainWindow::onValueChanged(int count){

    std::cout<<"onValueChanged" <<std::endl;
    m_imageCapture->capture();
    mThread->condition.wakeOne();
    //    condition.wakeOne();
    qApp->processEvents();
    

    }
    MainWindow::~MainWindow()
    {
    delete ui;
    }
    //void MainWindow::displayCapturedImage()
    //{
    // //ui->stackedWidget->setCurrentIndex(1);
    //}

    void MainWindow::processCapturedImage(int requestId, const QImage& img)
    {
    Q_UNUSED(requestId);
    std::cout<<"after processCapturedImage"<<std::endl;
    auto pe1 = std::chrono::high_resolution_clock::now();
    QPixmap pixmap;
    QImage qimg = img.convertToFormat(QImage::Format_RGBA8888);
    pixmap = QPixmap::fromImage(qimg);
    ui->lastImagePreviewLabel_2->setPixmap(pixmap);
    ui->lastImagePreviewLabel_2->setScaledContents(true);
    ui->lastImagePreviewLabel_2->show();
    auto pe2 = std::chrono::high_resolution_clock::now();
    auto pe_duration = std::chrono::duration_caststd::chrono::microseconds( pe2 - pe1).count() / 1000;
    std::cout<<"latency read "<<pe_duration<<std::endl;

    }
    void MainWindow::on_pushButton_clicked()
    {

    mThread->Stop=false;
    mThread->condition.wakeOne();
    

    }

    void MainWindow::on_pushButton_2_clicked()
    {
    mThread->Stop=true;
    }

    mythread.cpp:

    #include "mythread.h"
    #include <QDebug>
    #include<QMutex>
    #include<iostream>
    MyThread::MyThread(QObject *parent, bool b) :
    QThread(parent), Stop(b)
    {
    }

    // run() will be called when a thread starts
    void MyThread::run()
    {
    for(;;)
    {
    std::cout<<" mythread "<<std::endl;
    mutex.lock();

        condition.wait(&mutex);
        std::cout<<" mythread "<<std::endl;
        if(this->Stop) {
            this->Stop=false;
    
            mutex.unlock();
            condition.wait(&mutex);
           // break;
        }
        emit valueChanged(0);
    
        mutex.unlock();
    
        //condition.wakeOne();
        // slowdown the count change, msec
        this->msleep(30);
    }
    

    }

    main.cpp:

    #include "mainwindow.h"
    #include<iostream>
    #include <QApplication>

    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);
    MainWindow w;
    w.show();
    return a.exec();

    }

    1 Reply Last reply
    0
    • P Offline
      P Offline
      Pranav_nc
      wrote on last edited by Pranav_nc
      #8

      @SGaist ,

      Further I have modified code a little bit and make sure the code has implemented in asynchronous , I didn't see the earlier warning message "CameraBin warning: "Resource busy or not available."", but still I am seeing the same segfault issue.

      Please help me to resolve thiis issue

      Here is the Gstreamer debug messages:

      available for media type: application/x-gst-av-webp
      77 0:00:00.067371505 19108 0x3da392d0 WARN default descriptions.c:1229:gst_pb_utils_get_codec_description: No description available for media type: application/x-gst-av-wtv
      78 0:00:00.067440256 19108 0x3da392d0 WARN default descriptions.c:743:format_info_get_desc: Unexpected MPEG-1 layer in au dio/mpeg, mpegversion=(int)1
      79 0:00:00.136766277 19108 0x3da392d0 WARN GST_ELEMENT_FACTORY gstelementfactory.c:456:gst_element_factory_make: no such element fact ory "vaapisink"!
      80 0:00:00.142514305 19108 0x3da392d0 WARN GST_ELEMENT_FACTORY gstelementfactory.c:456:gst_element_factory_make: no such element fact ory "vaapisink"!
      81 "/dev/video0"
      82 mythread
      83 0:00:00.528898667 19108 0x3df0cb20 FIXME default gstutils.c:3981:gst_pad_create_stream_id_internal:preview-appsrc:src Creating random stream-id, consider implementing a deterministic way of creating a stream-id
      84 mythread
      85 mythread
      86 onValueChanged
      Segmentation fault (core dumped)

      Thanks in Advance,

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #9

        Can you run your application through the debugger and show the back trace ?

        In any case, your use of synchronisation primitive and threading is just adding complexity for nothing and adds another layer of issues.

        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
        1
        • P Offline
          P Offline
          Pranav_nc
          wrote on last edited by
          #10

          Hi @SGaist ,

          Somehow I was failed to run remote machine using qt-creator and I didn't get the back trace.
          When I run application using gdb on target platform I got only above call stack which I mentioned below as well.

          backtrace:

          Thread 10 "queue5:src" received signal SIGSEGV, Segmentation fault.
          [Switching to Thread 0x7fa8cce130 (LWP 14841)]
          0x0000007fb01f8cbc in gst_memory_unmap () from /usr/lib/aarch64-linux-gnu/libgstreamer-1.0.so.0
          (gdb) bt
          #0 0x0000007fb01f8cbc in gst_memory_unmap () at /usr/lib/aarch64-linux-gnu/libgstreamer-1.0.so.0
          #1 0x0000007fa98df0b8 in () at /usr/lib/aarch64-linux-gnu/gstreamer-1.0/libgstnvjpeg.so
          #2 0x0000000000a15550 in ()
          (gdb)

          Also I have notice another issue, when I configure the QCameraImageCapture as a CaptureToBuffer, why this capture evening saving the image(.jpg) file on to disk location(Pictures folder ).

          To check further I put some prints and its showing expected output .

          qDebug() << m_imageCapture->isCaptureDestinationSupported(QCameraImageCapture::CaptureToFile);
          qDebug() << m_imageCapture->isCaptureDestinationSupported(QCameraImageCapture::CaptureToBuffer);
          m_imageCapture->setCaptureDestination(QCameraImageCapture::CaptureToBuffer);
          qDebug() << m_imageCapture->captureDestination();

          true
          true
          QFlags(0x2)

          Kindly help me why jpg files are saving and how to stop it?

          Thanks, in advance,

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #11

            Can you check the example shown here ?

            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
            0
            • P Offline
              P Offline
              Pranav_nc
              wrote on last edited by
              #12

              Hi @SGaist ,

              Thanks for you quick reply on this issue .

              Here is my observations please kindly check.

              Suggested example is working fine on x86 machine, but it comes to hardware platform I still see a segfault and first frame itself the application crash.

              Thread 11 "queue5:src" received signal SIGSEGV, Segmentation fault.
              [Switching to Thread 0x7fa8d74130 (LWP 16081)]
              0x0000007fb0170cbc in gst_memory_unmap () from /usr/lib/aarch64-linux-gnu/libgstreamer-1.0.so.0
              (gdb) bt
              #0 0x0000007fb0170cbc in gst_memory_unmap () at /usr/lib/aarch64-linux-gnu/libgstreamer-1.0.so.0
              #1 0x0000007fa98dc0b8 in () at /usr/lib/aarch64-linux-gnu/gstreamer-1.0/libgstnvjpeg.so
              #2 0x0000000000a13910 in ()

              Example:

              mainwindow.cpp:

              #include "ui_mainwindow.h"
              #include "mainwindow.h"
              MainWindow::MainWindow(QWidget *parent)
              : QMainWindow(parent)
              , ui(new Ui::MainWindow)
              {
              ui->setupUi(this);

              QCamera *cam = new QCamera;
              
              cam->setCaptureMode(QCamera::CaptureStillImage);
              
              QCameraViewfinder *viewfinder = new QCameraViewfinder;
              
              viewfinder->show();
              
              QCameraImageCapture *cap = new QCameraImageCapture(cam);
              cap->setCaptureDestination(QCameraImageCapture::CaptureToBuffer);
              
              cam->setViewfinder(viewfinder);
              
              QObject::connect(cap, &QCameraImageCapture::imageCaptured, [=] (int id, QImage img) {
                  QByteArray buf;
                  QBuffer buffer(&buf);
                  buffer.open(QIODevice::WriteOnly);
                  img.save(&buffer, "PNG");
              });
              
              QObject::connect(cap, &QCameraImageCapture::readyForCaptureChanged, [=] (bool state) {
                 if(state == true) {
                     cam->searchAndLock();
                     cap->capture();
                     cam->unlock();
                 }
              });
              
              cam->start();
              

              }

              MainWindow::~MainWindow()
              {
              delete ui;
              }

              main.cpp:

              #include "mainwindow.h"

              #include <QApplication>

              int main(int argc, char *argv[])
              {
              QApplication a(argc, argv);
              MainWindow w;
              //w.show();
              return a.exec();
              }

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #13

                Which Linux distribution are your running on your target ?

                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
                0
                • P Offline
                  P Offline
                  Pranav_nc
                  wrote on last edited by
                  #14

                  Hi @SGaist ,

                  I am not sure how to get that details, but from dmesg command I could see below message

                  Here is my Linux details ,

                  Linux version 4.9.140-tegra (buildbrain@mobile-u64-2713) (gcc version 7.3.1 20180425 [linaro-7.3-2018.05 revision d29120a424ecfbc167ef90065c0eeb7f91977701] (Linaro GCC 7.3-2018.05) ) #1 SMP PREEMPT Mon Dec 9 22:47:42 PST 2019

                  Thanks in Advance,

                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #15

                    What does "uname -a" return ?

                    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
                    0
                    • P Offline
                      P Offline
                      Pranav_nc
                      wrote on last edited by
                      #16

                      @SGaist said in Qt_Camera crash on Jetson Nano:

                      uname -a
                      Linux nanoboard-1 4.9.140-tegra #1 SMP PREEMPT Mon Dec 9 22:47:42 PST 2019 aarch64 aarch64 aarch64 GNU/Linux

                      1 Reply Last reply
                      0
                      • P Offline
                        P Offline
                        Pranav_nc
                        wrote on last edited by Pranav_nc
                        #17

                        @SGaist ,

                        One more quick update from end is, now I am able to run the above example without crash. But again I stuck with same core problem where I want to read continuous frames from camera and do process on it.

                        The crash is happening due to below issue:
                        https://forums.developer.nvidia.com/t/mjpeg-patch-makes-jpegdec-segfault/119810

                        The example which you pointed here, with that also image file has creating every capture call

                        Thanks in Advance,

                        1 Reply Last reply
                        0
                        • P Offline
                          P Offline
                          Pranav_nc
                          wrote on last edited by Pranav_nc
                          #18

                          Hi @SGaist ,

                          As per my understanding right, reading frame from camera is very basic operation any one can expect from QT camera API.

                          From one week I am working on this and I feel so difficult for reading frame using QCamera API.
                          I have been working with OpenCV its so straightforward
                          Looks like am I missing something ? Please kindly help on this.

                          Thanks in Advance,

                          1 Reply Last reply
                          0
                          • SGaistS Offline
                            SGaistS Offline
                            SGaist
                            Lifetime Qt Champion
                            wrote on last edited by
                            #19

                            Qt uses GStreamer on Linux. If GStreamer has an issue, Qt can't do miracles.

                            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
                            0
                            • P Offline
                              P Offline
                              Pranav_nc
                              wrote on last edited by
                              #20

                              @SGaist ,

                              Thanks for the information, is there any API by which I can access the Qimage other than capture API?
                              Because capture is doing both the things in my case, file saving and filling same data into Qimage object.
                              As we know right performance and memory consumption will affect due to file writes.

                              Thanks in advance,

                              1 Reply Last reply
                              0
                              • SGaistS Offline
                                SGaistS Offline
                                SGaist
                                Lifetime Qt Champion
                                wrote on last edited by
                                #21

                                You said that you had it working the way you wanted with OpenCV. You can easily use it from Qt.

                                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
                                0

                                • Login

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