您的位置:首页 > 运维架构

directshow采集图像转换成OPENCV

2008-01-25 11:02 218 查看
#include "stdafx.h"

#include <stdio.h>

#include <cv.h>

#include "cxcore.h"

#include <highgui.h>

#include "math.h"

#include <stdio.h>

#include <ctype.h>

#include "ARFrameGrabber.h"

//#include <streams.h>

void main(int argc, char* argv[])

{

IplImage *frame =0;

static ARFrameGrabber frameGrabber; //声明对象

IplImage ds_frame;

frameGrabber.Init(0, true); //设置支持directshow的设备编号,从0开始

frameGrabber.SetFlippedImage(true); //图像是否翻转

for(;;)

{

frameGrabber.GrabByteFrame(); //获取一帧

BYTE *myBuffer = frameGrabber.GetByteBuffer(); //得到图像的缓冲

int width = frameGrabber.GetWidth();

int height = frameGrabber.GetHeight();

int stride = (width * sizeof( RGBTRIPLE ) + 3) & -4;

cvInitImageHeader( &ds_frame, cvSize(width, height), 8, 3,IPL_ORIGIN_BL, 4 ); //创建iplimage

ds_frame.widthStep = stride;

cvSetData( &ds_frame, myBuffer, stride ); //copy数据

frame = &ds_frame;

/**//* 视频分析部分 */

//int nFrmNum = 0;

cvNamedWindow("vedio",1);

cvShowImage("vedio",frame);

if (cvWaitKey(20)>=0)

break;

}

cvReleaseImage(&frame);

cvDestroyWindow("vedio");

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: