我正在寻找一种方法来创建可以拖/放以重新排列顺序的图形网格。我的第一次尝试是使用 QDockWidgets,因为它们允许拖放,但是它们在很多其他方面受到限制。是否可以在 QGridLayout 中实现此功能?
现在我有一个带有 3x3 matplotlib 小部件的 QGridLayout。
这是所需布局结果的示例。
示例代码:
import sys
from PyQt5 import QtWidgets
from matplotlib.figure import Figure
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
import random
from PyQt5.QtWidgets import QGridLayout, QVBoxLayout, QHBoxLayout, QScrollArea, QWidget, QDialog, QApplication, QFrame
class IndicSelectWindow(QDialog):
def __init__(self, parent=None):
super(IndicSelectWindow, self).__init__(parent=parent)
self.resize(1000, 800)
self.layout = QtWidgets.QHBoxLayout(self)
self.scrollArea = QScrollArea(self)
self.scrollArea.setWidgetResizable(True)
self.scrollAreaWidgetContents = QWidget()
self.gridLayout = QGridLayout(self.scrollAreaWidgetContents)
self.scrollArea.setWidget(self.scrollAreaWidgetContents)
self.layout.addWidget(self.scrollArea)
for i in range(3):
for j in range(3):
self.Frame = QFrame(self)
self.Frame.setStyleSheet("background-color: white;")
self.Frame.setFrameStyle(QFrame.Panel | QFrame.Raised) …Run Code Online (Sandbox Code Playgroud) 我想根据 15 FPS 的帧速率更新 Qtimer - 所以我的 def update(): 每 0,06 秒接收一个信号。你能帮助我吗?我在下面附加了一个代码示例,其中我的 setInterval 输入是 1/15,但我不知道这是否是正确的方法。谢谢。
from PyQt5 import QtCore
def update():
print('hey')
fps = 15
timer = QtCore.QTimer()
timer.timeout.connect(update)
timer.setInterval(1/fps)
timer.start()
Run Code Online (Sandbox Code Playgroud) 我试图找到与大量其他图像(+10.000)最接近的图像匹配。背景颜色全白色,相同的拍摄角度,图像内容形状彼此接近(见下图)。我尝试使用opencvandORB和BFMatcherwithknnMatch来找到最接近的匹配。但我还没有找到我想要的比赛。
据我理解,图像需要是灰度的,但就我而言,我认为颜色是一个非常重要的描述符?
我对 opencv 和图像匹配都很陌生,所以如果我需要使用其他方法,你能帮助我吗?
import cv2
import os
orb = cv2.ORB_create(nfeatures=1000) # Find 1000 features to match from
bf = cv2.BFMatcher()
# Image to match
findImg = 'captainA.png'
imgCur = cv2.imread(f'{"Images"}/{findImg}', 0)
kp1,des1 = orb.detectAndCompute(imgCur,None)
# Loop through all superheroe images and find closest match
images = ["img1.png","img2.png","img3.png","img4.png","img5.png","img6.png","img7.png","img8.png","img9.png","img10.png","img11.png","img12.png"]
matchList = []
names = []
for img in images:
imgCur = cv2.imread(f'{Superheroes}/{img}', 0)
kp2,des2 = orb.detectAndCompute(imgCur,None)
matches = bf.knnMatch(des1,des2,k=2)
goodMatches = [] …Run Code Online (Sandbox Code Playgroud) python opencv classification computer-vision object-recognition
我想将一个 QPixmap 放在另一个 QPixmap 上。两者的大小相同,所以我只想制作一个叠加层。叠加图像中间有一个透明的椭圆。我认为它们应该是 QPixmap 格式,但是我不知道如何将它们放置在彼此之上并在调整窗口大小时将它们保持在适当的位置。这是我的代码,显示了背景图像的放置方式。我附上了一张图片来解释我想要什么。
import sys
from PyQt5 import QtGui ,QtWidgets, uic
from PyQt5.QtCore import Qt
class Ergolab(QtWidgets.QMainWindow):
def __init__(self, *args, **kwargs):
super(Ergolab, self).__init__(*args, **kwargs)
# Load the UI Page
self.ui = uic.loadUi("mainwindow.ui",self)
self.pixmap1 = QtGui.QPixmap('C:/Users/Frede/Desktop/img1.jpg')
self.shoflexLLabel.setPixmap(self.pixmap1.scaled(self.shoflexLLabel.size(), Qt.KeepAspectRatio, Qt.SmoothTransformation))
self.shoflexLLabel.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
self.shoflexLLabel.setMinimumSize(150, 150)
self.shoflexLLabel.resize(800, 600)
self.pixmap2 = QtGui.QPixmap('C:/Users/Frede/Desktop/img2.jpg')
self.shoflexRLabel.setPixmap(self.pixmap2.scaled(self.shoflexRLabel.size(), Qt.KeepAspectRatio, Qt.SmoothTransformation))
self.shoflexRLabel.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
self.shoflexRLabel.setMinimumSize(150, 150)
self.shoflexRLabel.resize(800, 600)
def resizeEvent(self, event):
scaledSize = self.shoflexLLabel.size()
if not self.shoflexLLabel.pixmap() or scaledSize != self.shoflexLLabel.pixmap().size():
self.updateLabel()
def updateLabel(self):
self.shoflexLLabel.setPixmap(self.pixmap1.scaled(
self.shoflexLLabel.size(), Qt.KeepAspectRatio,
Qt.SmoothTransformation)) …Run Code Online (Sandbox Code Playgroud)