- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
考虑以下代码
from PyQt5.QtWidgets import QMainWindow, QLabel, QSizePolicy, QApplication
from PyQt5.QtGui import QPixmap, QImage
from PyQt5.QtCore import Qt
import numpy as np
import sys
class Test(QMainWindow):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
self.setGeometry(10,10,640, 400)
pixmap_label = QLabel()
pixmap_label.setSizePolicy(QSizePolicy.Ignored, QSizePolicy.Ignored)
pixmap_label.resize(640,400)
pixmap_label.setAlignment(Qt.AlignCenter)
im_np = np.ones((1800,2880,3),dtype=uint8)
im_np = np.transpose(im_np, (1,0,2))
qimage = QImage(im_np, im_np.shape[1], im_np.shape[0],
QImage.Format_RGB888)
pixmap = QPixmap(qimage)
pixmap = pixmap.scaled(640,400, Qt.KeepAspectRatio)
pixmap_label.setPixmap(pixmap)
self.setCentralWidget(pixmap_label)
self.show()
def main():
app = QApplication(sys.argv)
win = Test()
sys.exit(app.exec_())
if __name__=="__main__":
main()
我收到以下错误
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
根据this post这可能是由 numpy 创建 View 引起的。修改行
im_np = np.array(img)
im_np = np.transpose(im_np, (1,0,2))
至
im_np = np.array(img)
im_np = np.transpose(im_np, (1,0,2))
im_np_cpy = np.copy(im_np)
产生相同的错误。为了测试我没有通过 View ,我打印了测试结果
im_np_cpy.base is im_np
这是错误的。使用 cv2 可以正确显示图像。我显然错过了一些东西,知道什么吗?
干杯!
最佳答案
我在转置后添加了一个副本,如下所示:
im_np = np.transpose(im_np,(1,0,2)).copy()
这对我有用。
关于python - 来自 Numpy 数组的 PyQt5 QImage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48639185/
我正在寻找一种方法来简单地将一些Qimage粘贴到更大的图像中,从一些给定的(x,y)开始。现在,我正在逐像素复制所有Qimage。 最佳答案 QImage srcImage = QImage(100
我正在开发一个图像处理程序,当程序不断收到这些消息时,这里有一些示例,但我收到了数百条消息,以至于程序无法完全执行。 QImage::setPixel: coordinate (1043968,0)
我尝试将具有 RGB32 的 QImage 转换为具有 RGB24 的 QImage。我的代码在这种情况下不起作用: 当图片在BMP头中多出1024字节时,图片的大小为X*Y*3+54+未知的1024
我找到了类似的主题,但不是这个特定的主题。知道以下代码有什么问题吗?它返回'loaded=false',这显然意味着无法加载图像数据。 cv::Mat mymat; QImage qimg; myma
我创建了一个 Publisher 类,它定期发出 QImage 对象。 但是,我很难将 QImage 绘制到 QML 元素。 Image 和 Canvas QML 组件似乎需要 QUrl 而不是 QI
我是图形编程的新手(像素、图像等) 我正在尝试将原始数据转换为 QImage 并将其显示在 QLabel 上。问题是,原始数据可以是任何数据(它实际上不是图像原始数据,而是二进制文件。) 原因是,为了
是 QImage基于 QSharedData ?做 Qimage关注 pimpl或 copy on write ? 例如复制(通过复制骗局或分配)Qimage 会复制像素的深拷贝吗? 最佳答案 QIm
我正在调试一个巨大的 Qt 应用程序,其中包含数百个类、凌乱的代码等。在跟踪错误的同时,我想单步执行 gdb(kdbg、ddd 等等),同时观察使用 QPainter 绘制到 QImage 中的内容这
如何清除或清理 QIMage 我的以下方法获取对 QIMage 的常量引用。 MyMethod(const QImage & img) { // save it to a file img.s
我正在尝试将Format_Grayscale8图像转换为Format_ARGB32(或任何其他8bpp RGB格式)。我尝试使用QImage::convertToFormat和颜色表,但无法正常工作。
我正在使用 Qt 库创建 QImages。 我可以使用 this constructor : QImage image("example.jpg"); 但是我遇到了 this static funct
我知道 QImage 的高度和宽度,以及每个像素值(从 x、y 位置)。我如何构建一个知道这些值的 QImage? 最佳答案 setPixel() 的第二个参数是单个 int 中的 24 位 RGB
我正在开发用于编辑光栅图形的应用程序。在这个应用程序中,我必须创建扫描线函数,它与 QImage 类中的扫描线函数做同样的事情。但是我对扫描线函数的工作方式和一般的扫描线有点困惑。例如,当我为高度为
我的工作基于 this answer ,我正在尝试使用 Qt 的 QGLWidget 来呈现视频,但我遇到了一些问题。在我的视频解码线程中解码后立即保存帧时,结果很好: 但是当画出来的时候,它被严重破
我目前使用的是 Qt 5.12.3,在理解 QImage::pixel 函数的 10 位数字输出时遇到问题。对于此代码: QImage image; image.load("D:/qtProjects
我有一个简单的绘图应用程序,但是当我调整窗口大小时图像被删除,我想保留它。我尝试使用 image.scaled(current size) 但它不起作用。 qDebug() size(); QImag
我正在尝试显示 QImage在 QML 中,可能带有 Image .目前,我发现了类似 QQuickImageProvider 的内容,我实现并尝试使用,但没有成功。 我有QList我自己的对象( I
QImage具有以下构造函数: QImage(const QString &fileName, const char *format = nullptr); 但是,我正在尝试解析已作为字节数组加载的
我在我的 qt quick 应用程序中用相机捕获了一个图像。我想将路径发送到我的 c++ 代码并在 c++ QImage 中加载该图像。但是路径是 image://camera/preview_1 我
在我控制窗口的主类中,我有这个函数,其中 pixmapItem 是类头中定义的 QGraphicsPixmapItem*: void updateDisplay() { uchar *data
我是一名优秀的程序员,十分优秀!