PYQT Qlabel pixmap from PyCamera










0















I am working with a python multiprocessing program with three processes. The first one captures images from a pyCamera module, the second one is a GUI and the third one does some simple image processing. I am trying to show the current image taken by the camera in a Qlabel. I don't need to have more than 10 fps, it could be even as slow as 1fps. But every time I use setPixmap it looks like the updated image takes too long to show.



class Ui_MainWindow(QtWidgets.QMainWindow):

def __init__(self):
super(Ui_MainWindow,self).__init__()
uic.loadUi('/usr/local/bin/meltingPoints/GUI.ui',self)

#variables that contain the captured image
self.Gimage = mp.Array('B',768*1024*3,lock = mp.Lock())

#Image update timer
self.updateTimer = QtCore.QTimer()
self.updateTimer.timeout.connect(self.update_labels)
self.updateTimer.start(1000)

def update_labels(self):
#Reading the image from mp.Array
self.Gimage.acquire()
imageD = np.frombuffer(self.Gimage.get_obj(),dtype=np.uint8)
self.Gimage.release()

#Converting the image to Qimage
imageD.shape = [768,1024,3]
imageP = Image.fromarray(imageD[0:564,149:901,:].astype('uint8'), 'RGB')
imageQ = ImageQt(imageP.resize((400,300)))

#Setting Pixmap
self.imageDisplay.setPixmap(QtGui.QPixmap.fromImage(imageQ))

#Other simple label text updates go on after this


I do get an image in the Qlabel widget but instead of taking one second to update as the Timer configuration suggests, it takes about 5 seconds to show any change in the image. I have tried to use the OwnImageWidget shown here https://www.kurokesu.com/main/2016/08/01/opencv-usb-camera-widget-in-pyqt/ and it does update images on time, but the GUI gets unresponsive while the image update happens.



Any Ideas on what could be happening? I'll also include the function that captures the images (this function is called as a process in the main script and captures the image into two different multiprocessing arrays)



from time import sleep

import numpy as np
import picamera

def fotografo(Gimage,Oimage):
#Configuracion y encendido de la camara
with picamera.PiCamera() as camera:
#Fotos en blanco y negro
camera.color_effects = (128,128)
#Resolucion maxima
camera.resolution = (1024,768)
#Cambio de los parametros para fotos consistentes
camera.iso = 600
sleep(2)
camera.shutter_speed = camera.exposure_speed
camera.exposure_mode = 'off'
g = camera.awb_gains
camera.awb_mode = 'off'
camera.awb_gains = g

Pic = np.empty((768*1024*3), dtype = np.uint8)

while True:
camera.capture(Pic,'rgb')
Gimage[:] = Pic
Oimage[:] = Pic
sleep(0.25)


Thanks



unlucky_code










