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 -; } //-- Step 1: Detect the keypoints using SURF Detector
int minHessian = ; 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 = ; double min_dist = ; //-- Quick calculation of max and min distances between keypoints
for( int i = ; 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 = ; i < descriptors_1.rows; i++ )
{ if( matches[i].distance < *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[].queryIdx].pt.x,keypoints_1[good_matches[].queryIdx].pt.y,good_matches[].queryIdx,
keypoints_2[good_matches[].trainIdx].pt.x,keypoints_2[good_matches[].trainIdx].pt.y,good_matches[].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=;
alpha1=;//测试共面
gamma1=;
alpha2=;
gamma2=; X=;
Y=;
double FOVx=;
double FOVy=FOVx*Y/X;
x1=,y1=,z1=;
x2=,y2=,z2=; /* //测角偏差补偿
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=*(atan(1.0/))-*atan(1.0/);//精确定义圆周率
std::cout<<"pi为:"<<pi<<std::endl;
alpha1=alpha1*pi/;//角度弧度转换
gamma1=gamma1*pi/;
alpha2=alpha2*pi/;
gamma2=gamma2*pi/; // 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、C1
double 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)/;
Ytarget=(Yg+Yh)/;
Ztarget=(Zg+Zh)/; 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 ;
}
共面直线测试中,没有跳进共面直线解析交点中,但结果依然正确:

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

point-position2修改版的更多相关文章
- Medoo个人修改版
Medoo是一款轻量级的php数据库操作类,下面不会介绍Medoo的使用方法,想学习Medoo请前往官网自学:http://medoo.in/ 在接触Medoo之前,一直是用自己写的php数据库操作类 ...
- Android 仿美团网,大众点评购买框悬浮效果之修改版
转帖请注明本文出自xiaanming的博客(http://blog.csdn.net/xiaanming/article/details/17761431),请尊重他人的辛勤劳动成果,谢谢! 我之前写 ...
- 黄聪:WordPress图片插件:Auto Highslide修改版(转)
一直以来很多人都很喜欢我博客使用的图片插件,因为我用的跟原版是有些不同的,效果比原版的要好,他有白色遮罩层,可以直观的知道上下翻图片和幻灯片放映模式.很多人使用原版之后发现我用的更加帅一些,于是很多人 ...
- sqm(sqlmapGUI) pcat修改版
sqlmap是一款开源的注入工具,支持几乎所有的数据库,支持get/post/cookie注入,支持错误回显注入/盲注,还有其他多种注入方法. 支持代理,指纹识别技术判断数据库 .而sqm(sqlma ...
- 转载:Eclipse+Spket插件+ExtJs4修改版提供代码提示功能[图]
转载:Eclipse+Spket插件+ExtJs4修改版提供代码提示功能[图] ExtJs是一种主要用于创建前端用户界面,是一个基本与后台技术无关的前端ajax框架.功能丰富,无人能出其右.无论是界面 ...
- 若快打码平台python开发文档修改版
一.打码的作用 在进行爬虫过程中,部分网站的登录验证码是比较简单的,例如四个英文数字随机组合而成的验证码,有的是全数字随机组成的验证码,有的是全中文随机组成的验证码.为了爬虫进行自动化,需要解决自动登 ...
- 安装阿里云github提供的修改版minikube
由于kubenetes域名背墙(gcr.io),如kubernetes-dashboard服务依赖不能正常使用. $ docker pull gcr.io/google_containers/paus ...
- Indy 10.5.8 for Delphi and Lazarus 修改版(2011)
Indy 10.5.8 for Delphi and Lazarus 修改版(2011) Internet Direct(Indy)是一组开放源代码的Internet组件,涵盖了几乎所有流行的I ...
- [C语言]声明解析器cdecl修改版
一.写在前面 K&R曾经在书中承认,"C语言声明的语法有时会带来严重的问题.".由于历史原因(BCPL语言只有唯一一个类型——二进制字),C语言声明的语法在各种合理的组合下 ...
- Perl实用中文处理步骤(修改版)
发信人: FenRagwort (泽), 信区: Perl标 题: Perl实用中文处理步骤(修改版)发信站: 水木社区 (Mon Feb 14 12:52:14 2011), 转信 (修改版 感谢 ...
随机推荐
- sqls
ALTER TABLE `shh_data`.`topic_floor` ADD COLUMN `updated_date` DATETIME NULL AFTER `publish_date`,AD ...
- Spark1.0.0 编程模型
Spark Application能够在集群中并行执行,其关键是抽象出RDD的概念(详见RDD 细解),也使得Spark Application的开发变得简单明了.下图浓缩了Spark的编程模型. w ...
- 使用IntelliJ IDEA创建Maven多模块项目
转载:http://blog.csdn.net/xyw591238/article/details/52794788 使用Maven管理项目时,往往需要创建多个模块,模块之间存在相互引用的关系.对于M ...
- pip安装mysql报错 ld: library not found for -lssl
ld: library not found for -lssl clang: error: linker command failed with exit code (use -v to see in ...
- B5:责任链模式 Chain Of Responsibility
使多个对象都有机会处理处理请求,从而避免请求的发送者和接受者之间的耦合关系.将这个对象连成一条链,并沿着该链处理请求,直到有一个对象能够处理它为止. 相当于switch/case,在客户端指定了每一链 ...
- hdu1236 排名(结构体排序)
排名 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submiss ...
- (一)Oracle学习笔记—— 表和表空间
1. 表空间 一个数据库可以有多个表空间,一个表空间里可以有多个表.表空间就是存多个表的物理空间:可以指定表空间的大小位置等. 1.1 创建表空间语句 create tablespace ts3 d ...
- lucene 范围搜索表达式(range expression)
实际测试 lucene范围符号,大于等于或小于等于符号[],大于或小于符号{} newIntRange或newLongRange一样 代码: // test lucen ...
- java基础入门-多线程同步浅析-以银行转账为样例
在说之前先普及一下线程是什么? 线程:说白了就是一个任务片段 进程:是一个具有独立功能的程序关于某个数据集合的一次执行活动.一个进程有一个或者多个线程 线程与进程的本质差别就是有么有数据共享空间.线程 ...
- unity, 内存profile,ImageEffects Temp和Unity GI SystemTex RGBM
最近用unity的Profiler对公司项目进行内存profile,发现一些问题,记录一下. 用Memory Area的Detailed View,用法见:http://docs.unity3d.co ...