Pyqt5 cv2 ile resim kırpma modülü nasıl yerleştirilir?

Başlatan Dreatest, 01 Haziran 2021 - 14:04:08

« önceki - sonraki »

0 Üyeler ve 1 Ziyaretçi konuyu incelemekte.

Dreatest

Opencv ile bir resim kırpma uygulaması oluşturdum. Bir pencere açıyor onda kırptıktan sonra kırpılan resmi başka bir pencerede gösteriyor. Bu işlemleri opencv nin kendisinde değil de pyqt5'te nasıl yapabilirim?


#Modülleri belirtiyoruz.
import cv2
import os, sys
from responsive_voice import ResponsiveVoice
from responsive_voice.voices import TurkishFemale

#Foto
yol = "./photos/"
liste_yol = os.listdir( yol )
l = [yol+nesne for nesne in liste_yol if ".jpg" or ".png" in nesne]
im_nu = 0
t = 0
kesme = False
x_basl, y_basl, x_son, y_son = 0, 0, 0, 0

resim = cv2.imread(l[im_nu])
oriresim = resim.copy()


#tıkla kes = crop_node olcaK
def crop_node(olay, x, y, flags, param):
    global x_basl, y_basl, x_son, y_son, kesme, t

    if olay == cv2.EVENT_LBUTTONDOWN:
        x_basl, y_basl, x_son, y_son = x, y, x, y
        kesme = True

    elif olay == cv2.EVENT_MOUSEMOVE:
        if kesme == True:
            x_son, y_son = x, y

    elif olay == cv2.EVENT_LBUTTONUP:
        x_son, y_son = x, y
        kesme = False

        refNokta = [(x_basl, y_basl), (x_son, y_son)]

        if len(refNokta) == 2:
            t += 1
            alan = oriresim[refNokta[0][1]:refNokta[1][1], refNokta[0][0]:refNokta[1][0]]
            cv2.imshow("Kesilen Resim", alan)
            cv2.imwrite("cropped-images/new-image"+str(t)+".jpg", alan)


cv2.namedWindow("resim", cv2.WINDOW_NORMAL)
cv2.setMouseCallback("resim", crop_node)

while True:
    key = cv2.waitKey(1) & 0xFF
    i = resim.copy()

    if not kesme:
        cv2.imshow("resim", resim)

    elif kesme:
        cv2.rectangle(i, (x_basl, y_basl), (x_son, y_son), (255, 0, 0), 2)
        cv2.imshow("resim", i)   

    cv2.waitKey(1)
    if key == ord(" "):
        im_nu += 1
        resim = cv2.imread(l[im_nu])
        oriresim = resim.copy()
        cv2.imshow("resim", resim)
        cv2.setMouseCallback("resim", crop_node)

cv2.destroyAllWindows()