share|improve this question




























    0















    I am working with a python multiprocessing program with three processes. The first one captures images from a pyCamera module, the second one is a GUI and the third one does some simple image processing. I am trying to show the current image taken by the camera in a Qlabel. I don't need to have more than 10 fps, it could be even as slow as 1fps. But every time I use setPixmap it looks like the updated image takes too long to show.



    class Ui_MainWindow(QtWidgets.QMainWindow):

    def __init__(self):
    super(Ui_MainWindow,self).__init__()
    uic.loadUi('/usr/local/bin/meltingPoints/GUI.ui',self)

    #variables that contain the captured image
    self.Gimage = mp.Array('B',768*1024*3,lock = mp.Lock())

    #Image update timer
    self.updateTimer = QtCore.QTimer()
    self.updateTimer.timeout.connect(self.update_labels)
    self.updateTimer.start(1000)

    def update_labels(self):
    #Reading the image from mp.Array
    self.Gimage.acquire()
    imageD = np.frombuffer(self.Gimage.get_obj(),dtype=np.uint8)
    self.Gimage.release()

    #Converting the image to Qimage
    imageD.shape = [768,1024,3]
    imageP = Image.fromarray(imageD[0:564,149:901,:].astype('uint8'), 'RGB')
    imageQ = ImageQt(imageP.resize((400,300)))

    #Setting Pixmap
    self.imageDisplay.setPixmap(QtGui.QPixmap.fromImage(imageQ))

    #Other simple label text updates go on after this


    I do get an image in the Qlabel widget but instead of taking one second to update as the Timer configuration suggests, it takes about 5 seconds to show any change in the image. I have tried to use the OwnImageWidget shown here https://www.kurokesu.com/main/2016/08/01/opencv-usb-camera-widget-in-pyqt/ and it does update images on time, but the GUI gets unresponsive while the image update happens.



    Any Ideas on what could be happening? I'll also include the function that captures the images (this function is called as a process in the main script and captures the image into two different multiprocessing arrays)



    from time import sleep

    import numpy as np
    import picamera

    def fotografo(Gimage,Oimage):
    #Configuracion y encendido de la camara
    with picamera.PiCamera() as camera:
    #Fotos en blanco y negro
    camera.color_effects = (128,128)
    #Resolucion maxima
    camera.resolution = (1024,768)
    #Cambio de los parametros para fotos consistentes
    camera.iso = 600
    sleep(2)
    camera.shutter_speed = camera.exposure_speed
    camera.exposure_mode = 'off'
    g = camera.awb_gains
    camera.awb_mode = 'off'
    camera.awb_gains = g

    Pic = np.empty((768*1024*3), dtype = np.uint8)

    while True:
    camera.capture(Pic,'rgb')
    Gimage[:] = Pic
    Oimage[:] = Pic
    sleep(0.25)


    Thanks



    unlucky_code










    share|improve this question


























      0












      0








      0








      I am working with a python multiprocessing program with three processes. The first one captures images from a pyCamera module, the second one is a GUI and the third one does some simple image processing. I am trying to show the current image taken by the camera in a Qlabel. I don't need to have more than 10 fps, it could be even as slow as 1fps. But every time I use setPixmap it looks like the updated image takes too long to show.



      class Ui_MainWindow(QtWidgets.QMainWindow):

      def __init__(self):
      super(Ui_MainWindow,self).__init__()
      uic.loadUi('/usr/local/bin/meltingPoints/GUI.ui',self)

      #variables that contain the captured image
      self.Gimage = mp.Array('B',768*1024*3,lock = mp.Lock())

      #Image update timer
      self.updateTimer = QtCore.QTimer()
      self.updateTimer.timeout.connect(self.update_labels)
      self.updateTimer.start(1000)

      def update_labels(self):
      #Reading the image from mp.Array
      self.Gimage.acquire()
      imageD = np.frombuffer(self.Gimage.get_obj(),dtype=np.uint8)
      self.Gimage.release()

      #Converting the image to Qimage
      imageD.shape = [768,1024,3]
      imageP = Image.fromarray(imageD[0:564,149:901,:].astype('uint8'), 'RGB')
      imageQ = ImageQt(imageP.resize((400,300)))

      #Setting Pixmap
      self.imageDisplay.setPixmap(QtGui.QPixmap.fromImage(imageQ))

      #Other simple label text updates go on after this


      I do get an image in the Qlabel widget but instead of taking one second to update as the Timer configuration suggests, it takes about 5 seconds to show any change in the image. I have tried to use the OwnImageWidget shown here https://www.kurokesu.com/main/2016/08/01/opencv-usb-camera-widget-in-pyqt/ and it does update images on time, but the GUI gets unresponsive while the image update happens.



      Any Ideas on what could be happening? I'll also include the function that captures the images (this function is called as a process in the main script and captures the image into two different multiprocessing arrays)



      from time import sleep

      import numpy as np
      import picamera

      def fotografo(Gimage,Oimage):
      #Configuracion y encendido de la camara
      with picamera.PiCamera() as camera:
      #Fotos en blanco y negro
      camera.color_effects = (128,128)
      #Resolucion maxima
      camera.resolution = (1024,768)
      #Cambio de los parametros para fotos consistentes
      camera.iso = 600
      sleep(2)
      camera.shutter_speed = camera.exposure_speed
      camera.exposure_mode = 'off'
      g = camera.awb_gains
      camera.awb_mode = 'off'
      camera.awb_gains = g

      Pic = np.empty((768*1024*3), dtype = np.uint8)

      while True:
      camera.capture(Pic,'rgb')
      Gimage[:] = Pic
      Oimage[:] = Pic
      sleep(0.25)


      Thanks



      unlucky_code










      share|improve this question
















      I am working with a python multiprocessing program with three processes. The first one captures images from a pyCamera module, the second one is a GUI and the third one does some simple image processing. I am trying to show the current image taken by the camera in a Qlabel. I don't need to have more than 10 fps, it could be even as slow as 1fps. But every time I use setPixmap it looks like the updated image takes too long to show.



      class Ui_MainWindow(QtWidgets.QMainWindow):

      def __init__(self):
      super(Ui_MainWindow,self).__init__()
      uic.loadUi('/usr/local/bin/meltingPoints/GUI.ui',self)

      #variables that contain the captured image
      self.Gimage = mp.Array('B',768*1024*3,lock = mp.Lock())

      #Image update timer
      self.updateTimer = QtCore.QTimer()
      self.updateTimer.timeout.connect(self.update_labels)
      self.updateTimer.start(1000)

      def update_labels(self):
      #Reading the image from mp.Array
      self.Gimage.acquire()
      imageD = np.frombuffer(self.Gimage.get_obj(),dtype=np.uint8)
      self.Gimage.release()

      #Converting the image to Qimage
      imageD.shape = [768,1024,3]
      imageP = Image.fromarray(imageD[0:564,149:901,:].astype('uint8'), 'RGB')
      imageQ = ImageQt(imageP.resize((400,300)))

      #Setting Pixmap
      self.imageDisplay.setPixmap(QtGui.QPixmap.fromImage(imageQ))

      #Other simple label text updates go on after this


      I do get an image in the Qlabel widget but instead of taking one second to update as the Timer configuration suggests, it takes about 5 seconds to show any change in the image. I have tried to use the OwnImageWidget shown here https://www.kurokesu.com/main/2016/08/01/opencv-usb-camera-widget-in-pyqt/ and it does update images on time, but the GUI gets unresponsive while the image update happens.



      Any Ideas on what could be happening? I'll also include the function that captures the images (this function is called as a process in the main script and captures the image into two different multiprocessing arrays)



      from time import sleep

      import numpy as np
      import picamera

      def fotografo(Gimage,Oimage):
      #Configuracion y encendido de la camara
      with picamera.PiCamera() as camera:
      #Fotos en blanco y negro
      camera.color_effects = (128,128)
      #Resolucion maxima
      camera.resolution = (1024,768)
      #Cambio de los parametros para fotos consistentes
      camera.iso = 600
      sleep(2)
      camera.shutter_speed = camera.exposure_speed
      camera.exposure_mode = 'off'
      g = camera.awb_gains
      camera.awb_mode = 'off'
      camera.awb_gains = g

      Pic = np.empty((768*1024*3), dtype = np.uint8)

      while True:
      camera.capture(Pic,'rgb')
      Gimage[:] = Pic
      Oimage[:] = Pic
      sleep(0.25)


      Thanks



      unlucky_code







      pyqt5 qlabel qpixmap






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 13 '18 at 7:15







      Hugo Jiménez García

















      asked Nov 13 '18 at 7:08









      Hugo Jiménez GarcíaHugo Jiménez García

      13




      13






















          0






          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53275624%2fpyqt-qlabel-pixmap-from-pycamera%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53275624%2fpyqt-qlabel-pixmap-from-pycamera%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          這個網誌中的熱門文章

          How to read a connectionString WITH PROVIDER in .NET Core?

          In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

          Museum of Modern and Contemporary Art of Trento and Rovereto