Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Unable to do multithreading on a Jetson Nano device, got error:QObject:startTimer
QtWS25 Last Chance

Unable to do multithreading on a Jetson Nano device, got error:QObject:startTimer

Scheduled Pinned Locked Moved Unsolved Qt for Python
10 Posts 3 Posters 1.0k Views
  • 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
    sweety_12
    wrote on last edited by
    #1

    Unable to do multithreading using ThreadPoolExecutor for OCR and Face recognition using python on Jetson Nano device and IMX219 camera. Using PyQT version 5.
    As we got error: “QObject:startTimer: Timers cannot be started from another thread”
    Can you help in resolving this issue?

    jsulmJ 1 Reply Last reply
    0
    • S sweety_12

      Unable to do multithreading using ThreadPoolExecutor for OCR and Face recognition using python on Jetson Nano device and IMX219 camera. Using PyQT version 5.
      As we got error: “QObject:startTimer: Timers cannot be started from another thread”
      Can you help in resolving this issue?

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @sweety_12 said in Unable to do multithreading on a Jetson Nano device, got error:QObject:startTimer:

      Can you help in resolving this issue?

      The error already tells you how to fix: start the timers in threads where they are living (do not start a timer from other thread than the thread where the timer was created or moved to).

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      S 1 Reply Last reply
      0
      • jsulmJ jsulm

        @sweety_12 said in Unable to do multithreading on a Jetson Nano device, got error:QObject:startTimer:

        Can you help in resolving this issue?

        The error already tells you how to fix: start the timers in threads where they are living (do not start a timer from other thread than the thread where the timer was created or moved to).

        S Offline
        S Offline
        sweety_12
        wrote on last edited by
        #3

        @jsulm can you please suggest an approach or give an example, how to handle this, tried multiple approaches but couldn't resolve

        jsulmJ 1 Reply Last reply
        0
        • S sweety_12

          @jsulm can you please suggest an approach or give an example, how to handle this, tried multiple approaches but couldn't resolve

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @sweety_12 You should rather show your code. You are handling threads wrongly.

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          S 1 Reply Last reply
          0
          • jsulmJ jsulm

            @sweety_12 You should rather show your code. You are handling threads wrongly.

            S Offline
            S Offline
            sweety_12
            wrote on last edited by
            #5

            @jsulm Thank you for your response

            from PyQt5 import QtCore

            frame_mutex = QtCore.QMutex()

            def process_frame(frame):
            frame_mutex.lock()
            # Create a ThreadPoolExecutor with 2 worker threads
            with concurrent.futures.ThreadPoolExecutor(max_workers=2) as executor:
            # Submit the OCR and face recognition tasks to the executor
            text_future = executor.submit(recognize_text, frame)
            face_future = executor.submit(recognize_face, frame)

                # Wait for both tasks to complete
                text_result = text_future.result()
                face_result = face_future.result()
            
                # Print the results
                print("Text recognition result:", text_result)
                print("Face recognition result:", face_result)
            frame_mutex.unlock()
            

            if name == "main":
            # Open the USB camera
            cap = cv2.VideoCapture("nvarguscamerasrc ! video/x-raw(memory:NVMM), width=(int)1280, height=(int)720, format=(string)NV12, framerate=(fraction)60/1 ! nvvidconv ! video/x-raw, format=(string)BGRx ! videoconvert ! appsink")

            while(True):
                # Capture frame-by-frame
                ret, frame = cap.read()
                process_frame(frame)
            
                frame_mutex.lock()
                # Display the resulting frame
                cv2.imshow('frame', frame)
                frame_mutex.unlock()
                if cv2.waitKey(1) & 0xFF == ord('q'):
                    break
            
            # Release the camera
            cap.release()
            cv2.destroyAllWindows()
            
            jsulmJ 1 Reply Last reply
            0
            • S sweety_12

              @jsulm Thank you for your response

              from PyQt5 import QtCore

              frame_mutex = QtCore.QMutex()

              def process_frame(frame):
              frame_mutex.lock()
              # Create a ThreadPoolExecutor with 2 worker threads
              with concurrent.futures.ThreadPoolExecutor(max_workers=2) as executor:
              # Submit the OCR and face recognition tasks to the executor
              text_future = executor.submit(recognize_text, frame)
              face_future = executor.submit(recognize_face, frame)

                  # Wait for both tasks to complete
                  text_result = text_future.result()
                  face_result = face_future.result()
              
                  # Print the results
                  print("Text recognition result:", text_result)
                  print("Face recognition result:", face_result)
              frame_mutex.unlock()
              

              if name == "main":
              # Open the USB camera
              cap = cv2.VideoCapture("nvarguscamerasrc ! video/x-raw(memory:NVMM), width=(int)1280, height=(int)720, format=(string)NV12, framerate=(fraction)60/1 ! nvvidconv ! video/x-raw, format=(string)BGRx ! videoconvert ! appsink")

              while(True):
                  # Capture frame-by-frame
                  ret, frame = cap.read()
                  process_frame(frame)
              
                  frame_mutex.lock()
                  # Display the resulting frame
                  cv2.imshow('frame', frame)
                  frame_mutex.unlock()
                  if cv2.waitKey(1) & 0xFF == ord('q'):
                      break
              
              # Release the camera
              cap.release()
              cv2.destroyAllWindows()
              
              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @sweety_12 Can you please formast the code properly? Especially in Python indentation is critical.

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              S 1 Reply Last reply
              1
              • jsulmJ jsulm

                @sweety_12 Can you please formast the code properly? Especially in Python indentation is critical.

                S Offline
                S Offline
                sweety_12
                wrote on last edited by
                #7

                @jsulm sorry for that the format got changed while pasting it

                from PyQt5 import QtCore
                
                frame_mutex = QtCore.QMutex()
                
                def process_frame(frame):
                   frame_mutex.lock()
                   # Create a ThreadPoolExecutor with 2 worker threads
                   with concurrent.futures.ThreadPoolExecutor(max_workers=2) as executor:
                    # Submit the OCR and face recognition tasks to the executor
                     text_future = executor.submit(recognize_text, frame)
                     face_future = executor.submit(recognize_face, frame)!
                    # Wait for both tasks to complete
                     text_result = text_future.result()
                     face_result = face_future.result()
                    # Print the results
                     print("Text recognition result:", text_result)
                     print("Face recognition result:", face_result)
                frame_mutex.unlock()
                if __name__ == "__main__":
                # Open the USB camera
                   cap = cv2.VideoCapture("nvarguscamerasrc ! video/x-raw(memory:NVMM), width=(int)1280, height=(int)720, format=(string)NV12, framerate=(fraction)60/1 ! nvvidconv ! video/x-raw, format=(string)BGRx ! videoconvert ! appsink")
                   while(True):
                      # Capture frame-by-frame
                         ret, frame = cap.read()
                         process_frame(frame)
                         frame_mutex.lock()
                       # Display the resulting frame
                         cv2.imshow('frame', frame)
                         frame_mutex.unlock()
                         if cv2.waitKey(1) & 0xFF == ord('q'):
                               break
                
                   # Release the camera
                   cap.release()
                   cv2.destroyAllWindows()
                
                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  Hi,

                  Why use QMutex ? There's nothing in that code that uses Qt directly.

                  Even more, the mutex does not make much sense since you are blocking process_frame to wait on the two futures.

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

                  S 1 Reply Last reply
                  1
                  • SGaistS SGaist

                    Hi,

                    Why use QMutex ? There's nothing in that code that uses Qt directly.

                    Even more, the mutex does not make much sense since you are blocking process_frame to wait on the two futures.

                    S Offline
                    S Offline
                    sweety_12
                    wrote on last edited by
                    #9

                    @SGaist Can you please suggest an alternative approach or give an example for this?

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

                      With your current implementation, you can drop the mutex.

                      Everything is done sequentially since you are explicitly waiting on the futures.

                      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