我需要保存图像帧,文件名作为时间戳。我尝试通过
time.time()
函数中的 cv2.putText()
函数添加时间戳,它只是在每个帧上写入 time.time()
而不是时间戳。
我尝试通过
time.time()
函数中的 cv2.putText()
函数添加时间戳,但它只是在每个帧上写入 time.time()
而不是时间戳。
我还尝试使用
time.time()
代替 cv2.imwrite()
函数的图像名称,并且它也不添加时间戳。
font = cv2.FONT_HERSHEY_SIMPLEX
cv2.putText(frame,'time.time()',(10,500), font, 4,(255,255,255),2,cv2.CV_AA).
cv2.imwrite('str(time.time())'+str(i)+'.jpg',frame)
`
The issue is resolved by putting str(time.time()).``
目前,您在引号中包含
time.time()
,因此它实际上将文本设置为名为“time.time()”的字符串。要显示 time.time()
的实际值,请删除引号。从文档来看, cv2.putText()
采用 str
作为第二个参数。这是定义
cv2.putText(img, text, org, fontFace, fontScale, color[, thickness[, lineType[, bottomLeftOrigin]]])
因此,在您的情况下,您可以将
time.time()
的值转换为这样的 str
类型
cv2.putText(frame, str(time.time()), (10,500), font, 4, (255,255,255), 2, cv2.CV_AA)
与
cv2.imwrite()
类似,您可以将值转换为str
类型来获取时间戳,而不是文字字符串
cv2.imwrite(str(time.time()) + '_' + str(i) + '.jpg', frame)