python 三邊測量定位的實(shí)現(xiàn)代碼
定位原理很簡單,故不贅述,直接上源碼,內(nèi)附注釋。(如果對您的學(xué)習(xí)有所幫助,還請幫忙點(diǎn)個(gè)贊,謝謝了)
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Wed May 16 10:50:29 2018 @author: dag """ import sympy import numpy as np import math from matplotlib.pyplot import plot from matplotlib.pyplot import show import matplotlib.pyplot as plt import matplotlib #解決無法顯示中文問題,fname是加載字體路徑,根據(jù)自身pc實(shí)際確定,具體請百度 zhfont1 = matplotlib.font_manager.FontProperties(fname='/System/Library/Fonts/Hiragino Sans GB W3.ttc') #隨機(jī)產(chǎn)生3個(gè)參考節(jié)點(diǎn)坐標(biāo) maxy = 1000 maxx = 1000 cx = maxx*np.random.rand(3) cy = maxy*np.random.rand(3) dot1 = plot(cx,cy,'k^') #生成盲節(jié)點(diǎn),以及其與參考節(jié)點(diǎn)歐式距離 mtx = maxx*np.random.rand() mty = maxy*np.random.rand() plt.hold('on') dot2 = plot(mtx,mty,'go') da = math.sqrt(np.square(mtx-cx[0])+np.square(mty-cy[0])) db = math.sqrt(np.square(mtx-cx[1])+np.square(mty-cy[1])) dc = math.sqrt(np.square(mtx-cx[2])+np.square(mty-cy[2])) #計(jì)算定位坐標(biāo) def triposition(xa,ya,da,xb,yb,db,xc,yc,dc): x,y = sympy.symbols('x y') f1 = 2*x*(xa-xc)+np.square(xc)-np.square(xa)+2*y*(ya-yc)+np.square(yc)-np.square(ya)-(np.square(dc)-np.square(da)) f2 = 2*x*(xb-xc)+np.square(xc)-np.square(xb)+2*y*(yb-yc)+np.square(yc)-np.square(yb)-(np.square(dc)-np.square(db)) result = sympy.solve([f1,f2],[x,y]) locx,locy = result[x],result[y] return [locx,locy] #解算得到定位節(jié)點(diǎn)坐標(biāo) [locx,locy] = triposition(cx[0],cy[0],da,cx[1],cy[1],db,cx[2],cy[2],dc) plt.hold('on') dot3 = plot(locx,locy,'r*') #顯示腳注 x = [[locx,cx[0]],[locx,cx[1]],[locx,cx[2]]] y = [[locy,cy[0]],[locy,cy[1]],[locy,cy[2]]] for i in range(len(x)): plt.plot(x[i],y[i],linestyle = '--',color ='g' ) plt.title('三邊測量法的定位',fontproperties=zhfont1) plt.legend(['參考節(jié)點(diǎn)','盲節(jié)點(diǎn)','定位節(jié)點(diǎn)'], loc='lower right',prop=zhfont1) show() derror = math.sqrt(np.square(locx-mtx) + np.square(locy-mty)) print(derror)
輸出效果圖:
補(bǔ)充:python opencv實(shí)現(xiàn)三角測量(triangulation)
看代碼吧~
import cv2 import numpy as np import scipy.io as scio if __name__ == '__main__': print("main function.") #驗(yàn)證點(diǎn) point = np.array([1.0 ,2.0, 3.0]) #獲取相機(jī)參數(shù) cams_data = scio.loadmat('/data1/dy/SuperSMPL/data/AMAfMvS_Dataset/cameras_I_crane.mat') Pmats = cams_data['Pmats'] # Pmats(8, 3, 4) 投影矩陣 P1 = Pmats[0,::] P3 = Pmats[2,::] #通過投影矩陣將點(diǎn)從世界坐標(biāo)投到像素坐標(biāo) pj1 = np.dot(P1, np.vstack([point.reshape(3,1),np.array([1])])) pj3 = np.dot(P3, np.vstack([point.reshape(3,1),np.array([1])])) point1 = pj1[:2,:]/pj1[2,:]#兩行一列,齊次坐標(biāo)轉(zhuǎn)化 point3 = pj3[:2,:]/pj3[2,:] #利用投影矩陣以及對應(yīng)像素點(diǎn),進(jìn)行三角測量 points = cv2.triangulatePoints(P1,P3,point1,point3) #齊次坐標(biāo)轉(zhuǎn)化并輸出 print(points[0:3,:]/points[3,:])
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教。
- Python實(shí)現(xiàn)圖片指定位置加圖片水?。ǜ絇yinstaller打包exe)
- python3定位并識(shí)別圖片驗(yàn)證碼實(shí)現(xiàn)自動(dòng)登錄功能
- python selenium xpath定位操作
- 基于selenium及python實(shí)現(xiàn)下拉選項(xiàng)定位select
- Python selenium模塊實(shí)現(xiàn)定位過程解析
- python文件操作seek()偏移量,讀取指正到指定位置操作
- 利用Python實(shí)現(xiàn)某OA系統(tǒng)的自動(dòng)定位功能
- python3 使用traceback定位異常實(shí)例
相關(guān)文章
Python利用CNN實(shí)現(xiàn)對時(shí)序數(shù)據(jù)進(jìn)行分類
這篇文章主要為大家詳細(xì)介紹了Python如何利用CNN實(shí)現(xiàn)對時(shí)序數(shù)據(jù)進(jìn)行分類功能,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以了解一下2023-02-02Python利用matplotlib實(shí)現(xiàn)制作動(dòng)態(tài)條形圖
說到用 Python 制作動(dòng)態(tài)圖,首先想到的肯定是一些直接拿來就用的庫,雖然我沒做過,但是我相信一定有且不止一個(gè),搜了一圈后發(fā)現(xiàn)有個(gè)bar chart race庫看起來不錯(cuò),感興趣的可以跟隨小編一起學(xué)習(xí)一下2022-10-10Django動(dòng)態(tài)展示Pyecharts圖表數(shù)據(jù)的幾種方法
本文主要介紹了Django動(dòng)態(tài)展示Pyecharts圖表數(shù)據(jù)的幾種方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-08-08python3.x實(shí)現(xiàn)base64加密和解密
這篇文章主要為大家詳細(xì)介紹了python3.x實(shí)現(xiàn)base64加密和解密,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-03-03python中關(guān)于CIFAR10數(shù)據(jù)集的使用
這篇文章主要介紹了python中關(guān)于CIFAR10數(shù)據(jù)集的使用方式,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-02-02用python + openpyxl處理excel2007文檔思路以及心得
最近要幫做RA的老姐寫個(gè)合并excel工作表的腳本……源數(shù)據(jù)是4000+個(gè)excel 工作表,分布在9個(gè)xlsm文件里,文件內(nèi)容是中英文混雜的一些數(shù)據(jù),需要從每張表中提取需要的部分,分門別類合并到多個(gè)大的表里。2014-07-07