'PyQt, with GigE camera feed crashes on window move/resize

I'm trying to create a GUI app that takes a video feed from a GigE Vision camera (a FLIR Blackfly) using the Spinnaker SDK and displays it on screen. This is what I have so far. It works until I try to drag or resize the window, at which point it crashes with no errors or debug messages at all. Help solving this would be much appreciated. Thanks!

import PySpin
import cv2
import sys
from PyQt5.QtWidgets import  QWidget, QLabel, QApplication
from PyQt5.QtCore import QThread, Qt, pyqtSignal, pyqtSlot
from PyQt5.QtGui import QImage, QPixmap

class Thread(QThread):
    changePixmap = pyqtSignal(QImage)

    def init_blackfly(self, cam_list, serial, ROI_y, ROI_x):
        cam = cam_list.GetBySerial(serial)
        
        #initializing the camera to make everything work
        cam.Init()

        #get sensor dimensions
        height = cam.HeightMax()
        width = cam.WidthMax()
        
        #calculate and apply ROI
        vertical_offset   = round( (height - ROI_y) / 2)
        horizontal_offset = round( (width  - ROI_x)  / 2)
        
        cam.Height.SetValue(ROI_y)
        cam.Width.SetValue(ROI_x)
        cam.OffsetY.SetValue(vertical_offset)
        cam.OffsetX.SetValue(horizontal_offset)
        
        #set the frame rate
        cam.AcquisitionFrameRateEnable.SetValue(True)
        cam.AcquisitionFrameRate.SetValue(60)
        
        #these parameters give inaccurate color, but increase dynamic range
        #start by exposure-compensating the image way down to capture the bright parts of the image
        cam.AutoExposureEVCompensation.SetValue(-2.0) 
        #compensate for the darker image by bumping the gamma
        cam.GammaEnable.SetValue(True)
        cam.Gamma.SetValue(0.5)
        #Enabe the image processor and set it to increase the saturation. The previous two steps reduce saturation
        cam.IspEnable.SetValue(True)
        cam.SaturationEnable.SetValue(True)
        cam.Saturation.SetValue(2)
        
        #reduce latency by changing the way buffers are handled. 
        cam.TLStream.StreamBufferHandlingMode.SetValue(PySpin.StreamBufferHandlingMode_NewestOnly)
        
        #grab new frames until stopped
        cam.AcquisitionMode.SetValue(PySpin.AcquisitionMode_Continuous)
        cam.BeginAcquisition()
        return cam

    def run(self):
        system = PySpin.System.GetInstance() #get the camera interface
        cam_list = system.GetCameras() #get the list of cameras
        
        cam = self.init_blackfly(cam_list, '13371337', 768, 1024)
        
        while True:
            frame_raw = cam.GetNextImage() #image directly from camera
            frame_col = frame_raw.Convert(PySpin.PixelFormat_BGR8, PySpin.HQ_LINEAR) #debayer the image

            frame_QT = QImage(frame_col.GetData(), 1024, 768, 3 * 1024, QImage.Format_BGR888) #convert the image into pyqt format
            self.changePixmap.emit(frame_QT)

class App(QWidget):
    def __init__(self):
        super().__init__()
        self.title = 'PyQt5 Video'
        self.left = 100
        self.top = 100
        self.width = 640
        self.height = 480
        self.initUI()

    @pyqtSlot(QImage)
    def setImage(self, image):
        self.label.setPixmap(QPixmap.fromImage(image))

    def initUI(self):
        self.setWindowTitle(self.title)
        self.setGeometry(self.left, self.top, self.width, self.height)
        self.resize(960, 540)
        # create a label
        self.label = QLabel(self)
        self.label.move(10, 10)
        self.label.resize(1024, 768)
        th = Thread(self)
        th.changePixmap.connect(self.setImage)
        th.start()
        self.show()
        
if __name__ == '__main__':
    app = QApplication(sys.argv)
    ex = App()
    sys.exit(app.exec_())```


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source