int fr = 0;
double t_total = 0.0;
int fps = 0;
double t_prev = 0;
double t_curr;
char mybuffer[250];
int main(int argc, char ** argv) {
Size S2 = Size(1920,1080);//显示分辨率
cout <<"显示分辨率:"<< S2 << endl;
VideoCapture cap;
cap = VideoCapture(0, CAP_DSHOW);
if (!cap.isOpened())
{
cout << "wrong open camera" << endl;
return -1;
}
cap.set(CV_CAP_PROP_FOURCC, CV_FOURCC('M', 'J', 'P', 'G'));
cap.set(CAP_PROP_FPS, 120);
cap.set(CV_CAP_PROP_FRAME_WIDTH, camera_width);
cap.set(CV_CAP_PROP_FRAME_HEIGHT, camera_height);
double ffff = cap.get(CV_CAP_PROP_FPS);
cout << ffff << endl;
cvNamedWindow("face");
//去除标题栏
HWND hWnd = (HWND)cvGetWindowHandle("face");
HWND hRawWnd = ::GetParent(hWnd); //获得父窗口句柄
//ShowWindow(hWnd, 0); //0:的时候表示隐藏子窗口
//ShowWindow(hRawWnd, 0); //0:的时候表示隐藏父窗口
//SetWindowLong(hWnd, GWL_STYLE,WS_CAPTION);
LONG lStyle = ::GetWindowLong(hRawWnd, GWL_STYLE);
::SetWindowLong(hRawWnd, GWL_STYLE, lStyle & ~WS_CAPTION);
::SetWindowLong(hWnd, GWL_STYLE, lStyle & ~WS_CAPTION);
::SetWindowPos(hRawWnd, NULL, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED);
t_curr = t_prev = (double)cvGetTickCount();
for (;;)
{
//Mat img;
Mat frame;
cap >> frame;
if (!frame.data)
break;
fr++;
if (fr % 20 == 0)//每20帧统计一次帧率
{
t_curr = (double)cvGetTickCount();
double t_proc = (t_curr - t_prev) / (cvGetTickFrequency() * 1000);
fps = 20.0*1000.0 / t_proc;
t_prev = t_curr;
}
//将帧率在界面上画出
string num = to_string(fps);
putText(frame, num, Point(550, 20), 0, 0.8, Scalar(0, 127, 255));
int c = waitKey(1);
if (c == 'q' || c == 27) {
printf("q or esc to exit\n");
break;
}
switch (c) {
case 'c':
{
char buffer[10];
sprintf_s(buffer, "%d", fr);
std::string tet(buffer);
imwrite(".\\data\\right" + tet + ".jpg", right);
printf("%d.jpg saved\n", fm);
}
break;
}
resize(frame, frame, S2);
imshow("face", frame);
}
return 0;
}