1

Hy .what I am trying to do is load a bunch of images,resize them and save the resized image to another folder.it loads the images ,I checked ,and works ok , the only problem i have is with cvSaveImage. for example:

char num[350]="C:\\Users\\Alex\Desktop\\pozeTiles\\image";  
char str[10];      
char pmp[10]=".bmp";    
itoa(index, str, 10);                     
strcat(num,str);   
strcat(num,pmp);     

cvNamedWindow("Testimage", HG_AUTOSIZE);    
cvShowImage("Testimage", img);    
IplImage *imgA = resizeImage(img,20,20, true);    
cvSaveImage(num, imgA);    
cvWaitKey(0);    
cvReleaseImage(&img);    
cvDestroyWindow("Testimage");    
index++;

This is inside a loop and it does not work (for now is just 1 photo).If i change cvSaveImage atribute to :

 cvSaveImage("d:\\d.bmp", imgA);

it works.The problem is that i have multiple file and i cannot change the name for each one ..so can someone pls help me ?What parameter should i use so it should work?

3 Answers 3

2

Right before cvSaveImage() add a debug statement like printf("Saving: %s\n", num);.

Also, you are not checking the return of cvSaveImage(). This is awful because the function could be failing due to a number of reasons:

if (!cvSaveImage(num, imgA))
{
    printf("!!! cvSaveImage failed for %s\n", num);
    // break or exit()
}

Most probably you are assembling the wrong directory path. The debug I suggested you to add will tell you that. Let's do a step-by-step of your code:

char num[350]="C:\\Users\\Alex\Desktop\\pozeTiles\\image.jpg";  
char str[10];      
char pmp[10]=".bmp";    
itoa(index, str, 10);

strcat(num,str);   
// if num was "C:\\Users\\Alex\Desktop\\pozeTiles\\image.jpg"
// right now it should be: "C:\\Users\\Alex\Desktop\\pozeTiles\\image.jpgX"
// where X is the index number.

strcat(num,pmp);
// at this point, num will be:
// "C:\\Users\\Alex\Desktop\\pozeTiles\\image.jpgX.bmp"
Sign up to request clarification or add additional context in comments.

1 Comment

Can you save the image to "C:\\d.bmp" ? I would try to increment the directory name word by word. On some directories you may not have permissions to write.
2

int main(int argc, char* argv[]) {

int c=1;
IplImage* img=0;
char buffer[1000];
CvCapture* cv_cap=cvCaptureFromCAM(-1);
cvNamedWindow("Video",CV_WINDOW_AUTOSIZE);

while(1) {

  img=cvQueryFrame(cv_cap);
  cvShowImage("Video",img);
  sprintf(buffer,"D:/image%u.jpg",c);
  cvSaveImage(buffer,img);
  c++;
      if (cvWaitKey(100)== 27) break;

}

cvDestroyWindow("Video");
return 0;

}

Comments

1

Looks like you are creating the output filename wrongly, try printing the value of num inside the loop.

Or you can create the output file 1.bmp, 2.bmp etc with something like

char filename[80];

..... loop ...

sprintf(filename,"%u.bmp",counter)
cvSaveImage(filename, imgA);

1 Comment

It seems we have an OpenCV stalker. The community appreciates it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.