How to capture the text in OCR

How to capture the text by pressing a key without displaying the frame in OCR.

def detect_ocr(frame):
if cv2.waitKey(1) & 0XFF == ord(“s”):
text = pytesseract.image_to_string(frame)
print(text)
#cv2.imshow(“Frame”,frame)
cv2.waitKey(1)