OpenCV Viz 3D虛擬空間模組_opencv

來源:互聯網
上載者:User

在OpenCV2.4.9發布release版本時添加了3D模組,實現起來非常簡潔漂亮,三維虛擬空間模組是整合自三維電腦圖形學、影像處理和可視化的VTK得到的,OpenCV3.0的OpenCV tutorial中常式效果如下:


首次配置Viz運行得到的效果:

原始碼如下:

#include <opencv2/viz/vizcore.hpp>#include <iostream>using namespace cv;using namespace std;/*** @function main*/int main(){    /// Create a window    viz::Viz3d myWindow("Viz Demo");    /// Start event loop    myWindow.spin();    /// Event loop is over when pressed q, Q, e, E    cout << "First event loop is over" << endl;    /// Access window via its name    viz::Viz3d sameWindow = viz::getWindowByName("Viz Demo");    /// Start event loop    sameWindow.spin();    /// Event loop is over when pressed q, Q, e, E    cout << "Second event loop is over" << endl;    /// Event loop is over when pressed q, Q, e, E    /// Start event loop once for 1 millisecond    sameWindow.spinOnce(1, true);    while(!sameWindow.wasStopped())    {        /// Interact with window        /// Event loop for 1 millisecond        sameWindow.spinOnce(1, true);    }    /// Once more event loop is stopped    cout << "Last event loop is over" << endl;    return 0;}


Windows 7下並非第一幅映像一般一片黑。其他類似常式如下:

原始碼如下:

#include <opencv2/viz.hpp>#include <opencv2/calib3d.hpp>#include <iostream>using namespace cv;using namespace std;int main(){/// Create a windowviz::Viz3d myWindow("Coordinate Frame");/// Add coordinate axesmyWindow.showWidget("Coordinate Widget", viz::WCoordinateSystem());/// Add line to represent (1,1,1) axisviz::WLine axis(Point3f(-1.0f, -1.0f, -1.0f), Point3f(1.0f, 1.0f, 1.0f));axis.setRenderingProperty(viz::LINE_WIDTH, 4.0);myWindow.showWidget("Line Widget", axis);/// Construct a cube widgetviz::WCube cube_widget(Point3f(0.5, 0.5, 0.0), Point3f(0.0, 0.0, -0.5), true, viz::Color::blue());cube_widget.setRenderingProperty(viz::LINE_WIDTH, 4.0);/// Display widget (update if already displayed)myWindow.showWidget("Cube Widget", cube_widget);/// Rodrigues vectorMat rot_vec = Mat::zeros(1, 3, CV_32F);float translation_phase = 0.0, translation = 0.0;while (!myWindow.wasStopped()){//* Rotation using rodrigues /// Rotate around (1,1,1)rot_vec.at<float>(0, 0) += CV_PI * 0.01f;rot_vec.at<float>(0, 1) += CV_PI * 0.01f;rot_vec.at<float>(0, 2) += CV_PI * 0.01f;/// Shift on (1,1,1)translation_phase += CV_PI * 0.01f;translation = sin(translation_phase);Mat rot_mat;Rodrigues(rot_vec, rot_mat);/// Construct poseAffine3f pose(rot_mat, Vec3f(translation, translation, translation));myWindow.setWidgetPose("Cube Widget", pose);myWindow.spinOnce(1, true);}return 0;}





You need to build VTK 6.1 (download) using CMake 2.8.x with shared libs turned off. VTK needs to be build as static library so it can be used to link to opencv with the VIZ module.

Build opencv with the viz module turned on using the src and build folders for vtk.

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.