我有以下代码,在这些代码中,我将连续数据从拖缆发送到查看器。我正在检索cv函数调整大小错误
Streamer.py
footage_socket.connect('tcp://localhost:8080')
videoFile = "D:/sample.mp4"
camera = cv2.VideoCapture(videoFile)
while True:
grabbed, frame = camera.read()
try:
frame = cv2.resize( frame, (224, 224) ).astype( "float32" )
except cv2.error:
break
image= img_to_array(frame)
image=image.reshape((1,image.shape[0],image.shape[1],image.shape[2]))
image=preprocess_input(image)
preds=model.predict(image)
footage_socket.send(preds)
footage_socket.close()
Viewer.py
context = zmq.Context()
footage_socket = context.socket(zmq.SUB)
footage_socket.bind('tcp://*:8080')
footage_socket.setsockopt_string(zmq.SUBSCRIBE, np.unicode(''))
while True:
frame = footage_socket.recv()
img = cv2.imdecode(np.fromstring(base64.b64decode(frame),dtype = np.uint8),1)
frame = cv2.resize( img, (224, 224) )
image = img_to_array( frame )
image = image.reshape( (1, image.shape[0], image.shape[1], image.shape[2]) )
image = preprocess_input( image )
predictions = m1.predict(img)
footage_socket.close()
我正在检索以下错误
frame = cv2.resize( img, (224, 224) )
cv2.error: OpenCV(4.2.0) C:\projects\opencv-python\opencv\modules\imgproc\src\resize.cpp:4045: error:
(-215:Assertion failed) !ssize.empty() in function 'cv::resize'
我们非常感谢您的帮助。谢谢
答案 0 :(得分:0)
我通过将代码从recv_string()更改为recv_pyobj(),将代码从send()更改为send_pyobj()来解决了该问题,并且代码运行正常。谢谢