Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

memory leak on QtGui.QImage() #145

Open
hexxter opened this issue May 4, 2016 · 1 comment
Open

memory leak on QtGui.QImage() #145

hexxter opened this issue May 4, 2016 · 1 comment

Comments

@hexxter
Copy link

hexxter commented May 4, 2016

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
Copy link

ghost commented Apr 18, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant