这是一个python代码,用VideoCapture
openCV
模块读取图像的序列(0.jpg ... 1052.jpg)。
import cv2
import numpy
cap = cv2.VideoCapture("/path to/RGB/I%04d.jpg",cv2.CAP_IMAGES).
while(1):
ret,frame = cap.read()
cv2.imshow('image',frame)
cv2.waitKey()
print(frame.shape)
我收到此错误 OpenCV错误:imshow中的断言失败(size.width> 0& size.height> 0)。看来框架对象是空的!
答案 0 :(得分:0)
cap = cv2.VideoCapture("<path>/%04.jpg",cv2.CAP_IMAGES)
将您的图像重命名为3个零填充到左侧的sinze%04垫片,左侧为零以保留数字,如:0001,0002,...,1000等。
或者我会运行一个for循环,从1,2,...,n迭代并从那里捕获img名称然后用以下方法进行图像读取:
import cv2
import numpy
# Make sure range starts correctly.
nbrofpictures = 1000
for x in range(1, nbrofpictures):
#make sure path is correct.
path = '/<yourpath>/%d.jpg' % x
print (path)
frame = cv2.imread(path)
cv2.imshow('image',frame)
cv2.waitKey()
print(frame.shape)
答案 1 :(得分:0)
问题来自图像文件的名称。
1)脚本shell重命名文件。
images=$(for i in `ls *.jpg`; do LEN=`expr length $i`; echo $i; done | sort -n)
j=1
for i in $images; do
new=$(printf "%04d.jpg" "$j") #04 pad to length of 4
mv -i -- "$i" "$new"
let j=j+1
#we can add a condition on j to rename just the first 999 images.
done
2)读取图像序列图像:
import cv2
import numpy
cap = cv2.VideoCapture("/path to/RGB/I%04d.jpg",cv2.CAP_IMAGES).
while(1):
ret,frame = cap.read()
cv2.imshow('image',frame)
cv2.waitKey()
print(frame.shape)