[英]do i need to add this head file “stdafx.h” to run an c++ program in windows
[英]What is the purpose of including the stdafx.h file in a C++ program using opencv
這是一個示例代碼。 如果我刪除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文件的目的是什么 - 順便說一下這個文件是自動生成的。
非常感謝
它是編譯器預編譯頭的一部分,可以加快構建速度。
正如peterchen所說,它用於加速構建並添加一些Windows內容。 這包括完全視覺工作室特定 ,如果您希望您的程序是跨平台的,則不應使用,這是Open Cv庫的情況(您可以在windows,linux下使用opencv ......)。
你的編譯錯誤信息是什么?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.