【问题标题】:Retrieving opencv error (-215:Assertion failed) !ssize.empty() in function 'cv::resize'检索opencv错误(-215:断言失败)!ssize.empty()在函数'cv :: resize'中
【发布时间】:2021-02-23 06:45:36
【问题描述】:

我有以下代码,我将连续数据从流媒体发送到查看器。我在 cv 函数 resize 中检索错误

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()

查看器.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'

非常感谢您的帮助。谢谢

【问题讨论】:

  • 很可能footage_socket.recv() 返回null
  • 非常感谢我会看看这个@Ahx
  • 我可以检索到不为空的数据@Ahx
  • 那你显示图片cv2.imshow("img", img); cv2.waitKey(0) 了吗?
  • 我不需要显示图像,但我会检查并看到这个。一旦图像转换为帧@Ahx,我只需要发送预测结果

标签: python python-3.x tensorflow opencv opencv3.0


【解决方案1】:

我通过将代码从 recv_string() 更改为 recv_pyobj() 以及从 send() 更改为 send_pyobj() 解决了这个问题,并且代码运行良好。谢谢

【讨论】:

    猜你喜欢
    • 2020-08-21
    • 2020-02-03
    • 2021-12-19
    • 2020-08-11
    • 2020-10-13
    • 2019-12-07
    • 1970-01-01
    • 2019-05-18
    • 1970-01-01
    相关资源
    最近更新 更多