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. How to use scrollArea to view camera video in PyQt4

How to use scrollArea to view camera video in PyQt4

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 1.1k 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.
  • R Offline
    R Offline
    robotsandi
    wrote on last edited by
    #1

    Hi
    I am new in Pyqt4, I design GUI in Qt and convert to pyqt4, now i want to use scroll Area to show camera view in the scroll area.
    this is my code to open camera in the new window.
    def init(self):
    self.capturing = False
    self.c = cv2.VideoCapture(0)

    def startCapture(self):
        print "pressed start"
        self.capturing = True
        cap = self.c
        while(self.capturing):
            ret, frame = cap.read()
            cv2.imshow("Capture", frame)
            cv2.waitKey(5)
        cv2.destroyAllWindows()
    

    Heare is my code to scrollArea design.
    self.scrollArea = QtGui.QScrollArea(self.centralWidget)
    self.scrollArea.setMouseTracking(True)
    self.scrollArea.setWidgetResizable(True)
    self.scrollArea.setObjectName(_fromUtf8("scrollArea"))
    self.scrollAreaWidgetContents = QtGui.QWidget()
    self.scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, 0, 363, 214))
    self.scrollAreaWidgetContents.setObjectName(_fromUtf8("scrollAreaWidgetContents"))

        self.scrollArea.setWidget(self.scrollAreaWidgetContents)
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      You are trying to mix two different GUI library here and that won't go as you expect even if OpenCV might use Qt as backend.

      You should rather convert the frames you capture to a QImage and use a QLabel to show them. Or you could consider using QtMultimedia if it fits your need, then there's no need for OpenCV.

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

      R 1 Reply Last reply
      2
      • SGaistS SGaist

        Hi,

        You are trying to mix two different GUI library here and that won't go as you expect even if OpenCV might use Qt as backend.

        You should rather convert the frames you capture to a QImage and use a QLabel to show them. Or you could consider using QtMultimedia if it fits your need, then there's no need for OpenCV.

        R Offline
        R Offline
        robotsandi
        wrote on last edited by
        #3

        @SGaist
        How can i use QtMultimedia in PyQt4.

        mrjjM 1 Reply Last reply
        0
        • R robotsandi

          @SGaist
          How can i use QtMultimedia in PyQt4.

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi
          Like any other Qt module,
          Something like

          import sys
          from PyQt5.QtWidgets import QApplication, QWidget
          from PyQt5.QtCore import QUrl
          from PyQt5 import QtMultimedia
          from qt_tools import key_text
          
          class Window(QWidget):
               def __init__(self):
                   super().__init__()
                   self.player = QtMultimedia.QMediaPlayer(self)
                   self.player.setMedia(QUrl.fromLocalFile("xxxxx"))     
                   self.show()
          
               def keyPressEvent(self, e):
                   key = key_text(e.key())
                   if key == "space":
                       print(self.player.errorString())
                       self.player.play()
          
          app = QApplication(sys.argv)
          window = Window()
          sys.exit(app.exec_())
          

          Note I do not use python :)
          Just used google to find sample.

          1 Reply Last reply
          1

          • Login

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