我想在python上传输热图像,但是我只得到一个不会更新的图像。温度传感器停止更新温度。当我删除cv2.imshow时,一切再次正常。热传感器再次打印当前温度。我尝试了许多其他选项,例如plt.imshow(cv2.cvtColor(image, cv2.BGR2RGB))
plt.show()
或我在代码中的以下注释,但似乎没有任何效果。
参见下面的代码:
import socket
import pickle
import numpy as np
import cv2
from matplotlib import pyplot as plt
HEADERSIZE = 8355
host = ''
port = 1238
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((host, port))
while True:
full_msg = b''
new_msg = True
while True:
msg = s.recv(8355)
if new_msg:
print(f"new message length: {msg[:HEADERSIZE]}")
msglen = int(msg[:HEADERSIZE])
new_msg = False
full_msg += msg
if len(full_msg) - HEADERSIZE == msglen:
print("Full msg recvd")
print(full_msg[HEADERSIZE:])
d = pickle.loads(full_msg[HEADERSIZE:])
print(d)
image = np.array(d)
image = cv2.resize(image, (300, 300))
print(image)
plt.imsave('color_img1.jpg', image)
img = cv2.imread('color_img1.jpg', 1)
#plt.imshow(cv2.cvtColor(image, cv2.COLOR_BGR2HSV))
#plt.show()
#cv2.imshow('lmao', img)
#cv2.waitKey(0)
new_msg = True
full_msg = b''
print(full_msg)
答案 0 :(得分:1)
必须设置与传感器帧频兼容的waitKey输入值。例如,如果每隔100毫秒获取一次新图像,则应使用少于100毫秒的输入来输入waitKey:
cv2.imshow('lmao', img)
cv2.waitKey(10) # almost always 10 miliseconds is good enough for showing a good image