What is the purpose of including the stdafx.h file in a C++ program using opencv
here is a sample code. If I remove the stdafx.h file, the program wont compile.
stdafx.h file
'#pragma once
'#include "targetver.h"
'#include <stdio.h>
'#include <tchar.h>
Capture.ccp
// Capture.cpp : Defines the entry point for the console application. //
'#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;
}
What is the purpose of the stdafx.h file - this file by the way is generated automatically.
Many Thanks
It's part of the compilers Precompiled Header to speed up builds.
As says peterchen, it's used to speedup builds and add some Windows stuff. This include is totally visual studio specific, and shall not be used if you want your program to be cross platform, which is the case of Open Cv library (you can use opencv under windows, linux, ...).
What is your compilation error message ?
精彩评论