Ask Your Question
0

cv2.VideoCapture() importing file seq. with numbers on the name. Is this a bug?

asked 2019-10-25 06:47:29 -0500

Paygoo gravatar image

I was trying to open a tiff file seq. with cv2.VideoCapture(), because it's easier to handle then using cv2.imread.

It works ok in general, but if the file name have numbers in the basename, (before the number padding) it only opens the first frame. looks like its messing with the padding numbers.

If the filename as numbers on the base name ( eg: test123a.000001.tif) it ignores the sequence, and reads 1st frame only.

Steps to reproduce:

Create a file sequence (eg: test123a.000001.tif, test123a.000002.tif, test123a.000003.tif, etc) or download from my share here

import cv2
import numpy

cap = cv2.VideoCapture('C:/images/5frames/test123a.' + '{:06d}'.format(1, ) + '.jpg', cv2.CAP_IMAGES)
cap.set(1, 2)# 2nd number is the frame to show
ret, frame = cap.read()

cv2.imshow("", frame)
cv2.waitKey(0)

Windows 10 pro 64bit/ Python 3.7.4/ opencv-python 4.1.1.26/

Thanks.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2019-10-28 08:47:38 -0500

supra56 gravatar image

updated 2019-10-28 11:11:56 -0500

OK! I solved format problem. You may add this for win10 cv2.CAP_IMAGES.

   #!/usr/bin/python38
    #OpenCV 4.1.2, Raspberry pi 4, Thonny IDE.
    #Date; 28th October, 2019

    import cv2 as cv
    import numpy

    cap = cv.VideoCapture('test123a.{}'.format('%06d') + '.jpg')
    #cap = cv.VideoCapture('test123a.%06d.jpg')
    cap.set(1, 2)# 2nd number is the frame to show
    ret, frame = cap.read()

    cv.imshow("Images", frame)
    cv.waitKey(0)
edit flag offensive delete link more

Comments

Btw, I couldn't do format function. Also, you can do iteration.

supra56 gravatar imagesupra56 ( 2019-10-28 08:48:43 -0500 )edit

Thank you, I had figured out before but I didn't post it because this forum won't let noobs reply to own messages. It works if legacy formatting is used (eg:'%06d'.format(1, )). The format is important because I have some sequences not beginning at 000000.jpg.

Paygoo gravatar imagePaygoo ( 2019-10-28 10:18:30 -0500 )edit

The format has been solved.

supra56 gravatar imagesupra56 ( 2019-10-28 11:12:50 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2019-10-25 06:47:29 -0500

Seen: 345 times

Last updated: Oct 28 '19