本文整理汇总了C++中cv::Ptr::pixelToNormImageCoordinates方法的典型用法代码示例。如果您正苦于以下问题:C++ Ptr::pixelToNormImageCoordinates方法的具体用法?C++ Ptr::pixelToNormImageCoordinates怎么用?C++ Ptr::pixelToNormImageCoordinates使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cv::Ptr
的用法示例。
在下文中一共展示了Ptr::pixelToNormImageCoordinates方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: addCamera
void Visualizer::addCamera( const PointOfView& camera,
std::string name, int viewport )
{
//First get the focal of camera:
const cv::Ptr<Camera> cam = camera.getIntraParameters( );
double focal = cam->getFocal( );
//Now get the corners in camera's coordinates:
std::vector<cv::Vec2d> corners, real_coord;
corners.push_back( cv::Vec2d( 0, 0 ) );
corners.push_back( cv::Vec2d( cam->getImgWidth(),
cam->getImgHeight()) );
real_coord = cam->pixelToNormImageCoordinates( corners );
//create the mesh:
std::vector<Vec3d> camera_mesh;
camera_mesh.push_back( Vec3d(
real_coord[ 0 ][ 0 ], real_coord[ 0 ][ 1 ], 0 ) );//bottom left corner
camera_mesh.push_back( Vec3d(
real_coord[ 1 ][ 0 ], real_coord[ 0 ][ 1 ], 0 ) );//bottom right corner
camera_mesh.push_back( Vec3d(
real_coord[ 1 ][ 0 ], real_coord[ 1 ][ 1 ], 0 ) );//top right corner
camera_mesh.push_back( Vec3d(
real_coord[ 0 ][ 0 ], real_coord[ 1 ][ 1 ], 0 ) );//top left corner
camera_mesh.push_back( Vec3d(
0, 0, focal ) );//camera's origin
//move theses points to the world coordinates:
for( unsigned int i = 0; i < camera_mesh.size( ); ++i )
{
//translate to the correct location:
camera_mesh[ i ] = ( Vec3d ) ( Mat ) ( ( Mat )( camera_mesh[ i ] ) -
camera.getTranslationVector( ) );
//rotate the ith point:
camera_mesh[ i ] = ( Vec3d ) ( Mat ) ( ( Mat )( camera_mesh[ i ] ).t( ) *
camera.getRotationMatrix( ) );
}
pcl::PointCloud<pcl::PointXYZ>::Ptr camera_cloud (
new pcl::PointCloud<pcl::PointXYZ> );
mapping::convert_OpenCV_vector( camera_mesh, *camera_cloud );
//now create the mesh himself:
std::vector<pcl::Vertices> vertices;
pcl::Vertices vertice;
vertice.vertices.push_back( 0 );
vertice.vertices.push_back( 1 );
vertice.vertices.push_back( 2 );
vertice.vertices.push_back( 3 );
vertices.push_back( vertice ); vertice.vertices.clear( );
vertice.vertices.push_back( 0 );
vertice.vertices.push_back( 1 );
vertice.vertices.push_back( 4 );
vertices.push_back( vertice ); vertice.vertices.clear( );
vertice.vertices.push_back( 1 );
vertice.vertices.push_back( 2 );
vertice.vertices.push_back( 4 );
vertices.push_back( vertice ); vertice.vertices.clear( );
vertice.vertices.push_back( 2 );
vertice.vertices.push_back( 3 );
vertice.vertices.push_back( 4 );
vertices.push_back( vertice ); vertice.vertices.clear( );
vertice.vertices.push_back( 3 );
vertice.vertices.push_back( 0 );
vertice.vertices.push_back( 4 );
vertices.push_back( vertice ); vertice.vertices.clear( );
pcl::PolygonMesh triangles;
sensor_msgs::PointCloud2 msg;
pcl::toROSMsg( *camera_cloud, msg );
triangles.cloud = msg;
triangles.polygons = vertices;
pcl::io::saveVTKFile ( "meshCam.vtk", triangles );
//now add mesh to the viewer:
viewer->addPolygonMesh( triangles, name, viewport );
viewer->setShapeRenderingProperties(
pcl::visualization::PCL_VISUALIZER_LINE_WIDTH, 1.5, name );
//viewer->addPointCloud<pcl::PointXYZ>( camera_cloud, name );
//viewer->setPointCloudRenderingProperties (
// pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 5, name );
}