point-position2修改版

说明:

 在共面直线测试中,由于计算误差等原因,共面条件判断不准,但计算结果依然正确。

// point-position2.cpp : 定义控制台应用程序的入口点。
#include "stdafx.h"
#include <stdio.h>
#include <iostream>
#include "opencv2/core/core.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <opencv2/nonfree/features2d.hpp>
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/nonfree/nonfree.hpp"
#include "opencv2/legacy/legacy.hpp"
#include<Eigen/Core>  
#include <Eigen/Dense>
#include<math.h>
using namespace cv;int main( int argc, char** argv )
{Mat img_1 = imread("book_in_scene.png");Mat img_2 = imread("book2.png");if( !img_1.data || !img_2.data ){ std::cout<< " --(!) Error reading images " << std::endl; return -1; }//-- Step 1: Detect the keypoints using SURF Detectorint minHessian = 400;SiftFeatureDetector detector( minHessian );//SurfFeatureDetector detector( minHessian );
vector<KeyPoint> keypoints_1, keypoints_2;detector.detect( img_1, keypoints_1 );detector.detect( img_2, keypoints_2 );//-- Step 2: Calculate descriptors (feature vectors)
    SiftDescriptorExtractor extractor;//SurfDescriptorExtractor extractor;
Mat descriptors_1, descriptors_2;extractor.compute( img_1, keypoints_1, descriptors_1 );extractor.compute( img_2, keypoints_2, descriptors_2 );//-- Step 3: Matching descriptor vectors using FLANN matcher
    FlannBasedMatcher matcher;std::vector< DMatch > matches;matcher.match( descriptors_1, descriptors_2, matches );double max_dist = 0; double min_dist = 100;//-- Quick calculation of max and min distances between keypointsfor( int i = 0; i < descriptors_1.rows; i++ ){ double dist = matches[i].distance;if( dist < min_dist ) min_dist = dist;if( dist > max_dist ) max_dist = dist;}//printf("-- Max dist : %f \n", max_dist );//printf("-- Min dist : %f \n", min_dist );//-- Draw only "good" matches (i.e. whose distance is less than 2*min_dist )//-- PS.- radiusMatch can also be used here.std::vector< DMatch > good_matches;for( int i = 0; i < descriptors_1.rows; i++ ){ if( matches[i].distance < 2*min_dist ){ good_matches.push_back( matches[i]); }}//-- Draw only "good" matches
    Mat img_matches;drawMatches( img_1, keypoints_1, img_2, keypoints_2,good_matches, img_matches);//-- Show detected matches//imshow( "Good Matches", img_matches );//imwrite("Lena_match_surf.jpg",img_matches);//imwrite("Lena_match_sift.jpg",img_matches);//good_matches[i].queryIdx保存着第一张图片匹配点的序号,keypoints_1[good_matches[i].queryIdx].pt.x 为该序号对应的点的x坐标。y坐标同理//good_matches[i].trainIdx保存着第二张图片匹配点的序号,keypoints_2[good_matches[i].trainIdx].pt.x 为为该序号对应的点的x坐标。y坐标同理printf( "--Keypoint 1:%f,%f: %d  -- Keypoint 2:%f,%f: %d  \n",  keypoints_1[good_matches[0].queryIdx].pt.x,keypoints_1[good_matches[0].queryIdx].pt.y,good_matches[0].queryIdx, keypoints_2[good_matches[0].trainIdx].pt.x,keypoints_2[good_matches[0].trainIdx].pt.y,good_matches[0].trainIdx );/*_______________________________________________________________________________________________________________________________*/double x_inImage1,y_inImage1,x_inImage2,y_inImage2,y,X,Y,alpha,gamma;//像面坐标(x,y)和图像尺寸(X,Y)以及成像视场角(alpha,gamma)double x1,y1,z1,x2,y2,z2;//双站坐标double alpha1,gamma1;//双站俯仰角和偏转角double alpha2,gamma2;//赋予初始值alpha1=45;alpha1=90;//测试共面gamma1=45;alpha2=270;gamma2=45;X=640;Y=480;double FOVx=10;double FOVy=FOVx*Y/X;x1=0,y1=0,z1=0;x2=0,y2=200,z2=0;/*    //测角偏差补偿x_inImage1=keypoints_1[good_matches[0].queryIdx].pt.x;//目标点坐标由匹配所得y_inImage1=keypoints_1[good_matches[0].queryIdx].pt.y;x_inImage2=keypoints_2[good_matches[0].queryIdx].pt.x;y_inImage2=keypoints_2[good_matches[0].queryIdx].pt.y;double deviation_alpha1=(x_inImage1-X/2)/X*FOVx;double deviation_alpha2=(x_inImage2-X/2)/X*FOVx;double deviation_gamma1=(y_inImage1-Y/2)/X*FOVy;double deviation_gamma2=(y_inImage2-Y/2)/X*FOVy;alpha1=alpha1+deviation_alpha1;alpha2=alpha2+deviation_alpha2;gamma1=gamma1+deviation_gamma1;gamma2=gamma2+deviation_gamma2;
*///开始计算double pi=16*(atan(1.0/5))-4*atan(1.0/239);//精确定义圆周率std::cout<<"pi为:"<<pi<<std::endl;alpha1=alpha1*pi/180;//角度弧度转换gamma1=gamma1*pi/180;alpha2=alpha2*pi/180;gamma2=gamma2*pi/180;//    std::cout<<"cos(alpha1)为:"<<cos(alpha1)<<std::endl;
//    std::cout<<"cos(gamma1)为:"<<cos(gamma1)<<std::endl;double m1=(cos(alpha1))*(cos(gamma1));double n1=(sin(alpha1))*(cos(gamma1));double p1=sin(gamma1);double m2=(cos(alpha2))*(cos(gamma2));double n2=(sin(alpha2))*(cos(gamma2));double p2=sin(gamma2);std::cout<<"方向向量1为:"<<m1<<""<<n1<<""<<p1<<std::endl;std::cout<<"方向向量2为:"<<m2<<""<<n2<<""<<p2<<std::endl;double coplane;//共面判断coplane=(x2-x1)*(n1*p2-n2*p1)-(y2-y1)*(m1*p2-m2*p1)+(z2-z1)*(m1*n2-m2*n1);//coplane=0共面if(coplane){//计算公垂线方向向量A1、B1、C1double A1=n1*p2-n2*p1;double B1=p1*m2-p2*m1;double C1=m1*n2-m2*n1;//
        double A2=n2*C1-p2*B1;double B2=p2*A1-m2*C1;double C2=m2*B1-n2*A1;double A3=n1*C1-p1*B1;double B3=p1*A1-m1*C1;double C3=m1*B1-n1*A1;double delta1=n1*(B1*C2-B2*C1)+m1*(A1*C2-A2*C1);double delta2=n2*(B1*C3-B3*C1)+m2*(A1*C3-A3*C1);double D1=A2*(x2-x1)+B2*(y2-y1)+C2*(z2-z1);double D2=A3*(x1-x2)+B3*(y1-y2)+C3*(z1-z2);double Xg,Yg,Zg,Xh,Yh,Zh,Xtarget,Ytarget,Ztarget;//两直线垂足G和H点坐标,目标点在其中点位置。Xg=x1-(D1*m1*C1)/delta1;Yg=y1-(D1*n1*C1)/delta1;Zg=z1+D1*(A1*m1+B1*n1)/delta1;Xh=x2-(D2*m2*C1)/delta2;Yh=y2-(D2*n2*C1)/delta2;Zh=z2+D2*(A1*m2+B1*n2)/delta2;Xtarget=(Xg+Xh)/2;Ytarget=(Yg+Yh)/2;Ztarget=(Zg+Zh)/2;std::cout<<"目标坐标为:"<<Xtarget<<""<<Ytarget<<""<<Ztarget<<std::endl<<std::endl;}else//两线共面且相交,引入参数t
    {double t;t=(p2*(y1-y2)+n2*(z2-z1))/(n2*p1-p2*n1);double Xtarget,Ytarget,Ztarget;Xtarget=x1+m1*t;Ytarget=y1+n1*t;Ztarget=z1+p1*t;std::cout<<"目标坐标为:"<<Xtarget<<""<<Ytarget<<""<<Ztarget<<std::endl<<std::endl;}getchar();//waitKey(0);return 0;
}

 

