python rgb bgr_Python OpenCV/PIL颜色_BGR2RGB E

我编写了一些Python代码,它从视频中提取帧,并将其中的几个帧以jpeg格式放入行/列中。在大多数情况下,它是有效的,除了结尾。所以我假设这个错误与数组中索引超出范围有关。在import cv2, Image, os

name = raw_input('Video File (With Extension): ')

x_res = int(raw_input('Image Width (Pixels): '))

y_res = int(raw_input('Image Height (Pixels): '))

rows = int(raw_input('Number of Rows: '))

columns = int(raw_input('Number of Columns: '))

vidcap = cv2.VideoCapture(name)

_,im = vidcap.read()

frames = int(vidcap.get(cv2.CAP_PROP_FRAME_COUNT))

new_im = Image.new('RGB', (x_res, y_res))

x_cntr = 0

y_cntr = 0

if not os.path.exists('./' + name + ' Output/'):

os.makedirs('./' + name + ' Output/')

for x in xrange(0,frames,1):

if x%(rows*columns) == 0:

new_im.save('./' + name + ' Output/' + str(x) + '.jpg')

new_im = Image.new('RGB', (x_res,y_res))

y_cntr = 0

x_cntr = 0

print str(round(100*(float(x)/frames), 1)) + "% Complete"

elif x%rows == 0:

x_cntr = 0

y_cntr = y_cntr + y_res/columns

elif x%1 == 0:

x_cntr = x_cntr + x_res/rows

_,cv2_im = vidcap.read()

cv2_im = cv2.cvtColor(cv2_im,cv2.COLOR_BGR2RGB)

im = Image.fromarray(cv2_im)

im = im.resize((x_res/rows + x_res%rows, y_res/columns + y_res%columns), Image.ANTIALIAS)

new_im.paste(im, (x_cntr, y_cntr))

当它要生成最后一个图像时,它将返回此值:

^{pr2}$

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值