Converting sequenced frames to video

我的未来我决定 提交于 2019-12-25 06:29:28

问题


I'm trying to convert images to video, but it wasn't getting the right sequence, so I'm using glob to organize it. After this I was getting erros, and then I reduced my code to this:

import re
import glob
import cv2

numbers = re.compile(r'(\d+)')

def numericalSort(value):
    parts = numbers.split(value)
    parts[1::2] = map(int, parts[1::2])
    return parts

for infile in sorted(glob.glob('*.jpg'), key=numericalSort):
    img1 = cv2.imread(infile)

    cv2.imshow('image', img1)

    exit()

And for some reason it isn't showing 'img1'.

I think I can't call "cv2.imread" for a variable, because in my previous code it was saying something like "its not a valid array" when I called an opencv function to work with 'img1'.

So, my questions is, why isn't imshow running, and how could I use the image """behind""" infile and work with this file.


回答1:


You need a call to waitKey() in order for imshow() to work.

For example:

import re
import glob
import cv2

numbers = re.compile(r'(\d+)')

def numericalSort(value):
    parts = numbers.split(value)
    parts[1::2] = map(int, parts[1::2])
    return parts

for infile in sorted(glob.glob('*.jpg'), key=numericalSort):
    img1 = cv2.imread(infile)

    cv2.imshow('image', img1)
    k = cv2.waitKey(33)
    if k==27:    # Escape to quit
        break


来源:https://stackoverflow.com/questions/43240404/converting-sequenced-frames-to-video

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!