zoukankan      html  css  js  c++  java
  • 网络摄像头监控

    利用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;
    }


  • 相关阅读:
    eclipse 不自动提示和Alt + / 没提示和eclipse增强代码提示
    uboot 添加命令
    ps and kill command
    C 类型volatile 的作用
    git tutorial
    python 与命令
    C++ new and delete
    Glade3 tutorial in chinese
    查找IP与MAC
    ns3 无线资料
  • 原文地址:https://www.cnblogs.com/lgh1992314/p/5835077.html
Copyright © 2011-2022 走看看