我有以下脚本,我使用 OpenCV 从 Python3 读取 RTSP 流。
cap = cv2.VideoCapture(ID)
ret, frame = cap.read()
这些流使用 h264 进行编码,我收到大量警告和错误消息。
[h264 @ 0x7f74cc430c80] co located POCs unavailable
[h264 @ 0x7f74b4258160] error while decoding MB 38 2, bytestream -19
我尝试使用上下文管理器来重定向 stdout 和 stderr 让它们保持沉默,但没有成功:
class SilenceOutput(object):
def __enter__(self):
self._original_stdout = sys.stdout
self._original_stderr = sys.stderr
sys.stdout = None
sys.stderr = None
def __exit__(self, exc_type, exc_val, exc_tb):
sys.stdout = self._original_stdout
sys.stderr = self._original_stderr
Run Code Online (Sandbox Code Playgroud) 我正在使用 asyncio subprocess 来执行子命令。我想查看长时间运行的进程并同时将内容保存到缓冲区以供以后使用。此外,我发现了这个相关的问题(Getting live output from asyncio subprocess),但它主要围绕 ssh 的用例。
asyncio subprocess 文档有一个逐行读取输出的示例,这符合我想要实现的目标。(https://docs.python.org/3/library/asyncio-subprocess.html#examples)
import asyncio
import sys
async def get_date():
code = 'import datetime; print(datetime.datetime.now())'
# Create the subprocess; redirect the standard output
# into a pipe.
proc = await asyncio.create_subprocess_exec(
sys.executable, '-c', code,
stdout=asyncio.subprocess.PIPE)
# Read one line of output.
data = await proc.stdout.readline()
line = data.decode('ascii').rstrip()
# Wait for the subprocess exit.
await proc.wait()
return line
date = asyncio.run(get_date())
print(f"Current date: {date}")
Run Code Online (Sandbox Code Playgroud)
我将此示例改编为以下内容: …
可能是一个非常简单的问题,但我无法提出解决方案.我有一个包含9列和~100000行的数据框.从图像中提取数据,使得两列('row'和'col')指的是数据的像素位置.如何创建一个numpy数组A,使得行和列指向另一列中的另一个数据条目,例如'grumpiness'?
A[row, col]
# 0.1232
Run Code Online (Sandbox Code Playgroud)
我想避免使用for循环或类似的东西.