Ask Your Question
0

How to run the code repetitively and save result separately ?

asked 2013-08-14 18:57:58 -0600

Steve gravatar image

updated 2013-08-15 04:26:53 -0600

Hi, I am a beginner in Opencv and C++ programing. According to this tutorial, it is necessary to run the code manually and after all you will have just one pic saved.

I have a very basic problem, I want to run the code every second automatically and in every cycle store the pics somewhere. Could any body help me in this field?

Thank you in advance.

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
3

answered 2013-08-15 02:01:04 -0600

updated 2013-08-15 02:06:27 -0600

If you have not very large DB of pics (10-15 pics), the most easiest way to do it, is with bat file, that call your program and parse the input parameters (argc and **argv).

The other way is to use dirrent.h That is small example, that will do the job ;)

int check_ext(string path)   //only images
{
    string ext[]={"BMP","DIB","JPEG","JPG","JPE","PNG","PBM","PGM","PPM","SR","RAS","TIFF","TIF"
            ,"bmp","dib","jpeg","jpg","jpe","png","pbm","pgm","ppm","sr","ras","tiff","tif"};
    for(unsigned int i=0;i<(sizeof(ext)/sizeof(ext[0]));i++)
    {
        if(path.substr(path.find_last_of(".") + 1) == ext[i])return 1;
    }
    return 0;
}

//someware open files
if ((dir = opendir ((path).c_str())) != NULL)
{
    while ((ent = readdir (dir)) != NULL)
    {
        if(check_ext(ent->d_name))Mat img = imread(path+"\\"+ent->d_name);
        //processing               
        imwrite(outputdir+"\\"+ent->d_name,img);
    }
}
edit flag offensive delete link more

Comments

@Spas Hristov Thank you. Since I want to run it consecutively, there would be huge number of images that after a while I should compare them and delete the repetitive. So it seems the second one is better but I am not sure where I can add these to the source code.

Steve gravatar imageSteve ( 2013-08-15 19:18:02 -0600 )edit
1

answered 2013-08-15 01:26:46 -0600

Moster gravatar image

updated 2013-08-15 01:29:51 -0600

I guess the simplest way would be some while or for loop and put some sleep at the end of the loop, so that it wait until the next execution.

For the different images, you could do it like this. Take a simple image name and always concatenate it with a number in every loop. You could use the loop variable i or just increase an int after every loop.

Could look like this in c++:

    char *imageName = "image"; 
    char *jpgN = ".jpg";
    stringstream s;
    s << imageName << i << jpgN;

Then you can use imwrite (s.str(), image);

edit flag offensive delete link more

Comments

@Moster Thank you man. The loop is the way which I already guessed, but I couldn't implement it in the code. This time I will try again with your idea.

Steve gravatar imageSteve ( 2013-08-15 19:22:48 -0600 )edit

Question Tools

Stats

Asked: 2013-08-14 18:57:58 -0600

Seen: 461 times

Last updated: Aug 15 '13