我想使用sprintf函数将char变量作为文件名插入,如下所示。
#include <stdio.h>
#include <time.h>
#include<iostream>
#include <string.h>
char fileNameImage[1000]; // a string, containing the name of the JPG file
char fileNameGraph[1000]; // a string, the name of the graph JPG file
time_t rawtime;
struct tm * timeinfo;
char buffer [80];
time (&rawtime);
timeinfo = localtime (&rawtime);
strftime (buffer,80,"%I:%M:%S.%p-%x",timeinfo);
sprintf( fileNameImage, "%s.jpg",buffer ); // i need help here
sprintf( fileNameGraph, "%s-graph.jpg",buffer); // i need help here
imwrite( fileNameImage,frame );
flip(graph,graph,0); // flip it vertically before saving as JPG
imwrite( fileNameGraph,graph );
flip(graph,graph,0); // flip it back
file1 = fopen("Passed_objects.html","a"); // "a" is append (add at the end)
// printf to a text file
fprintf( file1, "<img src = %s><img src = %s>"
"Threshold = %d, countObjects = %d <br>\n",
fileNameImage, fileNameGraph, threshold, countObjects);
fclose(file1);
}
我正在使用此C ++代码和opencv以.jpg格式保存捕获的帧,并将当前系统时间作为其名称。但它不起作用。它不会保存任何东西。
但如果我更换,则代替那两行,
sprintf( fileNameImage, "%06d.jpg", countObjects);
sprintf( fileNameGraph, "%06d-graph.jpg", countObjects);
它的工作并保存框架。 (countobjects是int变量,在每个循环中递增)。
我的简要问题是添加时间而不是int varible。
在我提供的代码中不是整个代码......它是一个提取