Задать вопрос
@maroonlok

Как можно вывести значение в таблицу?

Сделал рабочее пространство на pyqt5 и создал окно cv2 c выводом в cv2.rectangle сложенных значений rgb. Кто сможет подсказать, как организовать вывод в созданный Qtable данных что выводятся в cv2.rectangle(Через cv2.putText())

spoiler
Интерфейс:
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import QApplication, QMainWindow, QFileDialog, QWidget, QMessageBox, QGraphicsView, QGraphicsScene, QGraphicsPixmapItem, QVBoxLayout, QTableWidget, QTableWidgetItem, QMenu, QMenuBar, QAction
from PyQt5.QtGui import QPixmap, QImage
import sys
import logo
import os
import openpyxl
from PIL import Image
import cv2
from open import show_photo
import xlrd
from PyQt5.Qt import *
from xlsxwriter.workbook import Workbook
import cv2
import numpy as np


class Ui_MainsWindow(object):
    def setupUi(self, MainsWindow):
        MainsWindow.setObjectName("Getera Program")
        MainsWindow.resize(1920, 1080)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(MainsWindow.sizePolicy().hasHeightForWidth())
        MainsWindow.setSizePolicy(sizePolicy)
        MainsWindow.setMinimumSize(QtCore.QSize(800, 800))
        MainsWindow.setStyleSheet("background-color:rgb(129, 129, 129)")
        MainsWindow.setIconSize(QtCore.QSize(24, 24))
        self.centralwidget = QtWidgets.QWidget(MainsWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.line = QtWidgets.QFrame(self.centralwidget)
        self.line.setGeometry(QtCore.QRect(50, 0, 20, 41))
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.line.sizePolicy().hasHeightForWidth())
        self.line.setSizePolicy(sizePolicy)
        self.line.setStyleSheet("background-color:rgb(149, 149, 149);")
        self.line.setFrameShape(QtWidgets.QFrame.VLine)
        self.line.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line.setObjectName("line")
        self.label = QtWidgets.QLabel(self.centralwidget)
        self.label.setGeometry(QtCore.QRect(0, 0, 1921, 41))
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.label.sizePolicy().hasHeightForWidth())
        self.label.setSizePolicy(sizePolicy)
        self.label.setStyleSheet("background-color:rgb(149, 149, 149);")
        self.label.setText("")
        self.label.setObjectName("label")
        self.pushButton = QtWidgets.QPushButton(self.centralwidget)
        self.pushButton.setGeometry(QtCore.QRect(70, 10, 81, 21))
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.pushButton.sizePolicy().hasHeightForWidth())
        self.pushButton.setSizePolicy(sizePolicy)
        font = QtGui.QFont()
        font.setFamily("Arial Black")
        font.setPointSize(9)
        font.setBold(True)
        font.setWeight(75)


        self.pushButton.setFont(font)
        self.pushButton.setStyleSheet("background-color:rgb(209, 209, 209);")
        self.pushButton.setObjectName("pushButton")
        self.pushButton_3 = QtWidgets.QPushButton(self.centralwidget)
        self.pushButton_3.setGeometry(QtCore.QRect(250, 10, 81, 21))
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.pushButton_3.sizePolicy().hasHeightForWidth())
        self.pushButton_3.setSizePolicy(sizePolicy)
        font = QtGui.QFont()
        font.setFamily("Arial Black")
        font.setPointSize(9)
        font.setBold(True)
        font.setWeight(75)
        self.pushButton_3.setFont(font)
        self.pushButton_3.setStyleSheet("background-color:rgb(209, 209, 209);")
        self.pushButton_3.setObjectName("pushButton_3")

    #Frame new
        self.col = QtWidgets.QFrame(self.centralwidget)
        self.col.setGeometry(QtCore.QRect(500, 100, 400, 400))
        self.col.setStyleSheet("background-color:rgb(149, 149, 149);")






    #создание таблицы
        self.table = QtWidgets.QTableWidget(self.centralwidget)
        self.table.setColumnCount(6)
        self.table.setRowCount(10000)
        self.table.setHorizontalHeaderLabels(["A","B","C","D"])
        sizePolicy.setHorizontalStretch(400)
        sizePolicy.setVerticalStretch(400)
        self.table.setGeometry(QtCore.QRect(10, 50, 460, 1000))
        self.table.setSizePolicy(sizePolicy)
        self.table.setStyleSheet("background-color:rgb(209, 209, 209);")




        


        self.label_2 = QtWidgets.QLabel(self.centralwidget)
        self.label_2.setGeometry(QtCore.QRect(10, 0, 41, 41))
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.label_2.sizePolicy().hasHeightForWidth())
        self.label_2.setSizePolicy(sizePolicy)
        self.label_2.setStyleSheet("background-color:rgb(149, 149, 149);")
        self.label_2.setText("")
        self.label_2.setPixmap(QtGui.QPixmap(":/newPrefix/logo.ico"))
        self.label_2.setScaledContents(True)
        self.label_2.setObjectName("label_2")

        self.pushButton_4 = QtWidgets.QPushButton(self.centralwidget)
        self.pushButton_4.setGeometry(QtCore.QRect(160, 10, 81, 21))
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.pushButton_4.sizePolicy().hasHeightForWidth())
        self.pushButton_4.setSizePolicy(sizePolicy)
        font = QtGui.QFont()
        font.setFamily("Arial Black")
        font.setPointSize(9)
        font.setBold(True)
        font.setWeight(75)
        self.pushButton_4.setFont(font)
        self.pushButton_4.setStyleSheet("background-color:rgb(209, 209, 209);")
        self.pushButton_4.setObjectName("pushButton_4")
        self.line_2 = QtWidgets.QFrame(self.centralwidget)
        self.line_2.setGeometry(QtCore.QRect(50, 0, 20, 41))
        self.line_2.setStyleSheet("background-color:rgb(149, 149, 149);")
        self.line_2.setFrameShape(QtWidgets.QFrame.VLine)
        self.line_2.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line_2.setObjectName("line_2")
        MainsWindow.setCentralWidget(self.centralwidget)
        self.statusbar = QtWidgets.QStatusBar(MainsWindow)
        self.statusbar.setObjectName("statusbar")
        MainsWindow.setStatusBar(self.statusbar)



        self.retranslateUi(MainsWindow)
        QtCore.QMetaObject.connectSlotsByName(MainsWindow)


    def retranslateUi(self, MainsWindow):
        _translate = QtCore.QCoreApplication.translate
        MainsWindow.setWindowTitle(_translate("MainsWindow", "MainsWindow"))
        self.pushButton.setText(_translate("MainsWindow", "Open"))
        self.pushButton_3.setText(_translate("MainsWindow", "Map"))
        self.pushButton_4.setText(_translate("MainsWindow", "Save"))


