Home > Back-end >  C how to implement carry images stored in the photo above have been dynamically create the folder
C how to implement carry images stored in the photo above have been dynamically create the folder

Time:09-19

Void TakePhotos ()
{
CascadeClassifier cascade;//load cascade analyzer
Cascade. The load (" haarcascade_frontalface_alt. XML ");//load the classifier train XML file
VideoCapture cap (0);//start camera
Mat frame;
if (! Cap. IsOpened ())
{
Cout & lt; <"The camera open failure!"
}
Char dir [200].
Char key;
Char filename [200].
int count=0;
Char STR [20].
Char * name=STR;
Printf (" \ n when when opening the camera to ensure good posture after press the blank space key input information (take pictures of more than 10 different Angle different expression), determine ");
system("pause");
Printf (" \ n please input your name abbreviations: ", & amp; STR);
The scanf (" % s ", STR);
Sprintf (dir, "D: \ \ vs2013priactice \ \ FAce_dect \ \ FAce_dect \ \ PIC \ \ % s", STR);//write to create the folder and name
_mkdir (dir);//create folders in the specified directory


NamedWindow (" [video] ", 1);
NamedWindow (" [images] ", 1);
While (1)
{
Key=waitKey (50);
Cap & gt;> Frame;
Imshow (" [video], "frame).

If (key==27)
break;//press the ESC key to exit the program
If (key==32)//press the space key to photograph 32 is the blank space key corresponding ascll code
{
STD: : vector Faces;//object defines the faces is a the RECT array
Mat frame_gray;
CvtColor (frame, frame_gray, COLOR_BGR2GRAY);//image gray processing
Cascade. DetectMultiScale (frame_gray, faces, 1.1, 4, 0, the Size (100, 100), the Size (500, 500));
For (size_t I=0; I & lt; Faces. The size (); I++)
{
A rectangle (frame, faces [I], Scalar (255, 0, 0), 2, 8, 0).//red rectangular box
}
Mat faceROI=frame_gray (faces [0]). The region of interest//ROI
Mat myFace.//set up an own face store
The resize (faceROI, myFace, Size (92, 112));//store is 92 * 112 photos please ensure good posture, because the picture too much cause error
Sprintf (filename, surprised "% s % jeter pg," dir, + + count);
Printf (" 11111111 ");
Imwrite (filename, myFace);//pictures saved to the project directory
Imshow (" [images], "myFace);
}
}
DestroyAllWindows ();
Printf (" information recorded success ");
}




//////this is the younger brother of the code,
Printf (" \ n please input your name abbreviations: ", & amp; STR);
The scanf (" % s ", STR);
Sprintf (dir, "D: \ \ vs2013priactice \ \ FAce_dect \ \ FAce_dect \ \ PIC \ \ % s", STR);//write to create the folder and name
_mkdir (dir);//create folders in the specified directory

This has created the folder
Next to the pictures to get images stored in the folder
Mat faceROI=frame_gray (faces [0]). The region of interest//ROI
Mat myFace.//set up an own face store
The resize (faceROI, myFace, Size (92, 112));//store is 92 * 112 photos please ensure good posture, because the picture too much cause error
Sprintf (filename, surprised "% s % jeter pg," dir, + + count);
Printf (" 11111111 ");
Imwrite (filename, myFace);//pictures saved to the project directory
Imshow (" [images], "myFace);
}


This folder is set according to your input
That is to say, you enter one after his own name to create a folder with the program of photos will be stored in this folder, can realize the function of this line
Thank you I bosses to help.

CodePudding user response:

Sprintf (filename, surprised "% s % jeter pg," dir, + + count);
The output filename to see if effective path name, file name and directory separator,
  • Related