简体   繁体   English

python cv2将无法保存图片且未显示任何错误

[英]python cv2 won't save picture and not shown any error

This is my old code, from what I write in my short note it should read video and save each frame in a folder, I try to use it again and it's not working. 这是我的旧代码,从我写的简短笔记中可以读取视频并将每一帧保存在一个文件夹中,我尝试再次使用它,但是它不起作用。 There are no error shown all path exist. 没有错误显示所有路径都存在。

filename = 'H2N2A'
trainingfiles = 14
def getFrames():
    vidcap = cv2.VideoCapture('Train'+str(trainingfiles)+'/'+filename+'.MP4')
    success, image = vidcap.read()
    count = 0
    success = True
    while success:
        success, image = vidcap.read()
        #print 'Read a new frame: ', success
        print count
        #print "Train"+str(trainingfiles)+"/"+filename+"/frame%d.jpg" % count, image
        cv2.imwrite("Train"+str(trainingfiles)+"/"+filename+"/frame"+str(count)+".jpg", image)
        count += 1
    vidcap.release()
    return count-1

Do anyone have any idea why? 有人知道为什么吗?

Did you try calling the getFrames() function from somewhere else in your code? 您是否尝试从代码中的其他位置调用getFrames()函数?

Given the code above, Python will not run the logic in getFrames unless you call it first. 给定上面的代码,除非您先调用Python,否则Python将不会在getFrames运行该逻辑。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM