利用opencv,原来如此简单!
代码自动实现每隔60秒自动拍照,再依托于百度云等服务,就可以简单的实现监控功能了=。=
#include <stdio.h>
#include <highgui.h>
#include <windows.h>
#include <stdlib.h>
#include <time.h>
#pragma warning (disable : 4996)
int main()
{
IplImage *pImg = NULL;
CvCapture *cap = cvCaptureFromCAM(0);
char fileName[100];
char key;
time_t t;
int sec;
struct tm* cur;
char temp[64];
while(true)
{
pImg = cvQueryFrame(cap);
cvFlip(pImg, NULL, 1); //水平翻转图像,像照镜子一样,不想要这个效果可以去掉此句
key = cvWaitKey(50);
t = time(NULL);
cur = localtime(&t);
sec = cur->tm_sec;
if(key == 27)
{
break;
}
else if(sec % 60 == 0)
{
t = time(NULL);
strftime( temp, sizeof(temp), "%Y%m%d%H%M%S", localtime(&t));
sprintf(fileName, "d:\\百度云\\data\\%s.jpg", temp); //按日期生成文件名
printf(fileName, "d:\\百度云\\data\\%s.jpg", temp);
printf("\n");
cvSaveImage(fileName, pImg);
cvXorS(pImg, cvScalarAll(255), pImg); //将拍到的图像反色(闪一下形成拍照效果)
cvShowImage("Camera", pImg);
cvWaitKey(200); //反色图像显示ms
}
cvShowImage("Camera", pImg);
}
cvReleaseCapture(&cap);
return 0;
}