小编mgu*_*che的帖子

在 Python 中从 OpenCV 调用时静默 h264 解码警告

我有以下脚本,我使用 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)

python logging opencv ffmpeg h.264

5
推荐指数
0
解决办法
2812
查看次数

使用 asyncio 子进程连续输出

我正在使用 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)

我将此示例改编为以下内容: …

python logging subprocess python-asyncio

5
推荐指数
1
解决办法
1937
查看次数

从Pandas数据帧创建2D数组

可能是一个非常简单的问题,但我无法提出解决方案.我有一个包含9列和~100000行的数据框.从图像中提取数据,使得两列('row'和'col')指的是数据的像素位置.如何创建一个numpy数组A,使得行和列指向另一列中的另一个数据条目,例如'grumpiness'?

A[row, col]
#  0.1232
Run Code Online (Sandbox Code Playgroud)

我想避免使用for循环或类似的东西.

python numpy vectorization pandas

3
推荐指数
2
解决办法
6429
查看次数