使用Boto将OpenCV映像上传到S3存储桶

时间:2018-07-31 19:13:58

标签: python-3.x opencv amazon-s3 encoding boto

我正在尝试使用boto2将图像上传到S3存储桶。但是,我遇到的问题是,在下面出现此错误:

  File "/home/dcs_user/code/ng_od/scripts/dataset_generator_slicer.py", line 131, in S3MGFrameExtractor
    key.send_file(f)
  File "/home/dcs_user/envMaster/lib/python3.5/site-packages/boto/s3/key.py", line 762, in send_file
    chunked_transfer=chunked_transfer, size=size)
  File "/home/dcs_user/envMaster/lib/python3.5/site-packages/boto/s3/key.py", line 963, in _send_file_internal
    query_args=query_args
  File "/home/dcs_user/envMaster/lib/python3.5/site-packages/boto/s3/connection.py", line 671, in make_request
    retry_handler=retry_handler
  File "/home/dcs_user/envMaster/lib/python3.5/site-packages/boto/connection.py", line 1071, in make_request
    retry_handler=retry_handler)
  File "/home/dcs_user/envMaster/lib/python3.5/site-packages/boto/connection.py", line 940, in _mexe
    request.body, request.headers)
  File "/home/dcs_user/envMaster/lib/python3.5/site-packages/boto/s3/key.py", line 840, in sender
    chunk = fp.read(self.BufferSize)
  File "/home/dcs_user/envMaster/lib/python3.5/codecs.py", line 321, in decode
    (result, consumed) = self._buffer_decode(data, self.errors, final)
  File "/home/dcs_user/envMaster/lib/python3.5/encodings/utf_16.py", line 61, in _buffer_decode
    codecs.utf_16_ex_decode(input, errors, 0, final)
UnicodeDecodeError: 'utf-16-le' codec can't decode bytes in position 0-1: illegal UTF-16 surrogate

我当前正在使用代码:

    cv2.imwrite(output_folder + str(uid) + '.jpg', frame)

    # Delete the frame now that we don't need it anymore
    del frame

    # Write to S3 nis-pub bucke
    bucket = s3.get_bucket('nis-pub')
    key = boto.s3.key.Key(bucket, str(uid) +'.jpg')
    with open(output_folder + str(uid) + '.jpg' ,encoding="utf16") as f:
        key.send_file(f)
        continue

通过以下方式获取frame的地方:

cap = cv2.VideoCapture(input_video)
ret, frame = cap.read()

我想找到一种将图像上传到S3的好方法,而无需将其实际保存到我的计算机上(没有文件I / O),并且使用了正确的编码。

0 个答案:

没有答案