Open Cascade源码 安装+配置+运行

最近导师要求开学前学习一下这个库,说实话一开始看着一头包,完全一头雾水,不过最终安下来了,总体来说一定要胆大心细!

1.下载opencascade和VS2017,安装包(百度云)贴在下面:

opencascade链接:https://pan.baidu.com/s/1UbhkF5Na5420gIsUb4VP1Q 
提取码:cqr7

下载好以后就是这样:

VS2017链接:https://pan.baidu.com/s/1l9DejZhBaCPdFOgHEvkJWw 
提取码:e6wi 

VS安装教程百度一堆,主要要注意的就是安装过程中要把ALT,MFC勾选上,如下:

2.配置系统环境变量

把下载好的opencascade里每个文件夹的bin目录都放到环境变量的PATH里,尤其注意tbb开头的文件夹中,路径要具体到bin目录下的版本号目录里,我分享的安装包版本号是vc14,可以参考我下面的截图:

然后在将bin文件夹内的dll文件全部复制一份放在C:\Windows\SysWOW64里(注意我这里是64位的),一定要一个一个文件夹找,tbb开头的就存vc14里的8个dll就行了,其他版本不用存。

3.打开VS2017

文件->新建->项目->MFC应用(随便选个存储路径)->确定->应用程序类型选择单文档->完成

4.接下来配置一下VS2017的项目属性

点击上方菜单栏的项目->最下方项目属性->VC++目录->修改一下包含目录和库目录(我的opencascade存在E盘,如果存在其他地方可以对应改一下路径)

我的包含目录是:E:\OpenCASCADE-7.4.0-vc14-64\opencascade-7.4.0\inc

我的库目录是:E:\OpenCASCADE-7.4.0-vc14-64\opencascade-7.4.0\win64\vc14\lib

接下来打开cmd,进入库目录E:\OpenCASCADE-7.4.0-vc14-64\opencascade-7.4.0\win64\vc14\lib,在此输入命令dir /b>libName.txt,把弹出来的所有lib文件名复制

点项目属性里的连接器->输入->附加依赖项,把上面复制的粘贴到这里(如果第一行粘贴上libName.lib,记得删除)

5.修改项目文件内容

打开头文件中的pch.h(或者叫stdafx.h,这是一个预编译源文件)

把下面内容复制到头文件

#include <BRepTools.hxx>  
#include <Standard_DefineHandle.hxx>  
#include <DsgPrs_LengthPresentation.hxx>  
#include <GCPnts_TangentialDeflection.hxx>  
#include <Geom_Axis2Placement.hxx>  
#include <Geom_CartesianPoint.hxx>  
#include <Geom_Line.hxx>  
#include <Geom_Surface.hxx>  
#include <BRepAdaptor_Surface.hxx>  
#include <GeomAbs_CurveType.hxx>  
#include <GeomAdaptor_Curve.hxx>  
#include <GeomTools_Curve2dSet.hxx>  
#include <gp_Vec.hxx>  
#include <Graphic3d_NameOfMaterial.hxx>  
#include <MMgt_TShared.hxx>  
#include <OSD_Environment.hxx>  
#include <Precision.hxx>  
#include <Prs3d_IsoAspect.hxx>  
#include <Prs3d_LineAspect.hxx>  
#include <Prs3d_Projector.hxx>  
#include <Prs3d_Text.hxx>  
#include <Quantity_Factor.hxx>  
#include <Quantity_Length.hxx>  
#include <Quantity_NameOfColor.hxx>  
#include <Quantity_PhysicalQuantity.hxx>  
#include <Quantity_PlaneAngle.hxx>  
#include <Quantity_TypeOfColor.hxx>  
#include <SelectMgr_EntityOwner.hxx>  
#include <SelectMgr_SelectableObject.hxx>  
#include <SelectMgr_Selection.hxx>  
#include <SelectMgr_SelectionManager.hxx>  
#include <SelectMgr_ListOfFilter.hxx>  
#include <SelectMgr_Filter.hxx>  
#include <StdSelect_EdgeFilter.hxx>  
#include <StdSelect_ShapeTypeFilter.hxx>  
#include <Standard_Boolean.hxx>  
#include <Standard_CString.hxx>  
#include <Standard_ErrorHandler.hxx>  
#include <Standard_Integer.hxx>  
#include <Standard_IStream.hxx>  
#include <Standard_Macro.hxx>  
#include <Standard_NotImplemented.hxx>  
#include <Standard_OStream.hxx>  
#include <Standard_Real.hxx>  
#include <StdPrs_Curve.hxx>  
#include <StdPrs_Point.hxx>  
#include <StdPrs_PoleCurve.hxx>  
#include <TCollection_AsciiString.hxx>  
#include <TColgp_Array1OfPnt2d.hxx>  
#include <TColgp_HArray1OfPnt2d.hxx>  
#include <TCollection_AsciiString.hxx>  
#include <TColStd_HSequenceOfTransient.hxx>  
#include <TColStd_MapIteratorOfMapOfTransient.hxx>  
#include <TColStd_MapOfTransient.hxx>  
#include <TopExp_Explorer.hxx>  
#include <TopoDS.hxx>  
#include <TopoDS_Compound.hxx>  
#include <TopoDS_Shape.hxx>  
#include <TopoDS_Solid.hxx>  
#include <TopoDS_Vertex.hxx>  
#include <TopExp.hxx>  
#include <TopTools_HSequenceOfShape.hxx>  
#include <UnitsAPI.hxx>  
#include <V3d_View.hxx>  
#include <V3d_Viewer.hxx>  
#include <WNT_Window.hxx>  
#include <Prs3d_PointAspect.hxx>  
#include <AIS_Point.hxx>  
#include <AIS_InteractiveContext.hxx>
#include <AIS_Shape.hxx>
#include <BRep_Tool.hxx>  
#include <BRepAlgoAPI_Fuse.hxx>  
#include <BRepBuilderAPI_MakeEdge.hxx>  
#include <BRepBuilderAPI_MakeFace.hxx>  
#include <BRepBuilderAPI_MakeWire.hxx>  
#include <BRepBuilderAPI_MakeVertex.hxx>  
#include <BRepBuilderAPI_Transform.hxx>  
#include <BRepPrimAPI_MakeCone.hxx>  
#include <BRepPrimAPI_MakeRevol.hxx>  
#include <BRepFilletAPI_MakeFillet.hxx>  
#include <BRepBuilderAPI_Copy.hxx>  
#include <BRepBuilderAPI_MakePolygon.hxx>  
#include <BRepLib.hxx>  
#include <BRepOffsetAPI_MakeThickSolid.hxx>  
#include <BRepOffsetAPI_ThruSections.hxx>  
#include <BRepPrimAPI_MakeCylinder.hxx>  
#include <BRepPrimAPI_MakePrism.hxx>  
#include <BRepPrimAPI_MakeTorus.hxx>  
#include <BRepAlgoAPI_Section.hxx>  
#include <BRepPrimAPI_MakeSphere.hxx>  
#include <BRepFeat_SplitShape.hxx>  
#include <TColgp_HArray1OfPnt.hxx>  
#include <GeomAPI_Interpolate.hxx>  
#include <GC_MakeArcOfCircle.hxx>  
#include <GC_MakeSegment.hxx>  
#include <GC_MakeCircle.hxx>  
#include <GCE2d_MakeSegment.hxx>  
#include <gp.hxx>  
#include <gp_Ax1.hxx>  
#include <gp_Ax2.hxx>  
#include <gp_Ax2d.hxx>  
#include <gp_Dir.hxx>  
#include <gp_Dir2d.hxx>  
#include <gp_Pnt.hxx>  
#include <gp_Pnt2d.hxx>  
#include <gp_Trsf.hxx>  
#include <gp_Vec.hxx>  
#include <Geom_CylindricalSurface.hxx>  
#include <Geom_Plane.hxx>  
#include <Geom_Surface.hxx>  
#include <Geom_TrimmedCurve.hxx>  
#include <Geom2d_Ellipse.hxx>  
#include <Geom2d_TrimmedCurve.hxx>  
#include <TopExp_Explorer.hxx>  
#include <TopoDS.hxx>  
#include <TopoDS_Edge.hxx>  
#include <TopoDS_Face.hxx>  
#include <TopoDS_Wire.hxx>  
#include <TopoDS_Shape.hxx>  
#include <TopoDS_Compound.hxx>  
#include <GCPnts_AbscissaPoint.hxx>  
#include <BRepAdaptor_Curve.hxx>  
#include <GeomLib.hxx>  
#include <GeomConvert_CompCurveToBSplineCurve.hxx>  
#include <TopTools_ListOfShape.hxx>  
#include <TopTools_ListIteratorOfListOfShape.hxx>  
#include <TopTools_DataMapOfShapeInteger.hxx>  
#include <TopTools_DataMapOfShapeReal.hxx>  
#include <TopTools_IndexedDataMapOfShapeAddress.hxx>  
#include <V3d_PositionalLight.hxx>  
#include <V3d_DirectionalLight.hxx>  
#include <V3d_AmbientLight.hxx>  
#include <IGESControl_Controller.hxx>  
#include <IGESControl_Writer.hxx>  
#include <Interface_Static.hxx>  
#include <OpenGl_GraphicDriver.hxx>  
#include <Graphic3d_GraphicDriver.hxx>

然后在项目名.h文件的类里添加:

Handle(Graphic3d_GraphicDriver) m_GraphicDriver;
Handle(Graphic3d_GraphicDriver) GetGraphicDriver() { return m_GraphicDriver; }

和头文件

#include <Standard_Macro.hxx>
#include <Graphic3d_GraphicDriver.hxx>

项目名.cpp的构造函数里加上:

try {
        Handle(Aspect_DisplayConnection) aDisplayConnection;
        m_GraphicDriver = new OpenGl_GraphicDriver(aDisplayConnection);
    }
    catch (Standard_Failure) {
        AfxMessageBox(L"(Error Ocured in Initializing the Opencascade graphic variable.)");
    }

接着在项目名Doc.h文件类里添加:

Handle(AIS_InteractiveContext) myAISContext;  
Handle(V3d_Viewer) myViewer;  
Handle(V3d_Viewer) GetViewer(void) {return myViewer;}

接着去实现文档项目名Doc.cpp中类的构造函数中添加:

Handle(Graphic3d_GraphicDriver) theGraphicDriver = ((C项目名App*)AfxGetApp())->GetGraphicDriver();

    myViewer = new V3d_Viewer(theGraphicDriver);
    myViewer->SetDefaultLights();
    myViewer->SetLightOn();

    myAISContext = new AIS_InteractiveContext(myViewer);

    myAISContext->SetDisplayMode(AIS_Shaded,true);
    myAISContext->SetAutomaticHilight(Standard_False);

然后去去项目名View.h定义类里添加:

Handle(V3d_View) myView;  

和添加要重写的这个函数:

virtual void OnInitialUpdate();  

并在实现中声明这个方法(如果已经有了就不用新建了):

void FitAll() { if (!myView.IsNull()) myView->FitAll();  myView->ZFitAll(); };

然后去项目名View.cpp文件里添加下面这个实现函数(随便添加在哪里):

void C项目名View::OnInitialUpdate()

{

    CView::OnInitialUpdate();



    myView = GetDocument()->GetViewer()->CreateView();
    myView->SetShadingModel(V3d_GOURAUD);
    Handle(Graphic3d_GraphicDriver) theGraphicDriver = ((C项目名App*)AfxGetApp())->GetGraphicDriver();
    Aspect_Handle aWindowHandle = (Aspect_Handle)GetSafeHwnd();
    Handle(WNT_Window) aWntWindow = new WNT_Window(GetSafeHwnd());
    myView->SetWindow(aWntWindow);
    if (!aWntWindow->IsMapped()) {
        aWntWindow->Map();
    }
    Standard_Integer w = 100;
    Standard_Integer h = 100;
    aWntWindow->Size(w, h);
    ::PostMessage(GetSafeHwnd(), WM_SIZE, SIZE_RESTORED, w + h * 65536);
    myView->FitAll();

    myView->ZBufferTriedronSetup(Quantity_NOC_RED, Quantity_NOC_GREEN, Quantity_NOC_BLUE1, 0.8, 0.05, 12);
    myView->TriedronDisplay(Aspect_TOTP_LEFT_LOWER, Quantity_NOC_WHITE, 0.2, V3d_ZBUFFER);
}

然后在这个文件中的OnDraw()函数中添加:

myView->MustBeResized();  
myView->Update(); 
 

编译运行!

参考来源:OpenCASCADE(一) VS2017+OpenCASCADE+MFC +win10下载配置安装运行单文档程序画个基本图形 - aircraft - 博客园

以下几种易错情况可以注意一下:

1.运行按钮左边的x86如果没改成x64会报错

2.VS的项目属性有时候会恢复初始化状态,如果莫名报错可以检查一下项目属性是不是没修改成功

3.没有与参数列表匹配的“XXX”重载实例/没有重载函数接收3个参数

这是因为opencascade对new进行了重载,我们将每个new报错文件顶部的:

#ifdef _DEBUG 
#define new DEBUG_NEW 
#endif

这几行代码注释就行了

3.最近我引用了opencascade的Demo,其中让我修改了符号设置,在工具-》选项-》调试-》符号里勾选了Microsoft符号服务器,这种情况下运行上文的项目会一直卡在启动项目,要记得取消勾选。

  • 12
    点赞
  • 54
    收藏
    觉得还不错? 一键收藏
  • 13
    评论
OpenCV(Open Source Computer Vision Library)是一个开源的计算机视觉库,其中包含了许多用于图像处理和机器视觉的算法和工具。人脸识别是OpenCV库中的一个重要功能,下面将简要介绍OpenCV人脸识别的核心源码OpenCV人脸识别的核心源码主要包含以下几个模块: 1. 人脸检测(Face Detection): OpenCV利用级联分类器(Cascade Classifier)实现了人脸检测功能,其中最常用的是Haar特征分类器和深度学习模型。Haar特征分类器是一种基于Haar特征的机器学习算法,通过训练分类器来识别人脸的特征,例如眼睛、嘴巴等。深度学习模型则是利用深度神经网络来实现人脸检测,例如一些基于卷积神经网络(CNN)的模型,如SSD、YOLO等。 2. 人脸对齐(Face Alignment): 人脸对齐是人脸识别中的重要步骤,其目的是将检测到的人脸在图像中进行精确的对齐,以利于后续的特征提取和匹配。OpenCV中常用的人脸对齐算法包括基于2D关键点的仿射变换和基于3D模型的三维形状重建。 3. 特征提取(Feature Extraction): 特征提取是人脸识别的核心步骤,通过提取人脸图像中的特征来表示该人脸的唯一性。OpenCV中常用的特征提取算法有局部二值模式(Local Binary Patterns, LBP)、主成分分析(Principal Component Analysis, PCA)以及深度学习模型中的卷积层特征等。 4. 特征匹配(Feature Matching): 特征匹配是人脸识别中的关键步骤,通过比较待识别人脸的特征与已知人脸特征进行匹配,从而确定是否为同一个人。OpenCV中一种常用的特征匹配算法是基于人脸特征向量的欧氏距离或余弦相似度进行比较,通过设定阈值来判断是否为同一个人。 综上所述,OpenCV人脸识别的核心源码包含了人脸检测、人脸对齐、特征提取和特征匹配等多个模块,通过不同的算法和技术实现了人脸识别的功能。这些源码可以帮助开发者理解和实现人脸识别系统,从而应用于人脸识别、人脸验证、人脸跟踪等相关领域。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 13
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值