共面直线测试中,没有跳进共面直线解析交点中,但结果依然正确:

单独测试共面直线求交点结果为:

 

转载于:https://www.cnblogs.com/wxl845235800/p/9067754.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/570829.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Ambari安装client报错OSError:[Error 17] File exists

Ambari为集群新增扩容过程中&#xff0c;有一个节点安装多个client报错 Traceback (most recent call last):File "/var/lib/ambari-agent/cache/stacks/HDP/2.0.6/hooks/after-INSTALL/scripts/hook.py", line 37, in <module>AfterInstallHook().execute()F…

Linux学习总结(十六)系统用户及用户组管理

先来认识两个文件/etc/passwd/etc/shadow我们打印出首尾三行&#xff0c;来了解下&#xff1a;每行由&#xff1a;分割为7段&#xff0c;每段含义为&#xff1a;第一段&#xff1a;用户名&#xff0c;比如root 用户&#xff0c;普通用户test,lv,test1第二段&#xff1a;早期存放…

linux修改hostname

1、临时修改&#xff0c;重启失效 hostname yourhostname 2、永久生效 2.1 vi /etc/sysconfig/network change HOSTNAME to yourhostname2.2 vi /proc/sys/kernel/hostnamechange to your hostnam

BZOJ2729 [HNOI2012]排队 【高精 + 组合数学】

题目链接 BZOJ2729 题解 高考数学题。。。 我们先把老师看做男生&#xff0c;女生插空站 如果两个老师相邻&#xff0c;我们把他们看做一个男生&#xff0c;女生插空站 对于\(n\)个男生\(m\)个女生的方案数&#xff1a;\[n!m!{n 1 \choose m}\] 还要特判一下没有男生女生的情况…

CentOS6离线升级CentOS7

‘利用本地centos7镜像升级centos6.7’ 需求背景&#xff1a; 服务器上安装的都是centos6.7&#xff0c;新部署的服务需要在centos7下&#xff0c;要么跑到机房重装系统&#xff0c;要么找离线解决方案&#xff0c;升级系统。 解决方案&#xff1a;之前有过离线升级小本版&a…

升级Python2.7后 no module name yum

从Python2.6.6升级到python2.7.5后导致Yum不可用。 原因是yum 命令&#xff0c;是调用的 /usr/bin/yum 脚本文件&#xff0c; 需要修改为 /usr/bin/python2.6.6 保存退出&#xff0c;成功解决。另外可能还会引起其他的问题&#xff0c;解决的思路就是根据报错的指向&#xff0…

hadoop综合大作业

Hadoop综合大作业 要求&#xff1a; 1.用Hive对爬虫大作业产生的文本文件&#xff08;或者英文词频统计下载的英文长篇小说&#xff09;词频统计。 词频统计的截图如下&#xff1a; 上次我所使用的文章是一篇中文文章&#xff0c;所以这次我用了一篇英文文档来进行分词&#xf…

Hadoop集群的kerberos认证

文章转载自http://www.cnblogs.com/easycloud/p/3724437.html 转载主要用于个人学习备查。 环境&#xff1a; OS 版本: Centos6.4 Kerberos版本: krb5-1.10.3 环境配置 机器名 Ip地址 功能 安装模块 ganglia.localdomain 192.168.124.140 Kerberos server krb5-li…

Oracle 表备份还原

方法1&#xff1a; create table mdmuser20120801 as select * from mdmuser方法2&#xff1a;create table mdmuser20120801 as select * from mdmuser where 12;insert into mdmuser20120801 select * from mdmuser ;转载于:https://www.cnblogs.com/zhchsh/p/9087331.html

