pyqt5 QImage引发TypeError: arguments did not match any overloaded call:

前言:

博主之前的写的的pyqt5的代码,在进行bug优化时,突然就爆出TypeError: arguments did not match any overloaded call:错误。

一、完整的错误内容

    exec(code_obj, self.user_global_ns, self.user_ns)
  File "", line 1, in 
    Q_img = QImage(image,
TypeError: arguments did not match any overloaded call:
  QImage(): too many arguments
  QImage(QSize, QImage.Format): argument 1 has unexpected type 'numpy.ndarray'
  QImage(int, int, QImage.Format): argument 1 has unexpected type 'numpy.ndarray'
  QImage(bytes, int, int, QImage.Format): argument 1 has unexpected type 'numpy.ndarray'
  QImage(sip.voidptr, int, int, QImage.Format): argument 1 has unexpected type 'numpy.ndarray'
  QImage(bytes, int, int, int, QImage.Format): argument 1 has unexpected type 'numpy.ndarray'
  QImage(sip.voidptr, int, int, int, QImage.Format): argument 1 has unexpected type 'numpy.ndarray'
  QImage(List[str]): argument 1 has unexpected type 'numpy.ndarray'
  QImage(str, format: str = None): argument 1 has unexpected type 'numpy.ndarray'
  QImage(QImage): argument 1 has unexpected type 'numpy.ndarray'
  QImage(Any): too many arguments

pyqt5 QImage引发TypeError: arguments did not match any overloaded call:_第1张图片

报错的代码:

        if len(image.shape) == 3:
            Q_img = QImage(image.data,
                           image.shape[1],
                           image.shape[0],
                           image.shape[1] * 3,
                           QImage.Format_RGB888)

 

            Q_img = QImage(image,
                           image.shape[1],
                           image.shape[0],
                           image.shape[1] * 3,
                           QImage.Format_RGB888)

解决方法:

将要显示的image进行一个copy操作

        if len(image.shape) == 3:
            Q_img = QImage(image.copy(),
                           image.shape[1],
                           image.shape[0],
                           image.shape[1] * 3,
                           QImage.Format_RGB888)

你可能感兴趣的:(python,pycharm,开发语言)