//
# include "stdafx. H"
# include "ConsoleApplication3. H"
# include "stdafx. H"
#include
#include
#include
#include
#include
#include
#include
#include
# ifdef _DEBUG
# define new DEBUG_NEW
# endif
//the only application objects
CWinApp theApp;
using namespace std;
Using the namespace CV;
Int main ()
{
Int nRetCode=0;
HMODULE HMODULE=: : GetModuleHandle (nullptr);
If (hModule!=nullptr)
{
//initialize the MFC and display an error when failure
if (! AfxWinInit (hModule nullptr, : : GetCommandLine (), 0))
{
//TODO: change the error code to fit your needs
Wprintf (L "error: [English] failed to initiate the MFC \ n");
NRetCode=1;
}
The else
{
//TODO: here is the behavior of the application code,
}
}
The else
{
//TODO: change the error code to fit your needs
Wprintf (L "error: GetModuleHandle failed \ n");
NRetCode=1;
}
VideoCapture cap;
Int CNT=0;
Char pname [100].
STD: : cout & lt; <"Please enter the camera serial number" & lt;
Int capNum=atoi (pname);
STD: : cout & lt; <"Please enter the resolution size: \
00 1:6 40 * 480 2:8 24 * 768 * 600 3:10 "& lt;
Int frameNum=atoi (pname);
Cap. Open (capNum);
The switch (frameNum)
{
Case 1:
{
Cap. Set (CV_CAP_PROP_FRAME_WIDTH, 640);
Cap. Set (CV_CAP_PROP_FRAME_HEIGHT, 480);
break;
}
Case 2:
{
Cap. Set (CV_CAP_PROP_FRAME_WIDTH, 800);
Cap. Set (CV_CAP_PROP_FRAME_HEIGHT, 600);
break;
}
Case 3:
{
Cap. Set (CV_CAP_PROP_FRAME_WIDTH, 1024);
Cap. Set (CV_CAP_PROP_FRAME_HEIGHT, 768);
break;
}
Default:
Cap. Set (CV_CAP_PROP_FRAME_WIDTH, 640);
Cap. Set (CV_CAP_PROP_FRAME_HEIGHT, 480);
}
if (! Cap. IsOpened ())
{
STD: : cerr & lt; <"Always read a video. Try moving video file to sample directory." & lt;
}
NamedWindow (" FG Segmentation, "WINDOW_NORMAL);
Mat frame;
Mat edges;
CTime time=CTime: : GetCurrentTime ();///constructs CTime object
Int m_nYear=time. GetYear ();///
Int m_nMonth=time, GetMonth ();///
Int m_nDay=time. GetDay ();///day
Int m_nHour=time. GetHour ();
///hour
Int m_nMinute=time. GetMinute ();///minute
Int m_nSecond=time. GetSecond ();///s
Cstrings m_strTime=time. The Format (" % % m - Y % d - m - H - % % % S ");
String path;
The string filename.
String a;
A=m_strTime. GetBuffer (0);
M_strTime. ReleaseBuffer ();
Filename=D \ \ PHOTOS_M \ \ "" + a;
Path="md D: \ \ PHOTOS_M \ " + a;
System (path. C_str ());
Cout & lt; <"Folder" & lt;
For (;; )
{
Cap & gt;> Frame;
Cap & gt;> Frame;
If (frame. The empty ())
break;
Frame. CopyTo (edges);
Imshow (FG "Segmentation", edges);
//STD: : cout & lt;
Char c=waitKey (30);
The switch (c)
{
In case the 's' :
{
//OFSTRUCT OFSTRUCT;
//OpenFile (filename. C_str (), & amp; OfStruct OF_READWRITE);
String filefolder;
Filefolder=D \ \ PHOTOS_M \ \ "" + a +" \ \ % picture 4 d. BMP ";
Sprintf_s (pname, 100, filefolder c_str (), CNT);
Cnt++;
Imwrite (pname, edges);
CvWaitKey (50);
Cout & lt; <"Save photos success!"
}
Case 'q:
{
return 0;
}
Default:
break;
}
}
Return nRetCode;
}
CodePudding user response:
Imshow to save images, then check that the path under written in c: \ \ 1. JPG such a tryCodePudding user response:
Need to check for the corresponding folder