Load image sequence

I want to open a window and load a image sequence from a given path

import cv2
 
imSeq = cv2.VideoCapture(r"D:\software\scripts\NikScr\img\610_002_UD_v001.%04d.jpg")
 
if(imSeq.isOpened() == False):
    print("Error opening the video")
 
while(imSeq.isOpened()):
    ret, frame = imSeq.read()
 
    if ret == True:
        cv2.imshow("Frames",frame)
 
        if cv2.waitKey(25):
            breakpoint()
    else:
        break
 
imSeq.release()
cv2.destroyAllWindows()

i want to display sequence.but Im getting this error
[image2 @ 0000028afef22840] Could find no file with path ‘D:\software\scripts\NikScr\img\610_002_070_4CG_UD_v001.%04d.jpg’ and index in the range 0-4
Error opening the video

do

D:\software\scripts\NikScr\img\610_002_070_4CG_UD_v001.0000.jpg
D:\software\scripts\NikScr\img\610_002_070_4CG_UD_v001.0001.jpg

exist ?

yes there are 15 images in sequence but there starting frame is 1001. I mentioned %04d so I thought it would take the starting frame as 1001.

it would not. it tries to start at 0, 1, …, 4 but certainly it can’t guess to start at 1001.

you should

  • use the pattern 610_002_UD_v001.1%03d.jpg instead. that’ll look at files 1000 to 1999
  • or relabel your images
  • or read them using imread and you’d generate the paths from your specific knowledge of the sequence

As you suggested I tried the 1 st option and tried 1%03d format. but the image is 3840x2160 resolution and my display has resolution of 1920x1080. so it is not displaying the complete image. so tried resizing the image. but it is displaying only the 1 st image for the sequence.
I searched for the sequence error, so is that anything to do with the ffmpeg build for opencv? I have done pip install opencv so the cmake build procedure is not working can you suggest me a way?

that’s another problem.

create a window using cv.namedWindow("somename", cv.WINDOW_NORMAL). that makes it resizable

next problem.

image sequences are not handled by ffmpeg. don’t go there. this is purely reading of image files, like imread would do.

the code you gave in the first post should display all frames. if it doesn’t, I need more information.

  • post a list of all image file names
  • insert statements into your code. insert print("ret:", ret) in the loop after imSeq.read(). run the code. post the text output.

Image Sequence Naming: images_0000.jpg, …, images_0014.jpg

As you suggested to add cv2.namedWindow it is jus displaying a output window but the image window is displaying incomplete 1 image only.

and the print(“ret”, ret) statement output

ret: True

d:\software\scripts\nikscr\opencvtest.py(9)()
→ while(imSeq.isOpened()):
(Pdb)
Process finished with exit code -805306369 (0xCFFFFFFF)

import cv2
 
imSeq = cv2.VideoCapture(r"D:\software\scripts\NikScr\img\images_%04d.jpg")
cv2.namedWindow("Sequence of Images", cv2.WINDOW_NORMAL)

if(imSeq.isOpened() == False):
    print("Error opening the video")
 
while(imSeq.isOpened()):
    ret, frame = imSeq.read()
    print("ret:", ret)
 
    if ret == True:
        cv2.imshow("Frames",frame)
 
        if cv2.waitKey(25):
            breakpoint()
    else:
        break
 
imSeq.release()
cv2.destroyAllWindows()

This is the updated code. Please jus check if I made any mistake or something I’m missing. Please

you need to use exactly the same window name for namedWindow() and imshow()

thank you so much it now opening in the same window but the image sequence is not playing, only 1 image is being displayed. If I try to drag and maximize or minimize the window it is not responding and the window exists. Does it have anything to do with the version of python and opencv? I’m using python 3.9 and the latest opencv 4.5.2.54

do this instead.

import cv2

imSeq = cv2.VideoCapture(r"D:\software\scripts\NikScr\img\images_%04d.jpg")
assert imSeq.isOpened()

cv2.namedWindow("window", cv2.WINDOW_NORMAL)

counter = 0
while True:
	ret, frame = imSeq.read()
	if not ret: break

	counter += 1
	print("count:", counter)

	cv2.imshow("window", frame)

	if cv2.waitKey(1000) != -1: # (-1 means no key)
		break

imSeq.release()
cv2.destroyAllWindows()

I’m think your 15 pictures simply played too quickly for you to notice. 25 ms * 15 pics = half a second.

Thank you so much it is working. it is playing 1 frame per sec now. was searching for a output for image sequence for a lot of time. Finally got it thank you so much. do you have any documentation for this or something to go through to gain more knowledge regarding the sequence.?

the tutorials sections are vast and wild:

https://docs.opencv.org/master/