Ask Question

Name:
Title:
Your Question:

Answer Question

Name:
Your Answer:
User Submitted Source Code!


Description:
  3r3
Language: C/C++
Code:
#abdullah yılmaz tarafından geliştirilmiştir
from PyQt5 import QtWebEngineWidgets
from PyQt5 import QtCore ,QtGui,QtWidgets
from PyQt5.QtCore import QUrl
import cv2
import numpy as np






class Ui_prototek(object):
    def setupUi(self, prototek):
        #self.cap = cv2.VideoCapture(0)
        prototek.setObjectName("prototek")
        prototek.setWindowModality(QtCore.Qt.NonModal)
        prototek.setEnabled(True)
        prototek.resize(804, 391)
        self.pdff = QtWidgets.QPushButton(prototek)
        self.pdff.setGeometry(QtCore.QRect(20, 10, 111, 41))
        self.pdff.setObjectName("pdff")
        self.webEngineView = QtWebEngineWidgets.QWebEngineView(prototek)
        self.webEngineView.setGeometry(QtCore.QRect(9, 59, 791, 331))
        self.webEngineView.setUrl(QtCore.QUrl("about:blank"))
        self.webEngineView.setObjectName("webEngineView")
        self.hata = QtWidgets.QPushButton(prototek)
        self.hata.setGeometry(QtCore.QRect(350, 10, 111, 41))
        self.hata.setObjectName("hata")
        self.httpp = QtWidgets.QPushButton(prototek)
        self.httpp.setGeometry(QtCore.QRect(190, 10, 111, 41))
        self.httpp.setObjectName("httpp")
        self.ayar = QtWidgets.QPushButton(prototek)
        self.ayar.setGeometry(QtCore.QRect(680, 10, 101, 41))
        self.ayar.setObjectName("ayar")
        self.kamera = QtWidgets.QPushButton(prototek)
        self.kamera.setGeometry(QtCore.QRect(520, 10, 101, 41))
        self.kamera.setObjectName("kamera")
        self.httpp.clicked.connect(self.internet)
        self.pdff.clicked.connect(self.kullanm)
        self.kamera.clicked.connect(self.run)
        self.hata.clicked.connect(self.hataa)



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






    def kullanm(self):
        QtGui.QDesktopServices.openUrl(QUrl("file:///C:/Users/abdullah/Desktop/RASAT_SIU2014_Sunum.pdf", QUrl.TolerantMode))



    def internet(self):

        #self.webEngineView.load(QUrl("https://www.google.com/"))
        #self.webEngineView.show()
        QtGui.QDesktopServices.openUrl(QUrl("https://www.google.com/", QUrl.TolerantMode))

    #def run(self):

    #      cv2.imshow('my webcam', img)
       #     if cv2.waitKey(1) == 27:
       #         break  # esc to quit
        #cv2.destroyAllWindows()


    def retranslateUi(self, prototek):
        _translate = QtCore.QCoreApplication.translate
        prototek.setWindowTitle(_translate("prototek", "prototek"))
        self.pdff.setText(_translate("prototek", "kullanım klavuzu"))
        self.hata.setText(_translate("prototek", "hata tespit"))
        self.httpp.setText(_translate("prototek", "internet"))
        self.ayar.setText(_translate("prototek", "ayarlar"))
        self.kamera.setText(_translate("prototek", "kamera aç"))


    def __init__(self, camera_port=0):
        self.camera = cv2.VideoCapture(camera_port)
        self.running = False

    def run(self):
        self.running = True
        while self.running:
            read, image = self.camera.read()
            cv2.imshow("image", image)

            if cv2.waitKey(250) & 0xFF ==27:

                break




        #self.camera.release()
        #cv2.destroyAllWindows()

    def hataa(self):
        self.running = True

        def nothing(x):
            pass

        cv2.namedWindow("Trackbars")
        cv2.createTrackbar("L - H", "Trackbars", 0, 179, nothing)
        cv2.createTrackbar("L - S", "Trackbars", 0, 255, nothing)
        cv2.createTrackbar("L - V", "Trackbars", 0, 255, nothing)
        cv2.createTrackbar("U - H", "Trackbars", 179, 179, nothing)
        cv2.createTrackbar("U - S", "Trackbars", 255, 255, nothing)
        cv2.createTrackbar("U - V", "Trackbars", 255, 255, nothing)
        cv2.createTrackbar("quality", "Trackbars", 1, 100, nothing)

        while self.running:
            read, frame = self.camera.read()

            hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
            kernel = np.array([[-1, -1, -1], [-1, 9, -1], [-1, -1, -1]])

            l_h = cv2.getTrackbarPos("L - H", "Trackbars")
            l_s = cv2.getTrackbarPos("L - S", "Trackbars")
            l_v = cv2.getTrackbarPos("L - V", "Trackbars")
            u_h = cv2.getTrackbarPos("U - H", "Trackbars")
            u_s = cv2.getTrackbarPos("U - S", "Trackbars")
            u_v = cv2.getTrackbarPos("U - V", "Trackbars")
            quality = cv2.getTrackbarPos("quality", "Trackbars")
            lower_blue = np.array([l_h, l_s, l_v])
            upper_blue = np.array([u_h, u_s, u_v])
            mask = cv2.inRange(hsv, lower_blue, upper_blue)
            result = cv2.bitwise_and(frame, frame, mask=mask)
            #gray = cv2.cvtColor(result, cv2.COLOR_BGR2GRAY)
            cannyd = cv2.Canny(mask, 50, 200)
            img_median = cv2.medianBlur(mask, 5)  # Add median filter to image
            img_sharped = cv2.filter2D(img_median, -1, kernel)

            quality = quality / 100 if quality > 0 else 0.01
            corners = cv2.goodFeaturesToTrack(img_median, 5, quality, 0.04)
            if corners is not None:
                corners = np.int0(corners)
                for corner in corners:
                    x, y = corner.ravel()
                    cv2.circle(img_median, (x, y), 3, (255, 100, 255), 5)
            cv2.line(result, (320, 240), (330, 250), (255, 0, 0), 2)
            cv2.line(result, (320, 240), (310, 230), (255, 0, 0), 2)
            cv2.line(result, (320, 240), (330, 230), (255, 0, 0), 2)
            cv2.line(result, (320, 240), (310, 250), (255, 0, 0), 2)
            cv2.imshow("frame", frame)
            cv2.imshow("mask", mask)
            cv2.imshow("result", result)
            cv2.imshow("cannyd", cannyd)
            cv2.imshow('img', img_median)  # Display img with median filter

            cv2.imshow('imgkeskin', img_sharped)
            if cv2.waitKey(250) & 0xFF == 27:
                break

        # self.camera.release()
        # cv2.destroyAllWindows()



if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    prototek = QtWidgets.QWidget()
    ui = Ui_prototek()
    ui.setupUi(prototek)
    prototek.show()
    sys.exit(app.exec_())
Comments: