我希望在每次迭代时将图像保存到新文件中:
str1='vid_result'
str2=str1+str(ret)
cv2.imwrite(str(str2),im)
ret
是一个计数器。
但我收到错误:
Could not find a writer for the specified extension in function cv::imwrite_.
实际上,cv2.imwrite('vid_result',im)
工作正常,所以我需要找到一种正确的方法来发送文件名作为第一个参数。
P.S。 str2
是一个字符串,其输出为vid_result1
。
答案 0 :(得分:-1)
听起来(“指定扩展名的编写者”)就像它试图弄清楚如何根据文件名写入图像并失败。打印出from tkinter import *
root = Tk()
rc = 0
types = ['a', 'b', 'c']
type_header = Label(root, text='Select Type:', font='-weight bold')
type_header.grid(row=rc, column=0,columnspan=2, sticky=W)
rc += 1
tvar0 = StringVar(root)
tvar1 = StringVar(root)
tvar2 = StringVar(root)
type_label_0 = Label(root, text='row1:')
type_label_0.grid(row=rc, column=0, sticky=E)
type_list = OptionMenu(root, tvar0, *types, command=optc)
type_list.config(width=15)
type_list.grid(row=rc, column=1, sticky=W)
rc += 1
type_label_1 = Label(root, text='row2:')
type_label_1.grid(row=rc, column=0, sticky=E)
type_list = OptionMenu(root, tvar1, *types, command=optc)
type_list.config(width=15)
type_list.grid(row=rc, column=1, sticky=W)
rc += 1
def optc(v):
if v == 'a':
# if option 'a' selected, just have one label, and one entry box
t0_label1 = Label(root, text=' temperature:')
t0_label1.grid(row=1, column=2, sticky=E)
t0_field1 = Entry(root)
t0_field1.grid(row=1, column=3, sticky=W)
t0_field1.config(width=7)
if v == 'b':
# if option 'b', then 2 labels and 2 entry boxes
t0_label1 = Label(root, text=' height:')
t0_label1.grid(row=1, column=2, sticky=E)
t0_field1 = Entry(root)
t0_field1.grid(row=1, column=3, sticky=W)
t0_field1.config(width=7)
t0_label2 = Label(root, text=' width:')
t0_label2.grid(row=1, column=2, sticky=E)
t0_field2 = Entry(root)
t0_field2.grid(row=1, column=3, sticky=W)
t0_field2.config(width=7)
的值,我认为这会使问题变得明显。