在viscual studio2008中添加自定义向导,以添加opencv wizard为例
1、在x:/Program Files/Microsoft Visual Studio 9.0/VC/vcprojects中添加文件夹OpenCVWiz,此目录即为新建项目时在左侧项目列表出现的项目名称。如下图所示:
2、在OpenCVWiz目录中添加文件OpenCVWiz.vsdir,内容如下:
../OpenCVconsole.vsz|0|OpenCV console application|1|Create a OpenCV console application|0|0|0|OpenCVconsoleApp
../OpenCVwin32.vsz|0|OpenCV win32 application|1|Create a OpenCV win32 application|0|0|0|OpenCVwin32App
3、在目录x:/Program Files/Microsoft Visual Studio 9.0/VC/vcprojects中添加OpenCVconsole.ico和OpenCVconsole.vsz,OpenCVconsole.vsz内容如下:
VSWIZARD 7.0
Wizard=VsWizard.VsWizardEngine.9.0
Param=”WIZARD_NAME = OpenCV”
Param=”RELATIVE_PATH = VCWizards/AppWiz/Generic”
Param=”CONSOLE_TYPE_ONLY = true”
同上添加OpenCVwin32.ico和OpenCVwin32.vsz,OpenCVwin32.vsz内容如下:
VSWIZARD 7.0
Wizard=VsWizard.VsWizardEngine.9.0
Param=”WIZARD_NAME = OpenCV”
Param=”RELATIVE_PATH = VCWizards/AppWiz/Generic”
Param=”CONSOLE_TYPE_ONLY = false”
4、在目录x:/Program Files/Microsoft Visual Studio 9.0/VC/VCWizards/AppWiz/Generic中添加目录opencv,目录内容可拷贝CustomWizard,只需要修改其中的scripts/2052/default.js,修改后内容如下,注释// Add for OpenCV后面的内容为增加的内容。
// Copyright (c) Microsoft Corporation. All rights reserved.
function OnFinish(selProj, selObj)
{
try
{
var strProjectPath = wizard.FindSymbol(“PROJECT_PATH”);
var strProjectName = wizard.FindSymbol(“PROJECT_NAME”);
var bEmptyProject = wizard.FindSymbol(“EMPTY_PROJECT”);
wizard.AddSymbol(“RC_FILE_NAME”,CreateSafeRCFileName(strProjectName) + “.rc”);
selProj = CreateProject(strProjectName, strProjectPath);
selProj.Object.Keyword = “Win32Proj”;
AddCommonConfig(selProj, strProjectName);
var strAppType = GetAppType();
AddSpecificConfig(selProj, strProjectName, bEmptyProject, strAppType);
SetupFilters(selProj);
if (!bEmptyProject)
{
SetResDlgFont();
var Pch = wizard.FindSymbol(“PRE_COMPILED_HEADER”);
if ((strAppType == “LIB” || ((strAppType == “CONSOLE”) &&
!wizard.FindSymbol(“SUPPORT_MFC”) && !wizard.FindSymbol(“SUPPORT_ATL”))) && !Pch)
{
AddFilesToProjectWithInfFile(selProj, strProjectName);
SetNoPchSettings(selProj);
}
else
{
AddFilesToProjectWithInfFile(selProj, strProjectName);
SetCommonPchSettings(selProj);
}
}
selProj.Object.Save();
}
catch(e)
{
if (e.description.length != 0)
SetErrorInfo(e);
return e.number
}
}
function SetFileProperties(projfile, strName)
{
if (strName == “dllmain.cpp”) {
var Configs = projfile.Object.FileConfigurations;
for(var i=1;i<=Configs.Count;++i) {
var Config = Configs(i);
var CLTool = Config.Tool;
CLTool.CompileAsManaged = 0; // Force no /CLR
CLTool.UsePrecompiledHeader = 0; // No pre-compiled headers
}
}
}
function GetTargetName(strName, strProjectName, strResPath, strHelpPath)
{
try
{
var strTarget = strName;
if (strName == “readme.txt”) {
strTarget = “ReadMe.txt”;
} else if (strName == “resource.h”) {
strTarget = “Resource.h”;
} else if (strName == “small.ico”) {
strTarget = “small.ico”;
} else if (strName == “root.rc”) {
strTarget = wizard.FindSymbol(“RC_FILE_NAME”);
} else if (strName.substr(0, 4) == “root”) {
strTarget = strProjectName + strName.substr(4);
}
return strTarget;
}
catch(e)
{
throw e;
}
}
function GetAppType()
{
try
{
var strAppType = “”;
if (wizard.FindSymbol(“CONSOLE_APP”))
strAppType = “CONSOLE”;
else
{
if (wizard.FindSymbol(“WIN_APP”))
strAppType = “WIN”;
else
{
if (wizard.FindSymbol(“DLL_APP”))
strAppType = “DLL”;
else
{
if (wizard.FindSymbol(“LIB_APP”))
strAppType = “LIB”;
}
}
}
return strAppType;
}
catch(e)
{
throw e;
}
}
function AddSpecificConfig(proj, strProjectName, bEmptyProject, strAppType)
{
try
{
var bMFC = wizard.FindSymbol(“SUPPORT_MFC”);
var bATL = wizard.FindSymbol(“SUPPORT_ATL”);
var config = proj.Object.Configurations(“Debug”);
config.CharacterSet = charSetUNICODE;
if (strAppType == “LIB”)
config.ConfigurationType = typeStaticLibrary;
else if (strAppType == “DLL”)
config.ConfigurationType = typeDynamicLibrary;
var CLTool = config.Tools(“VCCLCompilerTool”);
// CLTool.PrecompiledHeaderFile = “$(OutDir)/” + strProjectName + “.pch”;
CLTool.RuntimeLibrary = rtMultiThreadedDebugDLL;
// Add for OpenCV
CLTool.AdditionalIncludeDirectories = “$(OPENCVHOME)/include”;
CLTool.RuntimeTypeInfo = true;
//end!!
var strDefines = CLTool.PreprocessorDefinitions;
if (strDefines != “”) strDefines += “;”;
strDefines += GetPlatformDefine(config);
strDefines += “_DEBUG”;
switch(strAppType)
{
case “CONSOLE”:
strDefines += “;_CONSOLE”;
if (bMFC)
config.UseOfMFC = useMfcDynamic;
if (bATL)
config.UseOfATL = useATLStatic;
break;
case “LIB”:
strDefines += “;_LIB”;
if (bMFC)
config.UseOfMFC = useMfcDynamic;
break;
case “DLL”:
strDefines += “;_WINDOWS;_USRDLL;”;
var strExports = wizard.FindSymbol(“UPPER_CASE_SAFE_PROJECT_IDENTIFIER_NAME”) + “_EXPORTS”;
strDefines += strExports;
if (bMFC)
config.UseOfMFC = useMfcDynamic;
if (bATL)
config.UseOfATL = useATLStatic;
break;
case “WIN”:
strDefines += “;_WINDOWS”;
if (bMFC)
config.UseOfMFC = useMfcDynamic;
if (bATL)
config.UseOfATL = useATLStatic;
break;
default:
break;
}
CLTool.PreprocessorDefinitions = strDefines;
if (bEmptyProject)
CLTool.UsePrecompiledHeader = pchNone;
CLTool.DebugInformationFormat = debugEditAndContinue;
if (strAppType != “LIB”)
{
var LinkTool = config.Tools(“VCLinkerTool”);
LinkTool.GenerateDebugInformation = true;
LinkTool.LinkIncremental = linkIncrementalYes;
if (strAppType == “DLL” || strAppType == “WIN”)
LinkTool.SubSystem = subSystemWindows;
else
LinkTool.SubSystem = subSystemConsole;
// Add for OpenCV
//LinkTool.IgnoreDefaultLibraryNames = “libcmt.lib”;
LinkTool.AdditionalLibraryDirectories = “$(OPENCVHOME)/lib”
LinkTool.AdditionalDependencies= “cvd.lib cxcored.lib highguid.lib cvauxd.lib cxtsd.lib mld.lib”;
//end!!
}
config = proj.Object.Configurations.Item(“Release”);
config.CharacterSet = charSetUNICODE;
if (strAppType == “LIB”)
config.ConfigurationType = typeStaticLibrary;
else if (strAppType == “DLL”)
config.ConfigurationType = typeDynamicLibrary;
var CLTool = config.Tools(“VCCLCompilerTool”);
CLTool.RuntimeLibrary = rtMultiThreadedDLL;
// Add for OpenCV
CLTool.AdditionalIncludeDirectories = “$(OPENCVHOME)/include”;
CLTool.RuntimeTypeInfo = true;
//end!!
var strDefines = CLTool.PreprocessorDefinitions;
if (strDefines != “”) strDefines += “;”;
strDefines += GetPlatformDefine(config);
strDefines += “NDEBUG”;
if (bEmptyProject)
CLTool.UsePrecompiledHeader = pchNone;
CLTool.DebugInformationFormat = debugEnabled;
switch(strAppType)
{
case “CONSOLE”:
strDefines += “;_CONSOLE”;
if (bMFC)
config.UseOfMFC = useMfcDynamic;
if (bATL)
config.UseOfATL = useATLStatic;
break;
case “LIB”:
strDefines += “;_LIB”;
if (bMFC)
config.UseOfMFC = useMfcDynamic;
break;
case “DLL”:
strDefines += “;_WINDOWS;_USRDLL;”;
var strExports = wizard.FindSymbol(“UPPER_CASE_SAFE_PROJECT_IDENTIFIER_NAME”) + “_EXPORTS”;
strDefines += strExports;
break;
case “WIN”:
strDefines += “;_WINDOWS”;
if (bMFC)
config.UseOfMFC = useMfcDynamic;
if (bATL)
config.UseOfATL = useATLStatic;
break;
default:
break;
}
CLTool.PreprocessorDefinitions = strDefines;
if (strAppType != “LIB”)
{
var LinkTool = config.Tools(“VCLinkerTool”);
LinkTool.GenerateDebugInformation = true;
LinkTool.LinkIncremental = linkIncrementalNo;
if (strAppType == “DLL” || strAppType == “WIN”)
LinkTool.SubSystem = subSystemWindows;
else
LinkTool.SubSystem = subSystemConsole;
// Add for OpenCV
//LinkTool.IgnoreDefaultLibraryNames = “libcmt.lib”;
LinkTool.AdditionalLibraryDirectories = “$(OPENCVHOME)/lib”
LinkTool.AdditionalDependencies= “cv.lib cxcore.lib highgui.lib cvaux.lib cxts.lib ml.lib”;
//end!!
}
}
catch(e)
{
throw e;
}
}
// SIG // Begin signature block
//……
最后,在/templates/2052/stdafx.h中添加opencv需要用到的头文件即可,内容如下:
// include file for opencv
#include <cv.h>
#include <cxcore.h>
#include <highgui.h>
#include <cvaux.h>
#include <ml.h>