我正在尝试使用以下代码捕获命令的输出:
lines = subprocess.run(['ffmpeg', '-hide_banner', '-nostats', '-i', in_filename, '-vn', '-af', 'silencedetect=n={}:d={}'.format(silence_threshold, silence_duration), '-f', 'null', '-'], capture_output=True, text=True, shell=True, check=True, encoding='utf-8').stdout
print (lines)
Run Code Online (Sandbox Code Playgroud)
但lines是一个空字符串并且没有打印任何内容。删除后capture_output=True,将显示正确的输出(不打印)。
我测试了许多组合,包括删除所有subprocess.run参数并仅包含capture_output=True相同的结果。
我还用很少的参数进行了测试,举了一个最小的例子:subprocess.run(['ffmpeg', '-version'], capture_output=True, text=True, shell=True, check=True, encoding='utf-8').stdout
还进行了测试stdout=subprocess.PIPE并stderr=subprocess.PIPE作为subprocess.run参数而不是capture_output=True
我不明白发生了什么事。提前致谢!
我试图以正确的顺序组合图块,以便它们最终成为相同的整个幻灯片图像(.svs 文件)。
根据以下函数从文件路径读取 .svs 文件:
def open_slide(filepath = None):
try:
slide = openslide.open_slide(filepath)
except OpenSlideError as o:
print("Error" + str(o))
slide = None
except FileNotFoundError as f:
print("Error" + str(f))
slide = None
return slide
Run Code Online (Sandbox Code Playgroud)
在下图中,我尝试合并使用 openslide-python 的 DeepZoom 生成器获得的图块(请参阅下面的代码片段)
def create_tile_generator(slide, tile_size, overlap):
gen = DeepZoomGenerator(slide, tile_size=tile_size, overlap=overlap, limit_bounds=False)
Run Code Online (Sandbox Code Playgroud)
这就是我将 .svs 拆分为图块的方法:
def split_wsi_to_tiles(wsi_path = None):
print("splitting wsi into tiles")
tile_indices = process_slide(slide_num = SLIDE_NUM , filepath= wsi_path, tile_size = TILE_SIZE, overlap = OVERLAP)
i = 0
tile_indices_savepath = …Run Code Online (Sandbox Code Playgroud)