A
aldonnelley
Hi there.
I'm just learning c++, and this is driving me nuts.
I'm trying to save image files generated in a for loop with a filename
built using strcat with:
- a char base file name
+ a character to identify the individual files that is indexed from a
char array by the int index of the for loop
+ a char file extension.
I keep getting a "cannot convert 'int' to 'const char'" error on the
line where I'm trying to strcat the character I've indexed from the
char array to the base file name. (script attached)
Can anyone tell me what is happening here, and how to fix it?
Cheers, Al.
//code starts
for(i=0;i<(faces ? faces->total:0); i++ )
{
const char arr[25] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
'j', 'k', 'l', 'm', 'n', 'o',
'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y' };
CvRect* r = (CvRect*)cvGetSeqElem( faces, i );
pt1.x = ( r->x + 0.08*(r->width));
pt2.x = ( r->x + 0.92*(r->width));
pt1.y = (r->y );
CvRect reg;
reg.x = pt1.x;
reg.y = pt1.y;
reg.width = abs( pt2.x - pt1.x);
reg.height = (r->height);
image->roi = NULL;
cvSetImageROI (image, reg);
region = cvCreateImage(cvSize (reg.width, reg.height), image->depth,
image->nChannels);
cvCopy (image, region, 0);
char fileindex = arr;
fileindex = ( const char ) fileindex;
char fileName[50] = "output";
char str[60];
strcpy (str, fileName);
strcat (str, fileindex); //compiler doesn't like this at
all...
strcat (str, ".jpg");
puts(str);
cout << str << endl;
cvSaveImage( str, region);
cvResetImageROI(image);
cvRectangle(image, pt1, pt2, CV_RGB(255, 0, 0), 3, 8, 0);
//code ends
I'm just learning c++, and this is driving me nuts.
I'm trying to save image files generated in a for loop with a filename
built using strcat with:
- a char base file name
+ a character to identify the individual files that is indexed from a
char array by the int index of the for loop
+ a char file extension.
I keep getting a "cannot convert 'int' to 'const char'" error on the
line where I'm trying to strcat the character I've indexed from the
char array to the base file name. (script attached)
Can anyone tell me what is happening here, and how to fix it?
Cheers, Al.
//code starts
for(i=0;i<(faces ? faces->total:0); i++ )
{
const char arr[25] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
'j', 'k', 'l', 'm', 'n', 'o',
'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y' };
CvRect* r = (CvRect*)cvGetSeqElem( faces, i );
pt1.x = ( r->x + 0.08*(r->width));
pt2.x = ( r->x + 0.92*(r->width));
pt1.y = (r->y );
CvRect reg;
reg.x = pt1.x;
reg.y = pt1.y;
reg.width = abs( pt2.x - pt1.x);
reg.height = (r->height);
image->roi = NULL;
cvSetImageROI (image, reg);
region = cvCreateImage(cvSize (reg.width, reg.height), image->depth,
image->nChannels);
cvCopy (image, region, 0);
char fileindex = arr;
fileindex = ( const char ) fileindex;
char fileName[50] = "output";
char str[60];
strcpy (str, fileName);
strcat (str, fileindex); //compiler doesn't like this at
all...
strcat (str, ".jpg");
puts(str);
cout << str << endl;
cvSaveImage( str, region);
cvResetImageROI(image);
cvRectangle(image, pt1, pt2, CV_RGB(255, 0, 0), 3, 8, 0);
//code ends