当前位置: 首页 > news >正文

phpcms 图片网站北京公司建站模板

phpcms 图片网站,北京公司建站模板,公司简介链接怎么制作,珠海网站设计多少钱前文#xff1a; 1 基于SIFT图像特征识别的匹配方法比较与实现 2 OpenCV实现的F矩阵RANSAC原理与实践 1 E矩阵 1.1 由F到E E K T ∗ F ∗ K E K^T * F * K EKT∗F∗K E 矩阵可以直接通过之前算好的 F 矩阵与相机内参 K 矩阵获得 Mat E K.t() * F * K;相机内参获得的方式…前文 1 基于SIFT图像特征识别的匹配方法比较与实现 2 OpenCV实现的F矩阵RANSAC原理与实践 1 E矩阵 1.1 由F到E E K T ∗ F ∗ K E K^T * F * K EKT∗F∗K E 矩阵可以直接通过之前算好的 F 矩阵与相机内参 K 矩阵获得 Mat E K.t() * F * K;相机内参获得的方式是一个较为复杂的方式需要使用棋盘进行定位获得我们这里直接使用了 OpenMVG 提供的现成的图片和 K 矩阵 1.2 直接使用函数 利用 openCV 提供的 findEssentialMat 函数可以直接得到 E 矩阵 Mat E findEssentialMat(matchedPoints1, matchedPoints2, K, RANSAC, 0.999, 1.0, inliers);2 相机姿态恢复 这一步可以使用 SVD 来通过 E 矩阵获取相对旋转矩阵 R 和平移向量 t 但是OpenCV直接提供了一个非常便捷的函数 —— recoverPose 其接受本质矩阵 E 、特征点的对应关系、相机的内参信息以及输出的相对旋转矩阵 R 和平移向量 t 它会自动进行 SVD 分解和其他必要的计算以恢复相对姿态信息 //相机姿态恢复求解R,t,投影矩阵Mat R, t;recoverPose(E, inlierPoints1, inlierPoints2, K, R, t);3 相机投影矩阵 要构建相机的投影矩阵也称为视图矩阵或外参矩阵需要将旋转矩阵 R 和平移向量 t 合并到一起投影矩阵通常表示为 3x4 的矩阵其中旋转矩阵和平移向量都位于其中的适当位置 通常情况下投影矩阵的形式如下 P 1 K ∗ [ R ∣ t ] P_1 K * [R | t] P1​K∗[R∣t] P 2 K ∗ [ I ∣ 0 ] P_2 K * [I | 0] P2​K∗[I∣0] 实现代码如下 // 创建两个相机的投影矩阵 [R T] Mat proj1(3, 4, CV_32FC1); Mat proj2(3, 4, CV_32FC1);// 设置第一个相机的投影矩阵为单位矩阵 [I | 0] proj1(Range(0, 3), Range(0, 3)) Mat::eye(3, 3, CV_32FC1); proj1.col(3) Mat::zeros(3, 1, CV_32FC1);// 设置第二个相机的投影矩阵为输入的旋转矩阵 R 和平移向量 T R.convertTo(proj2(Range(0, 3), Range(0, 3)), CV_32FC1); t.convertTo(proj2.col(3), CV_32FC1);// 转换相机内参矩阵 K 为浮点型 Mat fK; K.convertTo(fK, CV_32FC1);// 计算投影矩阵 [K * [R|T]] proj1 fK * proj1; proj2 fK * proj2;4 三角法得稀疏点云 4.1 三角法计算3D点 对于每对匹配的特征点可以使用三角法来计算它们的三维坐标这通常涉及到将两个视角下的像素坐标与相应的投影矩阵相结合以恢复三维坐标 // 三角法求解稀疏三维点云 Mat point4D_homogeneous(4, inlierPoints1.size(), CV_64F); triangulatePoints(proj1, proj2, inlierPoints1, inlierPoints2, point4D_homogeneous);4.2 转换为非齐次坐标 函数 triangulatePoints 得到的 point4D_homogeneous 通常是齐次坐标需要将它们转换为非齐次坐标以得到真实的三维点坐标 // 将齐次坐标转换为三维坐标 Mat point3D; convertPointsFromHomogeneous(point4D_homogeneous.t(), point3D); cout point3D endl;5 匹配颜色 将颜色信息与点云关联在一起 使用了内点inliers的坐标从图像中提取了颜色信息然后将颜色信息与三维点坐标关联起来生成了带有颜色的稀疏点云 并将其存储在 pointCloud 和 pointColors 中就可以根据需要进一步处理颜色信息 // 获取特征点的颜色信息vectorVec3b colors1, colors2; // 颜色信息for (Point2f inlierPoints : inlierPoints1){int x cvRound(inlierPoints.x); // 关键点的x坐标int y cvRound(inlierPoints.y); // 关键点的y坐标Vec3b color img1.atVec3b(y, x);colors1.push_back(color);}for (Point2f inlierPoints : inlierPoints2){int x cvRound(inlierPoints.x); // 关键点的x坐标int y cvRound(inlierPoints.y); // 关键点的y坐标Vec3b color img2.atVec3b(y, x);colors2.push_back(color);}// 创建带颜色的点云数据结构vectorPoint3f pointCloud;vectorVec3b pointColors;// 关联颜色信息到点云for (int i 0; i point3D.rows; i){Point3f point point3D.atPoint3f(i);Vec3b color1 colors1[i];Vec3b color2 colors2[i];// 在这里可以根据需要选择使用哪个颜色或者进行颜色插值等处理Vec3b finalColor color1; // 这里示例使用第一个相机的颜色pointCloud.push_back(point);pointColors.push_back(finalColor);}6 生成 ply 文件 手动输出点云 PLY 文件并包括了 PLY 文件的头部信息以及点云数据的写入这是一种创建包含颜色信息的 PLY 文件的有效方法 在 PLY 文件的头部信息中指定了点的数量以及点的属性包括点的坐标和颜色通道蓝色、绿色、红色然后你循环遍历点云数据将点的坐标和颜色信息写入PLY文件 其会生成一个包含点云和颜色信息的PLY文件可以将其用于保存点云以进行可视化或进一步处理 特别注意图片是RGB还是BGR的颜色通道这里是RGB color[0]color[1] color[2] 分别代表蓝色绿色红色通道 // 手动输出点云ply文件 ofstream plyFile(PLY_SAVE_PATH);// ply的头部信息 plyFile ply\n; plyFile format ascii 1.0\n; plyFile element vertex point3D.rows \n; plyFile property float x\n; plyFile property float y\n; plyFile property float z\n; plyFile property uchar blue\n; plyFile property uchar green\n; plyFile property uchar red\n; plyFile end_header\n;// 写入点云数据 for (int i 0; i point3D.rows; i) {Vec3b color pointColors[i];const float* point point3D.ptrfloat(i);plyFile point[0] point[1] point[2] static_castint(color[0]) static_castint(color[1]) static_castint(color[2]) endl; }plyFile.close(); 7 完整测试代码 关于之前的阶段可以查看我之前的文章 // 定义图像文件路径和保存结果的路径 #define IMG_PATH1 test_img\\images\\100_7105.jpg #define IMG_PATH2 test_img\\images\\100_7106.jpg #define PLY_SAVE_PATH test_img\\results\\output.ply #define K_NUM 2905.88, 0, 1416, 0, 2905.88, 1064, 0, 0, 1 // 3*3#include opencv2/opencv.hpp #include iostream #include vector #include fstreamusing namespace std; using namespace cv;int main() {// 阶段一------------------------------------------------------------------------------------// 读取两幅图像Mat img1 imread(IMG_PATH1);Mat img2 imread(IMG_PATH2);if (img1.empty() || img2.empty()){cout 无法读取图像 endl;return -1;}// 创建SIFT对象PtrSIFT sift SIFT::create();vectorKeyPoint keypoints1, keypoints2;Mat descriptors1, descriptors2;// 检测关键点并计算描述子sift-detectAndCompute(img1, noArray(), keypoints1, descriptors1);sift-detectAndCompute(img2, noArray(), keypoints2, descriptors2);// 使用FLANN进行特征匹配FlannBasedMatcher matcher;vectorvectorDMatch matches;matcher.knnMatch(descriptors1, descriptors2, matches, 2);vectorDMatch good_matches;for (int i 0; i matches.size(); i){const float ratio 0.7f;if (matches[i][0].distance ratio * matches[i][1].distance){good_matches.push_back(matches[i][0]);}}// 阶段二------------------------------------------------------------------------------------// 声明用于保存匹配点对的容器vectorPoint2f matchedPoints1, matchedPoints2;for (int i 0; i good_matches.size(); i){matchedPoints1.push_back(keypoints1[good_matches[i].queryIdx].pt);matchedPoints2.push_back(keypoints2[good_matches[i].trainIdx].pt);}// 进行基本矩阵F的估计并使用RANSAC筛选Mat F;vectoruchar inliers;F findFundamentalMat(matchedPoints1, matchedPoints2, inliers, FM_RANSAC);cout F endl;vectorPoint2f inlierPoints1;vectorPoint2f inlierPoints2;for (int i 0; i inliers.size(); i){if (inliers[i]){inlierPoints1.push_back(matchedPoints1[i]);inlierPoints2.push_back(matchedPoints2[i]);}}// 相机内参矩阵KMat K (Mat_double(3, 3) K_NUM);cout K endl;计算本质矩阵E//Mat E findEssentialMat(matchedPoints1, matchedPoints2, K, RANSAC, 0.999, 1.0, inliers);Mat E K.t() * F * K;cout Essential Matrix (E): endl;cout E endl;//相机姿态恢复求解R,t,投影矩阵Mat R, t;recoverPose(E, inlierPoints1, inlierPoints2, K, R, t);cout recoverpose endl;cout R: R endl;cout t: t endl;// 创建两个相机的投影矩阵 [R T]Mat proj1(3, 4, CV_32FC1);Mat proj2(3, 4, CV_32FC1);// 设置第一个相机的投影矩阵为单位矩阵 [I | 0]proj1(Range(0, 3), Range(0, 3)) Mat::eye(3, 3, CV_32FC1);proj1.col(3) Mat::zeros(3, 1, CV_32FC1);// 设置第二个相机的投影矩阵为输入的旋转矩阵 R 和平移向量 TR.convertTo(proj2(Range(0, 3), Range(0, 3)), CV_32FC1);t.convertTo(proj2.col(3), CV_32FC1);// 转换相机内参矩阵 K 为浮点型Mat fK;K.convertTo(fK, CV_32FC1);// 计算投影矩阵 [K * [R|T]]proj1 fK * proj1;proj2 fK * proj2;// 三角法求解稀疏三维点云Mat point4D_homogeneous(4, inlierPoints1.size(), CV_64F);triangulatePoints(proj1, proj2, inlierPoints1, inlierPoints2, point4D_homogeneous);// 将齐次坐标转换为三维坐标Mat point3D;convertPointsFromHomogeneous(point4D_homogeneous.t(), point3D);cout point3D endl;// 获取特征点的颜色信息vectorVec3b colors1, colors2; // 颜色信息for (Point2f inlierPoints : inlierPoints1){int x cvRound(inlierPoints.x); // 关键点的x坐标int y cvRound(inlierPoints.y); // 关键点的y坐标Vec3b color img1.atVec3b(y, x);colors1.push_back(color);}for (Point2f inlierPoints : inlierPoints2){int x cvRound(inlierPoints.x); // 关键点的x坐标int y cvRound(inlierPoints.y); // 关键点的y坐标Vec3b color img2.atVec3b(y, x);colors2.push_back(color);}// 创建带颜色的点云数据结构vectorPoint3f pointCloud;vectorVec3b pointColors;// 关联颜色信息到点云for (int i 0; i point3D.rows; i){Point3f point point3D.atPoint3f(i);Vec3b color1 colors1[i];Vec3b color2 colors2[i];// 在这里可以根据需要选择使用哪个颜色或者进行颜色插值等处理Vec3b finalColor color1; // 这里示例使用第一个相机的颜色pointCloud.push_back(point);pointColors.push_back(finalColor);}// 手动输出点云ply文件ofstream plyFile(PLY_SAVE_PATH);// ply的头部信息plyFile ply\n;plyFile format ascii 1.0\n;plyFile element vertex point3D.rows \n;plyFile property float x\n;plyFile property float y\n;plyFile property float z\n;plyFile property uchar blue\n;plyFile property uchar green\n;plyFile property uchar red\n;plyFile end_header\n;// 写入点云数据for (int i 0; i point3D.rows; i){Vec3b color pointColors[i];const float* point point3D.ptrfloat(i);plyFile point[0] point[1] point[2] static_castint(color[0]) static_castint(color[1]) static_castint(color[2]) endl;}plyFile.close(); return 0; }最终效果 特别提醒用 meshlab 打开后记得在右侧的设置框中将 shading 改为None 这样才能看到真正的颜色也可以把点调大一点好看些
http://www.w-s-a.com/news/542783/

