0

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.

mmt
  • 53
  • 8

1 Answers1

0

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
telenachos
  • 884
  • 6
  • 18