pyside / PySide

ATTENTION: This project is deprecated, please refer to PySide2
https://wiki.qt.io/PySide2
GNU Lesser General Public License v2.1
291 stars 66 forks source link

memory leak on QtGui.QImage() #145

Open hexxter opened 8 years ago

hexxter commented 8 years ago

I get an frame from the cam and convert it to an QImage. This produce a memory leak. First i mean it is a problem with the QLabel (#144 closed issue) but its a problem with the QImage.

i found this: https://bugreports.qt.io/browse/PYSIDE-140 is this the same?

Info: Python3.4.3 virtualenv host: ubuntu 14.04 64bit

from PyV4L2Camera.camera import Camera
import time
import numpy
from PIL import Image
from PySide import QtGui

camera = Camera('/dev/video2')

while True:
    frame = camera.get_frame()

    # Decode the image
    dim = Image.frombytes('RGB', (camera.width, camera.height), frame, 'raw', 'RGB')

    # Convert the image to a numpy array and back to the pillow image
    arr = numpy.asarray(dim)
    im = Image.fromarray(numpy.uint8(arr))

    data = im.convert("RGBA").tostring("raw", "BGRA")

    size = im.size

    image = QtGui.QImage(data, size[0], size[1], QtGui.QImage.Format_ARGB32)

    time.sleep( 0.1 )

for simpler test you can use a picture as source...

ghost commented 6 years ago

Temporary workaround for this problem is to use:

status, buf = cv.imencode('.ppm', frame)
pixmap = QPixmap()
pixmap.loadFromData(buf.tostring())
qlbl.setPixmap(pixmap)

Where frame is a 3 channel numpy array / opencv image I checked and ppm encoding seems to have the lower encoding time