HDFS文件导出本地合并为一个文件

HDFS受限于Block大小&#xff0c;大文件会分割成多个块分布在多个节点&#xff0c;导出本地的时候直接用&#xff1a; hadoop fs -get 命令会在本地创建一个目录存放多个块。 要想合并为一个大文件可以这样&#xff1a; hadoop fs -getmerge hdfs:///user/nixm/news_rank1…

MPI对道路车辆情况的Nagel-Schreckenberg 模型进行蒙特卡洛模拟

平台Ubuntu 16.04&#xff0c;Linux下MPI环境的安装见链接&#xff1a;https://blog.csdn.net/lusongno1/article/details/61709460据 Nagel-Schreckenberg 模型&#xff0c;车辆的运动满足以下规则&#xff1a;1. 假设当前速度是 v &#xff0c;和前一辆车的距离为d。2. 如…

Kerberos:cannot get master principle

The server encountered an internal error that prevented it from fulfilling this request 问题背景&#xff1a; 集群新增节点&#xff0c;添加datanode、hawq segment、pxf服务后&#xff0c;原先连接Hbase在hawq 外表报错“获取不到master principle 舍弃中……”、“Th…

BZOJ3223文艺平衡树——非旋转treap

此为平衡树系列第二道&#xff1a;文艺平衡树您需要写一种数据结构&#xff0c;来维护一个有序数列&#xff0c;其中需要提供以下操作&#xff1a; 翻转一个区间&#xff0c;例如原有序序列是5 4 3 2 1&#xff0c;翻转区间是[2,4]的话&#xff0c;结果是5 2 3 4 1 输入 第一行…

Linux centOS 硬盘分区挂载

文章转载自&#xff1a;http://linux008.blog.51cto.com/2837805/548711 1、什么是分区&#xff1f; 分区是将一个硬盘驱动器分成若干个逻辑驱动器&#xff0c;分区是把硬盘连续的区块当做一个独立的磁硬使用。分区表是一个硬盘分区的索引,分区的信息都会写进分区表。 2、为…

Ambari删除服务报错之CSRF protection is turned on

Ambari安装组件失败后执行 curl 删除服务报错 CSRF protection is turned on X-Requested_By HTTP Header is required 解决方案&#xff1a; vi /etc/ambari-server/conf/ambari-properties增加 api.csrfPrevention.enabledfalse重启Ambari: ambari-server restart重新执行s…

Android 中.aar文件生成方法与用法

https://i.cnblogs.com/EditPosts.aspx?opt1 无论是用Eclipse还是用Android Studio做android开发&#xff0c;都会接触到jar包&#xff0c;全称应该是&#xff1a;Java Archive&#xff0c;即java归档文件。在用AS的过程中&#xff0c;你会发现有aar这么个东西&#xff0c;经查…

Ambari实现HTTPS登陆

关于Ambari的安全、访问控制在这里有非常详细的介绍。 http://pivotalhd.docs.pivotal.io/docs/security-guide-ambari-2.1.2.html 另外还可以参考这一篇 https://community.hortonworks.com/articles/39865/enabling-https-for-ambariserver-and-troubleshootin.html Amba…

ffs, fls

linux内核中的宏ffs(x) linux内核中ffs(x)宏是平台相关的宏,在arm平台,该宏定义在 arch/arm/include/asm/bitops.h #define ffs(x) ({ unsigned long __t (x); fls(__t & -__t); }) __t & -__t 等于找到__t 第一个为1的位(从低位开始),并把该位保留为1其余位清0. 例…

PLSQL注册码

Product Code: 4t46t6vydkvsxekkvf3fjnpzy5wbuhphqz serial Number: 601769 password: xs374ca

【JAVA学习】09.创建BootstrapTale列表页

【提要】只要JSON 返回了rows , total ,数据就会展示在列表 【步骤】 1、页面添加Table标签用于装载数据 <table class"table" id"userTable"> <tr><td>请输入查询条件查询</td></tr>   </table> 2、页面初始化请求…