这里是一个示例代码。如果我删除stdafx.h文件,程序将不会编译。使用opencv在C++程序中包含stdafx.h文件的目的是什么?
的stdafx.h文件
'#pragma once
'#include "targetver.h"
'#include <stdio.h>
'#include <tchar.h>
Capture.ccp
// Capture.cpp:定义控制台应用程序的入口点。 //
'#include "stdafx.h"
'#include "string.h"
'#include "cv.h"
'#include "highgui.h"
int _tmain(int argc, char ** argv[])
{
CvCapture * pCapture = 0;
IplImage * pVideoFrame = 0;
int i;
char filename[50];
//Initialize vieo capture
pCapture = cvCaptureFromCAM(CV_CAP_ANY);
if(!pCapture)
{
fprintf(stderr, "failed to initialize video capture\n");
return -1;
}
//Capture three video frames and write them as files
for(i=0;i<20;i++)
{
pVideoFrame = cvQueryFrame(pCapture);
if(!pVideoFrame)
{
fprintf(stderr, "failed to get a video frame\n");
}
//Write the captured video frame as an image file
sprintf(filename, "VideoFrame%d.jpg", i+1);
if(!cvSaveImage(filename, pVideoFrame))
{
fprintf(stderr, "faile dto write image file %s\n", filename);
}
//IMPORTANT : Don't release or modify the image returned
//from cvQueryFrame() !
}
//Terminate video capture and free capture resources
cvReleaseCapture(&pCapture);
return 0;
}
什么是StdAfx.h文件的目的 - 这个文件的方式自动生成。
非常感谢
请不要使用#pragma一次,它不是C++,它依赖于编译器。改为使用包含警卫(http://en.wikipedia.org/wiki/Include_guard)。 – Scharron 2010-07-21 12:47:47
TKS Scharron我会做 – Haxed 2010-07-21 12:52:42