经过不断的测试终于试验好了
#include <iostream>
#include <cv.h>
#include <highgui.h>
using namespace std;
using namespace cv;
int main( int argc, char** argv )
{
VideoCapture cap(0); //打开默认的摄像头号
Mat edges;
namedWindow("edges",1); //边缘的窗口
namedWindow("video",1); //正常摄像头视频
int num = 0;
cap.open(num);
for(;;) //也可换为while(1)
{
Mat frame;
cap >> frame; // 从摄像头中获取新的一帧
if ( !frame.empty() ) imshow("Video", frame);//摄像头部分到这就结束了,下面全是关于轮廓的
cvtColor(frame, edges, CV_BGR2GRAY);
GaussianBlur(edges, edges, Size(7,7), 1.5, 1.5);
Canny(edges, edges, 0, 30, 3);
imshow("edges", edges);
if(waitKey(30) >= 0) break;
}
return 0;
}
最简单的打开摄像头视频程序
#include <iostream>
#include <cv.h>
#include <highgui.h>
using namespace std;
using namespace cv;
int main( int argc, char** argv )
{
VideoCapture cap(0);
cap.open(0);
// namedWindow("edges",1);
while(1)
{
Mat frame;
cap >> frame;
if ( !frame.empty() ) imshow("Video", frame);
if(waitKey(30) >= 0) break;
}
cap.release();
return 0;
}
简单视频
#include "cv.h"
#include "highgui.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <math.h>
#include <float.h>
#include <limits.h>
#include <time.h>
#include <ctype.h>
int main()
{
cv::VideoCapture capture("1.mp4");//dssssssssssss
if(!capture.isOpened())
return 1;
bool stop(false);
cv::Mat frame;
cv::namedWindow("extracted");
while(!stop)
{
if(!capture.read(frame))
break;
cv::imshow("extracted frame",frame);
if(cv::waitKey(10)>0)
stop=true;
}
capture.release();
}
感谢这位朋友给出了起步代码:http://blog.csdn.net/BrikOff/article/details/21243491