python脚本中出错:进程已完成,退出代码为1073740940(0xC0000374)

2024-06-25 05:56:53 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在写一个脚本来创建蠕虫图像的骨架(在视频中),以测量所述骨架的长度。 脚本工作正常,直到一些视频停止程序并显示以下错误消息:

"Process finished with exit code -1073740940 (0xC0000374)"

我不知道发生了什么,因为它在为该节目提供的每一个其他视频中都能正常工作。唯一的区别是视频长度。导致此错误消息的视频长2分钟,而其他视频长约1分钟。不过,错误消息仅出现在部分视频中,而不是所有视频中。当错误消息出现时,它在特定帧上并不一致,而是始终出现在不同的帧上

我尝试使用faulthandler获取有关错误的更多信息

我收到的信息是:

Windows fatal exception: code 0xc0000374

Thread 0x00001e78 (most recent call first):   File
"C:\Users\Dennis\anaconda3\envs\WormRuler\lib\site-packages\imageio_ffmpeg\_parsing.py",
line 60 in run   File
"C:\Users\Dennis\anaconda3\envs\WormRuler\lib\threading.py", line 932
in _bootstrap_inner   File
"C:\Users\Dennis\anaconda3\envs\WormRuler\lib\threading.py", line 890
in _bootstrap

Current thread 0x00003918 (most recent call first):   File
"C:\Users\Dennis\anaconda3\envs\WormRuler\lib\site-packages\PIL\Image.py",
line 2698 in new   File
"C:\Users\Dennis\anaconda3\envs\WormRuler\lib\site-packages\PIL\Image.py",
line 2784 in frombuffer   File
"C:\Users\Dennis\anaconda3\envs\WormRuler\lib\site-packages\PIL\Image.py",
line 2849 in fromarray   File
"C:\Users\Dennis\anaconda3\envs\WormRuler\lib\site-packages\imageio\plugins\pillow.py",
line 835 in ndarray_to_pil   File
"C:\Users\Dennis\anaconda3\envs\WormRuler\lib\site-packages\imageio\plugins\pillowmulti.py",
line 347 in converToPIL   File
"C:\Users\Dennis\anaconda3\envs\WormRuler\lib\site-packages\imageio\plugins\pillowmulti.py",
line 159 in add_image   File
"C:\Users\Dennis\anaconda3\envs\WormRuler\lib\site-packages\imageio\plugins\pillowmulti.py",
line 116 in _append_data   File
"C:\Users\Dennis\anaconda3\envs\WormRuler\lib\site-packages\imageio\core\format.py",
line 502 in append_data   File
"C:/Users/Dennis/Documents/PhD/Python/WormRuler/worm_ruler_V3.1.py",
line 281 in skeletonize   File
"C:/Users/Dennis/Documents/PhD/Python/WormRuler/worm_ruler_V3.1.py",
line 339 in skeletonization   File
"C:\Users\Dennis\anaconda3\envs\WormRuler\lib\tkinter\__init__.py",
line 1892 in __call__   File
"C:\Users\Dennis\anaconda3\envs\WormRuler\lib\tkinter\__init__.py",
line 1429 in mainloop   File
"C:/Users/Dennis/Documents/PhD/Python/WormRuler/worm_ruler_V3.1.py",
line 645 in <module>

Process finished with exit code -1073740940 (0xC0000374)

也许一段代码会有所帮助:

import skan
import os
import imageio
from skimage.morphology import thin
from skimage.util import img_as_bool
from skimage import color
from fil_finder import FilFinder2D
import astropy.units as u
import warnings

# Ignore filfinder warnings
warnings.filterwarnings('ignore', '.*No beam width given.*', )
warnings.filterwarnings('ignore', '.*Graph pruning reached max iterations.*', )

def skeletonize():
    # open vid
    video_root = "C:/Users/Dennis/Desktop/test_marius/"
    folders = []
    for r, d, f in os.walk(video_root):
        for folder in d:
            folders.append(folder)
    for folder in folders:
        video_paths = []
        for r, d, f in os.walk(str(video_root) + "/" + str(folder)):
            for file in f:
                if "_bw.gif" in file:
                    video_paths.append(os.path.join(r, file))

        for v_path in video_paths:
            vid = imageio.get_reader(v_path, 'ffmpeg')
            worm_lengths = []
            for num, frame in enumerate(vid):
                try:
                    img = color.rgb2gray(frame)
                    binary = img_as_bool(img)
                    # perform skeletonization
                    skel = thin(binary)
                    fil = FilFinder2D(skel, distance=250 * u.pc, mask=skel)
                    fil.medskel(verbose=False)
                    fil.analyze_skeletons(branch_thresh=400 * u.pix, skel_thresh=10 * u.pix, prune_criteria='length')
                    skel_fil = fil.skeleton_longpath
                    # checks if any true values in numpy array of skeleton
                    if skel.any():
                        paths = skan.Skeleton(skel_fil, keep_images=False)
                        pathlengths = paths.path_lengths()
                        pathlengths.sort()
                        worm_lengths.append(pathlengths[0])
                    else:
                        worm_lengths.append(None)
                except:
                    worm_lengths.append(None)

skeletonize()

可用于重现错误消息。产生错误的视频可以在here找到


Tags: inpyimport视频libpackageslinesite