Узнать цвет с картинки и добавить значение в определенном диапазоне:

spoiler
import cv2
import numpy as np
import sys

img_path = "6.jpg"
img = cv2.imread(img_path, cv2.IMREAD_COLOR)
img_1 = cv2.resize(img, (1920, 1080))
r = g = b = 0
clicked = False

def color_function(event, x, y, flag, param):
    if event == cv2.EVENT_LBUTTONUP:
        global r, g, b, z, clicked
        r, g, b = img_1[y, x]
        r = int(r)
        g = int(g)
        b = int(b)
        z = int(r) + int(g) + int(b)
        clicked = True

cv2.namedWindow("getera")
cv2.setMouseCallback("getera", color_function)

while True:
    cv2.imshow("getera", img_1)

    if clicked:
        cv2.rectangle(img_1, (10, 20), (200, 60), (r, g, b), -1)
        if r + g + b  <= 650:

            cv2.putText(img_1, "% = " + str(r + g + b), (50, 50), 2, 1.0,
                                        (0, 0, 0))
        else:
            cv2.putText(img_1, "% = " + str(z), (30, 50), 2, 1.0,
                        (0, 0, 0))

        cv2.rectangle(img_1, (10, 130), (200, 60), (r, g, b), -1)
        if 363 <= z <= 366:
            cv2.putText(img_1, "Int = 0%", (30, 100), 2, 1.0,
                                        (0, 0, 0))

        if 589 <= z <= 650:
            cv2.putText(img_1, "Int = 15%", (30, 100), 2, 1.0,
                                        (0, 0, 0))
        if 431 <= z <= 510:
            cv2.putText(img_1, "Int = 10%", (30, 100), 2, 1.0,
                                        (0, 0, 0))
        if 290 <= z <= 310:
            cv2.putText(img_1, "Int = 100%", (30, 100), 2, 1.0,
                                        (0, 0, 0))


    if cv2.waitKey(20) & 0xFF == 27:
        break
cv2.destroyAllWindows()
  • Вопрос задан
  • 59 просмотров
Подписаться 1 Средний 2 комментария
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы