zoukankan      html  css  js  c++  java
  • OpenCV-Utils学习日志:viz模块要点总结

    1.Widgetset/getRenderingProperty(key, val)=void   fromPlyFile(path)=wgt   WidgetAccessor=friend

             (1)Widget2DsetColor(color)=void

                      1)WText:txt(str, pos, size=20, color=Color::white())   set/getText(str)=void

                      2)WImageOverlay:ima(mat, rect)   setImage(mat)=void

             (2)Widget3DapplyTransform(affine)=void   updatePose(affine)   setColor(color)=void   set/getPose(affine)=void

                      1)WLine:line(pt1, pt2, color=Color::white())

                      2)WCircle:circle(radius, [center, normal,]thickness=0.01, color=Color::white())

                      3)WPlane:plane([center, normal, newY, ]size=Size2d(1.0, 1.0), color=Color::white())

                      4)WGrid:grid([center, noraml,newY, ]cells=Vec2i::all(10), cellspacing=Vec2d::all(1.0), color=Color::white())

                      5)WCube:cube(min=Vec3d::all(-0.5), max=Vec3d::all(0.5), wireframe=true, color=Color::white())

                      6)WCone:cone(height, radius, resolution=6.0, color=Color::white())   cone(radius, center, tip, resolution=6.0, color=Color::white())

                      7)WSphere:sphere(center, radius, resolution=10, color=Color::white())

                      8)WCylinder:cylinder(center1, center2, radius, numsides=30, color=Color::white())

                      9)WPolyLine:polyline(pts, color=Color::white()/colors)

                      10)WArrow:arrow(pt1, pt2, thickness=0.03, color=Color::white())

                      11)WText3D:txt(str, pos, scale=1, faceCamera=true, color=Color::white())   set/getText(str)=void

                      12)WImage3D:ima(mat, size[, center, normal, newY])   setSize(size)=void   setImage(mat)=void

                      13)WCoordinateSystem:csys(scale=1.0)

                      14)WCameraPosition:camPos(scale=1.0)   camPos(K/fov, [ima, ]scale=1.0, color=Color::white())

                      15)WTrajectory:traj(affines, mode=PATH/FRAME/BOTH, scale=1.0,color=Color::white())

                      16)WTrajectorySpheres:traj(affines, lineLen=0.05, radius=0.007, from=Color::red(), to=Color::white())

                      17)WTrajectoryFrustums:traj(affines, K/fov, scale=1, color=Color::white())

                      18)WCloud[u1] :cloud(mat, color=Color::white())   cloud(mat, color/colors, normals)

                      19)WPaintedCloudcloud(mat, pt1,pt2[, color1,color2])

                      20)WCloudNormalsnormals(mat, norms, level=64, scale=0.1, color=Color::white())

                      21)WCloudCollectioncollection(mat, color=Color::white()/colors, pos=Affine3d::Identity())

                      22)WMeshmesh(mat, polygons, colors=noArray(), normals=noArray())

                      23)WWidgetMerger:addWidget(wgt,pose=Affine3d::Identity())=void   finalize()=void

    2.Viz3dviz(name)   VizStorage=friend

             (1)部件:set/get/updateWidgetPose[u2] (wgtId, affine)=void   show/getWidget(wgtId, wgt, affine=Affine3d::Identity())=void   removeWidget(wgtId)=void   removeAllWidgets()=void

                   showImage(ima, size)=void   setRepresentation[u3] (val)=void   set/getRenderingProperty[u4] (wgtId, key, val)=void

             (2)视口[u5] :set/getViewerPose(affine)=void   set/getCamera(cam)=void   resetCamera()=void   resetCameraViewpoint(wgtId)=void

             (3)窗体:getWindowName()=str   set/getWindowSize(size)=void   setWindowPosition(pos)=void   setGlobalWarnings(enabled=false)=void

             (4)背景:setBackgroundColor(color1=Color::black(), color2=Color::not_set())=void   setBackgroundTexture(ima)=void   setBackgroundMeshLab()=void

             (5)屏幕:setFullScreen(mode=true)=void   getScreenshot()=mat   saveScreenshot(path)=void   setOffScreenRendering()=void

             (6)灯光:addLight(orgPt, focalPt=Vec3d(0,0,0), color=Color::white(), diffuseColor=Color::white(), ambientColor=Color::black(), specularColor=Color::white())=void   removeAllLights()=void

             (7)事件:spin()=void   spinOnce(ms=1, forceRedraw=false)=void   wasStopped()=bl   close()=void   registerMouseCallback(cb, usrdata)=void   registerKeyboardCallback(cb, usrdata)=void

             (8)坐标变换:convertToWindowCoordinates(worldPt, pixelPt)=void   converTo3DRay(pixelPt, origin, direction)=void

    3.工具类

             (1)Color:color(gray)   color(r, g, b)   color(scalar)   black/gray/white/red/orange/yellow/green/cyan/blue/purple/~()=color

             (2)Mesh:load(file, type=LOAD_AUTO/LOAD_PLY/LOAD_OBJ)   cloud   colors   normals   polygons   tcoords   texture

             (3)MouseEvent:mouseevent(type, btn, pt, modifers)   type[u6]    button[u7]    pointer   modifiers[u8] 

             (4)KeyboardEvent:keyevent(action, symbol, code, modifiers)   action[u9]    symbol   code   modifiers[u10] 

             (5)Camera:cam(fov/K/P/(fx, fy, cx, cy), size)   computeProjectionMatrix(P)=void   set/getClip(clip)=void   set/getFov(fov)=void   set/getWindowSize(size)=void   getPrincipalPoint()=pt

    4.全局函数

             (1)makeTransformToGlobal(axisX, axisY, axisZ, org=Vec3d::all(0))=affine   makeCameraPose(orgPt, focalPt, axisY)=affine

             (2)isNan(flt/db/vec/point3d)=bl   computeNormals(mesh, normals)=void   getWindowByName(name)=viz   unregisterAllWindows()=void   imshow[u11] (viz, ima, size=Size(-1,-1))=void

             (3)writePose(path,affine,tag=”pose”)=void  writeTrajectory(traj,path,start=0,tag=”pose”)=void  writeCloud(path,cloud,colors=noArray(),normals=noArray(),binary=false)=void

             (4)readPose(path, affine, tag=”pose”)=void  readTrajectory(traj, path, start=0, end=INT_MAX, tag=”pose”)=void  readCloud(path, colors=noArray(), noramls=noArray())=mat  readMesh(path)=mesh

    5.使用说明

             (1)Widget赋值方式同Mat:即只复制文件头,数据是共享的,且只有无被引用的地方时才析构

             (2)Viz3d回调函数同Gui:即lambda表达式的捕获参数只能为空,访问外部变量的方式是将其定义为静态变量

             (3)几何物理量的默认单位:


     [u1]数据类型:三四通道单双精度

    颜色类型:一三四通道无符字符

    法线类型:三四通道单双精度

    无效点值:所有分量为NaN

    类型相同:数据法线两者相同

    尺寸相同:数据颜色法线三者相同

     [u2]set是修改当前位姿为给定位姿

    update是当前位姿左乘给定位姿

    get针对Widget3D才能有生效

     [u3]REPRESENTATION_POINTS

    REPRESENTATION_WIREFRAME

    REPRESENTATION_SURFACE

    默认切换键:W,S,P

     [u4]POINT_SIZE、OPACITY、LINE_WIDTH、FONT_SIZE、REPRESENTATION、IMMEDIATE_RENDERING、SHADING、AMBIENT、LIGHTING

     [u5]1.xxxWidgetPose是部件在世界坐标系中的位姿,xxxViewerPose是相机在世界坐标系中的位姿

    2.缩放窗体自适应更新相机内参

    3.操作鼠标自适应更新相机外参和相机远近平面

     [u6]MouseMove、MouseButtonPress、MouseButtonRelease、MouseScrollDown、MouseScrollUp、MouseDblClick

     [u7]NoButton、LeftButton、RightButton、MiddleButton、VScroll

     [u8]NONE、ALT、CTRL、SHIFT

     [u9]KEY_UP、KEY_DOWN

     [u10]NONE、ALT、CTRL、SHIFT

     [u11](1)若viz不存在则新建之且尺寸为size并将ima全窗显示

    (2)若viz存在则同showImage功能

    6.使用样例

             以下提供OpenCV viz模块的使用样例,封装在类AboutOpenCVVIZ,包括testVizViz3d、testVizWidget、testVizGlobal三个样例。

             关于AboutOpenCVVIZ::testVizViz3d功能说明

             (1)在三维窗Viz3d添加坐标系WCoordinateSystem和一个立方体WCube,并将两者设置为较高透明度,以方便查看相关变换。

             (2)为三维窗Viz3d注册鼠标和键盘响应函数,使能实时响应鼠标键盘事件,如按F1执行Viz3d::resetCamera以平移相机到最佳观测位置、按F2执行Viz3d::resetCameraView以旋转相机到最佳观测角度。

             (3)在三维窗Viz3d添加文本框WText,用于动态显示鼠标键盘状态、相机内外参、快速捷说明等信息,需要说明的是这里显示的相机外参(即Viz3d::getViewerPose返回位姿)就是相机在世界坐标系下(世界坐标系与Viz3d绑定的)的位姿。

             (4)在三维窗Viz3d添加WArrow,用于动态展示相机光心到鼠标点的指向,converTo3DRay的输入是屏幕坐标,输出是光心和光心到鼠标的指向。

             关于AboutOpenCVVIZ::testVizWidget功能说明

             (1)实现从左到右依次按~、1、2、…、Backspace、F1绘制不同的三维物体,其中坐标系WCoordinateSystem、提示文本WText及平面图WImageOverlay总是显示。

             (2)为三维窗Viz3d注册鼠标事件完成的以上功能。

             关于AboutOpenCVVIZ::testVizGlobal功能说明

             (1)调用readMesh读取三个不同的PLY文件显示在不同的位置。

             (2)调用readCloud读取三个不同的PLY文件显示在不同的位置,并调用writeCloud保存为移除mesh信息的PLY文件(即仅点云)。

             (3)PLY文件下载:https://files.cnblogs.com/files/dzyBK/OpenCV-Utils%E5%AD%A6%E4%B9%A0%E6%97%A5%E5%BF%97%EF%BC%9Aviz%E6%A8%A1%E5%9D%97%E8%A6%81%E7%82%B9%E6%80%BB%E7%BB%93-data.zip


            以下是详细代码,依赖于C++14、OpenCV4.x和Spdlog。
      1 #include <opencv2/opencv.hpp>
      2 #include <opencv2/core/utils/filesystem.hpp>
      3 #include <opencv2/viz.hpp>
      4 #include <spdlog/spdlog.h>
      5 using namespace std;
      6 using namespace cv;
      7 
      8 #ifndef StrPairKey
      9 #define StrPairKey(key) make_pair(#key, key)
     10 #define StrPairVal(val) make_pair(val, #val)
     11 #endif
     12 
     13 #ifndef  RAD2DEG
     14 #define RAD2DEG (180 * 0.3183098861837906715)
     15 #define DEG2RAD (3.14159265358979323846 * 0.0055555555555555556)
     16 #endif
     17 
     18 class AboutOpenCVVIZ
     19 {
     20 public:
     21     struct VizMouse
     22     {
     23         int rowsUser;//GivenByUser
     24         int colsUser;//GivenByUser
     25         VizMouse(int rows = INT_MAX, int cols = INT_MAX) : rowsUser(rows), colsUser(cols) {}
     26         int xMouse;//UpdatedByCbVizMouse
     27         int yMouse;//UpdatedByCbVizMouse
     28         int type;//UpdatedByCbVizMouse
     29         int button;//UpdatedByCbVizMouse
     30         int modifiers;//UpdatedByCbVizMouse
     31         map<int, string> mouseTypes =
     32         {
     33             StrPairVal(viz::MouseEvent::MouseMove),
     34             StrPairVal(viz::MouseEvent::MouseButtonPress),
     35             StrPairVal(viz::MouseEvent::MouseButtonRelease),
     36             StrPairVal(viz::MouseEvent::MouseScrollDown),
     37             StrPairVal(viz::MouseEvent::MouseScrollUp),
     38             StrPairVal(viz::MouseEvent::MouseDblClick)
     39         };
     40         map<int, string> mouseButtons =
     41         {
     42             StrPairVal(viz::MouseEvent::NoButton),
     43             StrPairVal(viz::MouseEvent::LeftButton),
     44             StrPairVal(viz::MouseEvent::MiddleButton),
     45             StrPairVal(viz::MouseEvent::RightButton),
     46             StrPairVal(viz::MouseEvent::VScroll)
     47         };
     48         map<int, string> mouseModifiers =
     49         {
     50             StrPairVal(viz::KeyboardEvent::NONE),
     51             StrPairVal(viz::KeyboardEvent::ALT),
     52             StrPairVal(viz::KeyboardEvent::CTRL),
     53             StrPairVal(viz::KeyboardEvent::SHIFT)
     54         };
     55     };
     56     struct VizBoard
     57     {
     58         int code;//UpdatedByCbVizBoard
     59         int action;//UpdatedByCbVizBoard
     60         int modifiers;//UpdatedByCbVizBoard
     61         string symbol;//UpdatedByCbVizBoard
     62         map<int, string> boardActions =
     63         {
     64             StrPairVal(viz::KeyboardEvent::KEY_UP),
     65             StrPairVal(viz::KeyboardEvent::KEY_DOWN)
     66         };
     67         map<int, string> boardModifiers =
     68         {
     69             StrPairVal(viz::KeyboardEvent::NONE),
     70             StrPairVal(viz::KeyboardEvent::ALT),
     71             StrPairVal(viz::KeyboardEvent::CTRL),
     72             StrPairVal(viz::KeyboardEvent::SHIFT)
     73         };
     74     };
     75 
     76     static void callbackVizMouse(const viz::MouseEvent& mouseEvent, void* pVizMouse)
     77     {    //common case. could be replaced by lambda based on actual requirement
     78         VizMouse* vizMouse = (VizMouse*)pVizMouse;
     79         int x = mouseEvent.pointer.x;
     80         int y = mouseEvent.pointer.y;
     81 
     82         if (x >= vizMouse->colsUser * 3) x -= vizMouse->colsUser * 3;
     83         else if (x >= vizMouse->colsUser * 2) x -= vizMouse->colsUser * 2;
     84         else if (x >= vizMouse->colsUser) x -= vizMouse->colsUser;
     85 
     86         if (y >= vizMouse->rowsUser * 3) y -= vizMouse->rowsUser * 3;
     87         else if (y >= vizMouse->rowsUser * 2) y -= vizMouse->rowsUser * 2;
     88         else if (y >= vizMouse->rowsUser) y -= vizMouse->rowsUser;
     89 
     90         vizMouse->xMouse = x;
     91         vizMouse->yMouse = y;
     92         vizMouse->type = mouseEvent.type;
     93         vizMouse->button = mouseEvent.button;
     94         vizMouse->modifiers = mouseEvent.modifiers;
     95     }
     96     static void callbackVizBoard(const viz::KeyboardEvent& keyboarEvent, void* pVizBorad)
     97     {    //common case. could be replaced by lambda based on actual requirement
     98         VizBoard* vizBoard = (VizBoard*)pVizBorad;
     99 
    100         vizBoard->code = keyboarEvent.code;
    101         vizBoard->action = keyboarEvent.action;
    102         vizBoard->modifiers = keyboarEvent.modifiers;
    103         vizBoard->symbol = keyboarEvent.symbol;
    104     }
    105 
    106 
    107 public:
    108     static void testVizViz3d(int argc = 0, char** argv = 0)
    109     {
    110         //1.Widgets
    111         viz::WCoordinateSystem csys(100); csys.setRenderingProperty(viz::OPACITY, 0.1);
    112         viz::WCube cube(Point3d(-50, -50, -50), Point3d(50, 50, 50), false, viz::Color(255, 255, 255)); cube.setRenderingProperty(viz::OPACITY, 0.2);
    113 
    114         //2.Viz3D
    115         viz::Viz3d viz3d(__FUNCTION__);
    116         VizMouse vizMouse; viz3d.registerMouseCallback(callbackVizMouse, &vizMouse);
    117         VizBoard vizBoard; viz3d.registerKeyboardCallback(callbackVizBoard, &vizBoard);
    118         viz3d.showWidget("csys", csys);
    119         viz3d.showWidget("cube", cube);
    120 
    121         //3.MainLoop: should be distributed to MouseCallback and KeyboardCallback for efficiency.
    122         stringstream ss;
    123         for (int k = 0; k < 1000; ++k)
    124         {
    125             //3.1 ForEvent
    126             if (vizBoard.symbol == "F1") { viz3d.resetCamera(); vizBoard.symbol.clear(); }
    127             if (vizBoard.symbol == "F2") { viz3d.resetCameraViewpoint("cube"); vizBoard.symbol.clear(); }
    128 
    129             //3.2 ForTips
    130             ss << endl << "Loop: " << k;
    131             ss << endl << "Representations: W, S, P";
    132             ss << endl << "Unknown defaults: R, F, O, 3";
    133             ss << endl << "DIY F1: Viz3d::resetCamera";
    134             ss << endl << "DIY F2: Viz3d::resetCameraViewpoint";
    135             viz3d.showWidget("txt1", viz::WText(ss.str(), Point(viz3d.getWindowSize().width / 3, viz3d.getWindowSize().height / 10 * 9))); cout << endl << ss.str(); ss.str("");
    136 
    137             //3.3 ForIntuition
    138             ss << endl << "mouse.x: " << vizMouse.xMouse;
    139             ss << endl << "mouse.y: " << vizMouse.yMouse;
    140             ss << endl << "mouse.type: " << vizMouse.mouseTypes[vizMouse.type];
    141             ss << endl << "mouse.button: " << vizMouse.mouseButtons[vizMouse.button];
    142             ss << endl << "mouse.modifiers: " << vizMouse.mouseModifiers[vizMouse.modifiers];
    143             ss << endl;
    144             ss << endl << "board.code: " << vizBoard.code;
    145             ss << endl << "board.action: " << vizBoard.boardActions[vizBoard.action];
    146             ss << endl << "board.modifiers: " << vizBoard.boardModifiers[vizBoard.modifiers];
    147             ss << endl << "board.symbol: " << vizBoard.symbol;
    148             ss << endl;
    149             ss << endl << "cam.fxfy: " << viz3d.getCamera().getFocalLength();
    150             ss << endl << "cam.cxcy: " << viz3d.getCamera().getPrincipalPoint();
    151             ss << endl << "cam.size: " << viz3d.getCamera().getWindowSize();
    152             ss << endl << "cam.fov: " << viz3d.getCamera().getFov() * RAD2DEG;
    153             ss << endl << "cam.clip: " << viz3d.getCamera().getClip();
    154             ss << endl << "cam.euler: " << cv::RQDecomp3x3(viz3d.getViewerPose().matrix.get_minor<3, 3>(0, 0), Matx33d(), Matx33d());
    155             ss << endl << "cam.trans: " << viz3d.getViewerPose().matrix.col(3).t();
    156             ss << endl;
    157             Point3d uvz(vizMouse.xMouse, vizMouse.yMouse, 0), org; Vec3d dir; viz3d.converTo3DRay(uvz, org, dir);
    158             ss << endl << "mouse.pt: " << uvz;
    159             ss << endl << "3DRay.org: " << org;
    160             ss << endl << "3DRay.dir: " << dir;
    161             viz3d.showWidget("arrow", viz::WArrow(Point3d(0, 0, 0), Point3d(dir[0] * 100, dir[1] * 100, dir[2] * 100), 0.01));
    162             viz3d.showWidget("txt2", viz::WText(ss.str(), Point(10, 10))); cout << endl << ss.str(); ss.str("");
    163 
    164             //3.3 ForCalculation
    165             ss << endl << "cam.Rt: " << endl << viz3d.getViewerPose().matrix;
    166             ss << endl << "cam.Rt.inv: " << endl << viz3d.getViewerPose().matrix.inv();
    167             Matx44d M;  viz3d.getCamera().computeProjectionMatrix(M);
    168             ss << endl << "cam.computeProjectionMatrix: " << endl << M;
    169             viz3d.showWidget("txt3", viz::WText(ss.str(), Point(viz3d.getWindowSize().width / 2 + 10, 10))); cout << endl << ss.str(); ss.str("");
    170 
    171             //3.4 ShowViz3D
    172             viz3d.spinOnce(500);
    173         }
    174     }
    175 
    176     static void testVizWidget(int argc = 0, char** argv = 0)
    177     {
    178         //1.Widget2D
    179         string naoPath = "./data/nao.jpg";
    180         if (utils::fs::exists(naoPath) == false) { spdlog::critical("{} not exits", naoPath); }
    181         Mat_<Vec3b> ima = imread(naoPath, 1);
    182         viz::WText txt2d("Press in turn: ~ 1 2 ... Backspace F1 to draw different widgets", Point(400, 10));
    183         viz::WImageOverlay ima2d(imread(naoPath, 1), Rect(10, 10, ima.cols >> 2, ima.rows >> 2));
    184 
    185         //2.Widget3D
    186         viz::WCoordinateSystem csys(100); csys.setRenderingProperty(viz::OPACITY, 0.1);
    187         Mat_<Point3f> polyline(10, 1); cv::randu(polyline, -50, 50);
    188         Mat_<cv::Affine3f> traj(10, 1); for (int k = 0; k < traj.rows; ++k) traj(k) = cv::Affine3f(Vec3f(Vec3f::randu(-50, 50).val), Vec3f(Vec3f::randu(-50, 50).val));
    189         static map<string, viz::Widget> wgts =
    190         {
    191             make_pair("txt2d", txt2d),
    192             make_pair("ima2d", ima2d),
    193             make_pair("csys", csys),
    194             make_pair("quoteleft", viz::WLine(Point3d(-50, -50, -50), Point3d(50, 50, 50))),
    195             make_pair("1", viz::WCircle(50, Point3d(0, 0, 0), Vec3d(0, 0, 1), 0.1)),
    196             make_pair("2", viz::WPlane(Point3d(0, 0, 0), Vec3d(0, 0, 1), Vec3d(0, 1, 0), Size2d(100, 100))),
    197             make_pair("3", viz::WCube(Point3d(-50, -50, -50), Point3d(50, 50, 50), false)),
    198             make_pair("4", viz::WCone(10, Point3d(0, 0, -50), Point3d(0, 0, 50), 60)),
    199             make_pair("5", viz::WSphere(Point3d(0, 0, 0), 50, 100)),
    200             make_pair("6", viz::WCylinder(Point3d(0, 0, -50), Point3d(0, 0, 50), 50, 300)),
    201             make_pair("7", viz::WPolyLine(polyline)),
    202             make_pair("8", viz::WArrow(Point3d(-50, -50, -50), Point3d(50, 50, 50))),
    203             make_pair("9", viz::WText3D("viz::WText3D", Point3d(0, 0, 0), 10)),
    204             make_pair("0", viz::WImage3D(ima, ima.size() / 4, Vec3d(0,0, 0), Vec3d(0, 0, 1), Vec3d(0, 1, 0))),
    205             make_pair("minus", viz::WCameraPosition(Vec2d(0.8, 0.6), 10)),
    206             make_pair("equal", viz::WTrajectory(traj, viz::WTrajectory::BOTH, 10)),
    207             make_pair("BackSpace", viz::WTrajectorySpheres(traj, 100, 1)),
    208             make_pair("F1", viz::WTrajectoryFrustums(traj, Vec2d(0.8, 0.6), 10))
    209         };
    210         for (map<string, viz::Widget>::iterator it = wgts.begin(); it != wgts.end(); ++it)
    211         {
    212             if (it->first == "txt2d" || it->first == "ima2d" || it->first == "csys") continue;
    213             wgts[it->first].setRenderingProperty(viz::OPACITY, 0.5);
    214         }
    215 
    216         //3.Viz3D
    217         static viz::Viz3d viz3d(__FUNCTION__);
    218         viz3d.showWidget("txt2d", wgts["txt2d"]);
    219         viz3d.showWidget("ima2d", wgts["ima2d"]);
    220         viz3d.showWidget("csys", wgts["csys"]);
    221         VizMouse vizMouse; viz3d.registerMouseCallback(callbackVizMouse, &vizMouse);
    222         VizBoard vizBoard; viz3d.registerKeyboardCallback([](const viz::KeyboardEvent& keyboarEvent, void* pVizBorad)->void
    223             {
    224                 if (keyboarEvent.action != viz::KeyboardEvent::KEY_DOWN) return;
    225                 viz3d.removeAllWidgets();
    226                 viz3d.showWidget("txt2d", wgts["txt2d"]);
    227                 viz3d.showWidget("ima2d", wgts["ima2d"]);
    228                 viz3d.showWidget("csys", wgts["csys"]);
    229                 if (wgts.find(keyboarEvent.symbol) != wgts.end()) viz3d.showWidget(keyboarEvent.symbol, wgts[keyboarEvent.symbol]);
    230             }, 0);
    231         viz3d.spin();
    232     }
    233 
    234     static void testVizMesh(int argc = 0, char** argv = 0)
    235     {
    236         //1.CheckPaths
    237         string plypath0 = "./data/xyz.ply";
    238         string plypath1 = "./data/xyz+norm.ply";
    239         string plypath2 = "./data/xyz+norm+color.ply";
    240         if (utils::fs::exists(plypath0) == false) { spdlog::critical("{} not exits", plypath0); return; }
    241         if (utils::fs::exists(plypath1) == false) { spdlog::critical("{} not exits", plypath1); return; }
    242         if (utils::fs::exists(plypath2) == false) { spdlog::critical("{} not exits", plypath2); return; }
    243 
    244         //2.ReadMeshs
    245         viz::Mesh m0 = viz::readMesh(plypath0);
    246         viz::Mesh m1 = viz::readMesh(plypath1);
    247         viz::Mesh m2 = viz::readMesh(plypath2);
    248         viz::WMesh mesh0(m0);
    249         viz::WMesh mesh1(m1);
    250         viz::WMesh mesh2(m2);
    251 
    252         //3.ReadClouds
    253         Mat_<Vec3b> rgb0, rgb1, rgb2;
    254         Mat_<Vec3f> norm0, norm1, norm2;
    255         Mat_<Vec3f> xyz0 = viz::readCloud(plypath0, rgb0, norm0);
    256         Mat_<Vec3f> xyz1 = viz::readCloud(plypath1, rgb1, norm1);
    257         Mat_<Vec3f> xyz2 = viz::readCloud(plypath2, rgb2, norm2);
    258         viz::WCloud cloud0(xyz0, viz::Color(0, 0, 255), norm0);
    259         viz::WCloud cloud1(xyz1, viz::Color(0, 255, 0), norm1);
    260         viz::WCloud cloud2(xyz2, rgb2, norm2);
    261         viz::writeCloud(plypath0 + "_rewritten.ply", xyz0, rgb0, norm0);
    262         viz::writeCloud(plypath1 + "_rewritten.ply", xyz1, rgb1, norm1);
    263         viz::writeCloud(plypath2 + "_rewritten.ply", xyz2, rgb2, norm2);
    264 
    265         //4.CreateViz3D
    266         viz::Viz3d viz;
    267         viz::WCoordinateSystem csys(100); csys.setRenderingProperty(viz::OPACITY, 0.1);
    268         viz::WText txt2d("
    Press q to exit and show pointcloud", Point(10, 10));
    269         viz.showWidget("sys", csys); viz.showWidget("txt2d", txt2d);
    270 
    271         //5.ShowMeshs
    272         viz.showWidget("mesh0", mesh0, cv::Affine3d(Vec3d(0, 0, 0), Vec3d(100, 0, 0)));
    273         viz.showWidget("mesh1", mesh1, cv::Affine3d(Vec3d(0, 0, 0), Vec3d(0, 100, 550)));
    274         viz.showWidget("mesh2", mesh2, cv::Affine3d(Vec3d(0, 0, 0), Vec3d(0, 0, 100)));
    275         viz.spin();
    276 
    277         //6.ShowClouds
    278         viz.removeWidget("mesh0"); viz.removeWidget("mesh1"); viz.removeWidget("mesh2");
    279         viz.showWidget("cloud0", cloud0, cv::Affine3d(Vec3d(0, 0, 0), Vec3d(100, 0, 0)));
    280         viz.showWidget("cloud1", cloud1, cv::Affine3d(Vec3d(0, 0, 0), Vec3d(0, 100, 550)));
    281         viz.showWidget("cloud2", cloud2, cv::Affine3d(Vec3d(0, 0, 0), Vec3d(0, 0, 100)));
    282         viz.spin();
    283     }
    284 };
    285 
    286 int main(int argc, char** argv)
    287 {
    288     int which = 0;
    289     Mat_<Vec3b> ima(480, 640, Vec3b(48, 48, 48));
    290     cv::putText(ima, "Pressing 1 starts testVizViz3d", Point(200, 200), FONT_HERSHEY_PLAIN, 1, Scalar(255, 255, 255), 1);
    291     cv::putText(ima, "Pressing 2 starts testVizWidget", Point(200, 220), FONT_HERSHEY_PLAIN, 1, Scalar(255, 255, 255), 1);
    292     cv::putText(ima, "Pressing 3 starts testVizMesh", Point(200, 240), FONT_HERSHEY_PLAIN, 1, Scalar(255, 255, 255), 1);
    293     cv::namedWindow(__FUNCTION__);
    294     while(1)
    295     {
    296         cv::imshow(__FUNCTION__, ima);
    297         which = cv::waitKey(30);
    298         if (which == '1' || which == '2' || which == '3') break;
    299     }
    300     cv::destroyWindow(__FUNCTION__);
    301     if (which == '1') AboutOpenCVVIZ::testVizViz3d(argc, argv);
    302     else if (which == '2') AboutOpenCVVIZ::testVizWidget(argc, argv);
    303     else if (which == '3') AboutOpenCVVIZ::testVizMesh(argc, argv);
    304     return 0;
    305 }
    View Code
  • 相关阅读:
    谈mvc开发中gzip压缩的应用
    MIME 类型(HttpContext.Response.ContentType)列表
    Asp.net使用HttpModule压缩并删除空白Html请求
    ASP.NET MVC 网站优化之压缩技术
    从零开始编写自己的C#框架(25)——网站部署 【转】
    ReSharper的功能真的很强大主要是针对代码规范和优化,园子里介绍的也不少,如果你没有安装,那我只能表示你们会相见恨晚
    多用户角色权限访问模块问题”的解决思路( 位运算 + ActionFilterAttribute )
    Asp.Net Web Api 图片上传
    sqlserver并发用户数
    在线图片服务设计小计
  • 原文地址:https://www.cnblogs.com/dzyBK/p/13909734.html
Copyright © 2011-2022 走看看