Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
保存Opencv图像_Opencv - Fatal编程技术网

保存Opencv图像

保存Opencv图像,opencv,Opencv,您好,我有一个在OpenCV(C API)中运行的窗口,我想从该窗口保存一系列图像,而不必保存上一个图像。因此,在一段时间后,窗口应该保存刷新,然后保存和刷新等,我的计算机上应该有多个图像。我还没有完全做到这一点,但我正在尝试这样做: if (counter>=300) { int counterimg=1; //reset background to black cvSet(imgScribble,cvScalar(0,0,0); //save image to file cvSav

您好,我有一个在OpenCV(C API)中运行的窗口,我想从该窗口保存一系列图像,而不必保存上一个图像。因此,在一段时间后,窗口应该保存刷新,然后保存和刷新等,我的计算机上应该有多个图像。我还没有完全做到这一点,但我正在尝试这样做:

if (counter>=300)  {
int counterimg=1;
//reset background to black
cvSet(imgScribble,cvScalar(0,0,0);
//save image to file 
cvSaveImage("/Documents/testframe.jpg" [counterimg], frame); 
counter=0;
//increase counter for saving
counterimg+=1;  
}

您只需要创建一个带有图像索引的路径名:

char path[512];
snprintf(path, 512, "/Documents/testframe%03d.jpg", counterimg);
cvSaveImage(path, frame);

“%03d”将被“000”、“001”、“002”等替换。

一个用增量名称将图像保存到文件的示例,如
capture001.jpg
capture002.jpg
capture003.jpg

char path[255];
char num[10];
char jpg[10] = ".jpg";
int counter = 0;

while (1) {
    // To save 20 images
    if (counter < 20) {
        strcpy(path, "c:\\capture");
        sprintf(num, "%03i", counter);
        strcat(path, num);   
        strcat(path, jpg);
        printf("Saving: %s\n", path);
        cvSaveImage(path, frame);
        counter++;
    }
    // Press ESC to break loop
    char ch = waitKey(25);              
    if (ch == 27) break;
}
char路径[255];
字符数[10];
char jpg[10]=“.jpg”;
int计数器=0;
而(1){
//保存20张图片
如果(计数器<20){
strcpy(路径,“c:\\capture”);
sprintf(num,“%03i”,计数器);
strcat(路径,num);
strcat(path,jpg);
printf(“保存:%s\n”,路径);
cvSaveImage(路径、帧);
计数器++;
}
//按ESC键以断开循环
char ch=等待键(25);
如果(ch==27)中断;
}

谢谢您的帮助,但这只保存了001而不是增量,而且还保存了testframe310720:?我想您已经意识到了,因为我的评论有点晚了,但您只需要执行
counterimg++以获取不同的数字。