Cześć. Mój projekt to inteligentne lustro i mam z nim problem jeśli chodzi o kod mianowicie kod działa na takiej zasadzie że pokazuję dłoń i wyświetla się okienko kamery z narysowanymi kwadratami w rogach po najechaniu ręką na kwadrat wykonuje się instrukcja inteligentnego lustra i tu pojawia się problem bo chciałbym tak zrobić aby po pokazaniu ręki ponownie włączało się okienko kamery abym mógł wybrać opcję zamknięcia wyświetlania interfejsu lustera. Proszę pomóżcie ;-;
root = "tk.Tk()"
root.configure(background="black")
root.attributes("-fullscreen", True)
# Ukrycie kursora
root.config(cursor="none")
def close_camera():
cap.release()
camera_label.place_forget()
camera_label.place(relx=0.5,rely=0.5, x=0,y=200,anchor='s') # lub gdziekolwiek chcesz umieścić etykietę kamery
cap = cv2.VideoCapture(0)
hand_cascade=cv2.CascadeClassifier('/home/karol/Dokumenty/Smart_Mirror/OpenCV-master/haarcascades/palm.xml')
hand_shown=False
def get_camera():
global hand_shown
ret, frame = cap.read()
hands = hand_cascade.detectMultiScale(frame, 1.3, 5)
if ret and len(hands)>0:
hand_shown=True
if hand_shown:
for (x,y,w,h) in hands:
cv2.rectangle(frame, (x,y),(x+w,y+h),(0,255,0),2)
if (x < 100 and y < 100):
cv2.putText(frame, 'ON', (x, y), cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 0, 0), 2, cv2.LINE_AA)
close_camera()
hand_shown=False
get_date()
get_time()
get_sunrise()
get_weather()
get_weather_feels_like()
get_forecast_title()
get_forecast_day_name()
get_forecast_day_temp()
get_forecast_feels()
get_forecast_icon()
get_wind_speed()
get_calendar_title()
get_calendar()
get_compliments()
update_track_info()
get_news(entries, 0)
if (x + w > frame.shape[1] - 100 and y < 100):
cv2.putText(frame,'LOL',(x + w,y),cv2.FONT_HERSHEY_SIMPLEX,1,(255,0,0),2,cv2.LINE_AA)
if (x < 100 and y + h > frame.shape[0] - 100):
cv2.putText(frame,'DUPA',(x,y + h),cv2.FONT_HERSHEY_SIMPLEX,1,(0,0,255),2,cv2.LINE_AA)
if (x + w > frame.shape[1] -100 and y + h > frame.shape[0] - 100):
cv2.putText(frame,'KUPA',(x + w,y + h),cv2.FONT_HERSHEY_SIMPLEX,1,(0,0,255),2,cv2.LINE_AA)
frame=cv2.flip(frame,1)
height, width,_=frame.shape
square_size=150
thickness=2
cv2.rectangle(frame,(0,0),(square_size,square_size),(0,0,255),thickness)
cv2.rectangle(frame,(width-square_size,0),(width,square_size),(0,0,255),thickness)
cv2.rectangle(frame,(0,height-square_size),(square_size,height),(0,0,255), thickness)
cv2.rectangle(frame,(width-square_size,height-square_size),(width,height),(0,0,255),thickness)
cv2.putText(frame, 'OFF', (10, 30), cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 255), 2)
cv2.putText(frame, 'ON', (width - square_size + 10, 30), cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 255), 2)
cv2.putText(frame, 'LED-OFF', (10, height - square_size + 30), cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 255), 2)
cv2.putText(frame, 'LED-ON', (width - square_size + 10, height - square_size + 30), cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 255), 2)
image=cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)
image=Image.fromarray(frame)
imgtk=ImageTk.PhotoImage(image=image)
camera_label.imgtk=imgtk
camera_label.configure(image=imgtk)
camera_label.after(15, get_camera)
# Wywołanie funkcji
get_camera()
# uruchamianie głównej pętli programu
root.mainloop()