相关文章:

  • 免费建个人手机网站WordPress 简历库
  • 建网站 是否 数据库阳瘘的最佳治疗方法是什么
  • 知晓程序网站怎么做网站基础维护
  • 兼职做网站赚钱吗图片设计制作哪个软件好手机
  • 做手机旅游网站智慧校园登录入口
  • 莆田网站建设维护国外极简网站
  • 百度怎样收录网站缪斯设计集团
  • 网站建设在开封找谁做wordpress 数据转换
  • 旅游网站开发的流程江苏付费网络推广培训
  • 网站软文标题2018wordpress主题
  • 德清网站设计wordpress免登录发布接
  • 可以做游戏的网站有哪些客户关系管理系统的主要功能
  • 整人关不掉的网站怎么做广东省网站免备案表
  • 网站设计素材edu域名网站
  • 中山学校的网站建设wordpress文章图片显示不出
  • 兰溪城市建设规划网站网站联盟的基本流程
  • 免费推广网站注册入口小说阅读网站怎么建设
  • 新网站怎么做网络推广怎么做企业网站排名
  • jsp商业网站开发网站链接如何做二维码
  • 江苏高校品牌专业建设网站怎么制作网站搜索窗口
  • 北京app建设 网站开发公司织梦网站seo
  • 大学网站 作风建设专题汽车配件外贸出口公司
  • 东莞做网站系统购物网站建设精英
  • 建设vip网站相关视频网站营销建设公司
  • 微站直播平台杭州seo按天计费
  • seo 新旧网站 两个域名福州设计网站建设
  • 如何做网站客户端如何做网络营销网站
  • 苏州网站建设制度打鱼网站建设
  • 瓜子二手车直卖网上海小红书seo
  • 天津中小企业网站制作珠海做网站的