[Python] Python CV2 and tkinter canvas

Discussão em 'Python' iniciado por Stack, Abril 11, 2025.

  1. Stack

    Stack Membro Participativo

    I have been working on face recognition tool and i have to draw a square on an image the problem is before the last line cv2.rectangle(photo1.....) because the image is not a cv2 it says i have given a bad argument but putting in frame_rgb doesnt work print('hello world')

    face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + 'haarcascade_frontalface_default.xml')
    def update_camera1():
    global photo1
    if camera1_active:
    ret, frame = cap1.read()
    if ret:
    frame = cv2.resize(frame, (int(w*0.5), int(h*0.498)))
    frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
    frame_gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    faces = face_cascade.detectMultiScale(frame_gray, 1.3, 5)
    photo1 = PIL.ImageTk.PhotoImage(image=PIL.Image.fromarray(frame_rgb))
    canvas.create_image(0, 0, image=photo1, anchor=NW)
    for (x, y, width, height) in faces:
    cv2.rectangle(photo1, (x, y), (x+width, y+height), (255, 0), 3)
    root.after(10, update_camera1)

    Continue reading...

Compartilhe esta Página