Hi,
Here my first program (python and windows11 opencv-python 4.11.0.86):
import time
import numpy as np
import cv2 as cv
tps_start = time.time()
img = np.zeros((256, 256, 3),np.uint8)
idx = 0
code = 0
while code != 27:
if time.time()-tps_start > 1:
tps_start = time.time()
idx = idx + 1
img = np.zeros((256, 256, 3),np.uint8)
cv.putText(img, str(idx), (100, 100), cv.FONT_HERSHEY_SIMPLEX, 3, (255, 255, 255))
cv.imshow(“chrono”, img)
code = cv.waitKeyEx(50)
When you pressed a key and keep key down image change. Normal
Now I use socket. First program is server:
import socket
import time
host = “127.0.0.1”
port = 4444
server_socket = socket.socket()
server_socket.bind((host, port))
server_socket.listen(2)
conn, address = server_socket.accept()
print("Connection from: " + str(address))
tps_start = time.time()
idx = 0
while True:
if time.time()-tps_start > 1:
tps_start = time.time()
idx = idx + 1
conn.send(str(idx).encode())
conn.close()
Now client program
import socket
import numpy as np
import cv2 as cv
IP_SERVEUR = "127.0.0.1"
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(0.5)
s.connect((IP_SERVEUR, 4444))
img = np.zeros((256, 256, 3),np.uint8)
code = 0
while code != 27:
try:
data = s.recv(3)
if data:
idx = int(data.decode())
img = np.zeros((256, 256, 3),np.uint8)
cv.putText(img, str(idx), (100, 100), cv.FONT_HERSHEY_SIMPLEX, 3, (255, 255, 255))
cv.imshow("chrono", img)
except TimeoutError:
print("timeout")
data = ""
code = cv.waitKeyEx(50)
Run server program and client program. Do nothing… It works. Press a key down and let it down and something weird happen time stop. Key up and then time go on.
If you had cv.imwrite(“image”+str(idx_image)+“.jpg”, img) before imshow then on disk all images are saved.
Why waitKeyEx (waitKey or pollKey) disable update image?
UPDATE there is no problm on ubuntu with QT5