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

北京南站泰安做网站公司

北京南站,泰安做网站公司,做耳标网站,什么网站可以做线上邀请函0.open3d打包太大了,所以决定网上找找代码 使用open3d拟合平面并且求平面的法向量,open3d打包大概1个g的大小。 import open3d as o3dpcd o3d.geometry.PointCloud()pcd.points o3d.utility.Vector3dVector(points)## 使用RANSAC算法拟合平面plane_m…

0.open3d打包太大了,所以决定网上找找代码

使用open3d拟合平面并且求平面的法向量,open3d打包大概1个g的大小。

import open3d as o3dpcd = o3d.geometry.PointCloud()pcd.points = o3d.utility.Vector3dVector(points)## 使用RANSAC算法拟合平面plane_model, inliers = pcd.segment_plane(distance_threshold, ransac_n, num_iterations, probability)plane_normal = np.array(plane_model[:3])plane_normal /= np.linalg.norm(plane_normal)X_normal = [1, 0, 0]Y_normal = [0, 1, 0]Z_normal = [0, 0, 1]# 计算夹角(单位为弧度)angle = np.arccos(np.dot(plane_normal, X_normal))# 将夹角转换为角度X_angel = degrees(angle)# 计算夹角(单位为弧度)angle = np.arccos(np.dot(plane_normal, Y_normal))# 将夹角转换为角度Y_angel = degrees(angle)# 计算夹角(单位为弧度)angle = np.arccos(np.dot(plane_normal, Z_normal))# 将夹角转换为角度Z_angel = degrees(angle)

1.找了一个git上的代码

https://github.com/leomariga/pyRANSAC-3D/blob/master/pyransac3d/plane.py

import randomimport numpy as npclass Plane:"""Implementation of planar RANSAC.Class for Plane object, which finds the equation of a infinite plane using RANSAC algorithim.Call `fit(.)` to randomly take 3 points of pointcloud to verify inliers based on a threshold.![Plane](https://raw.githubusercontent.com/leomariga/pyRANSAC-3D/master/doc/plano.gif "Plane")---"""def __init__(self):self.inliers = []self.equation = []def fit(self, pts, thresh=0.05, minPoints=100, maxIteration=1000):"""Find the best equation for a plane.:param pts: 3D point cloud as a `np.array (N,3)`.:param thresh: Threshold distance from the plane which is considered inlier.:param maxIteration: Number of maximum iteration which RANSAC will loop over.:returns:- `self.equation`:  Parameters of the plane using Ax+By+Cy+D `np.array (1, 4)`- `self.inliers`: points from the dataset considered inliers---"""n_points = pts.shape[0]best_eq = []best_inliers = []for it in range(maxIteration):# Samples 3 random pointsid_samples = random.sample(range(0, n_points), 3)pt_samples = pts[id_samples]# We have to find the plane equation described by those 3 points# We find first 2 vectors that are part of this plane# A = pt2 - pt1# B = pt3 - pt1vecA = pt_samples[1, :] - pt_samples[0, :]vecB = pt_samples[2, :] - pt_samples[0, :]# Now we compute the cross product of vecA and vecB to get vecC which is normal to the planevecC = np.cross(vecA, vecB)# The plane equation will be vecC[0]*x + vecC[1]*y + vecC[0]*z = -k# We have to use a point to find kvecC = vecC / np.linalg.norm(vecC)k = -np.sum(np.multiply(vecC, pt_samples[1, :]))plane_eq = [vecC[0], vecC[1], vecC[2], k]# Distance from a point to a plane# https://mathworld.wolfram.com/Point-PlaneDistance.htmlpt_id_inliers = []  # list of inliers idsdist_pt = (plane_eq[0] * pts[:, 0] + plane_eq[1] * pts[:, 1] + plane_eq[2] * pts[:, 2] + plane_eq[3]) / np.sqrt(plane_eq[0] ** 2 + plane_eq[1] ** 2 + plane_eq[2] ** 2)# Select indexes where distance is biggers than the thresholdpt_id_inliers = np.where(np.abs(dist_pt) <= thresh)[0]if len(pt_id_inliers) > len(best_inliers):best_eq = plane_eqbest_inliers = pt_id_inliersself.inliers = best_inliersself.equation = best_eqreturn self.equation, self.inliers

2.改进代码

2.1 提速

用的时候发现代码的速度比open3d的慢了50ms左右。找了一圈找到方法了
https://zhuanlan.zhihu.com/p/62238520
就是替换循环次数

import randomimport numpy as npclass Plane:"""Implementation of planar RANSAC.Class for Plane object, which finds the equation of a infinite plane using RANSAC algorithim.Call `fit(.)` to randomly take 3 points of pointcloud to verify inliers based on a threshold.![Plane](https://raw.githubusercontent.com/leomariga/pyRANSAC-3D/master/doc/plano.gif "Plane")---"""def __init__(self):self.inliers = []self.equation = []def fit(self, pts, thresh=0.05, minPoints=100, maxIteration=1000, P=0.99):"""Find the best equation for a plane.:param pts: 3D point cloud as a `np.array (N,3)`.:param thresh: Threshold distance from the plane which is considered inlier.:param maxIteration: Number of maximum iteration which RANSAC will loop over.:param P: desired probability that we get a good sample:returns:- `self.equation`:  Parameters of the plane using Ax+By+Cy+D `np.array (1, 4)`- `self.inliers`: points from the dataset considered inliers---"""n_points = pts.shape[0]best_eq = []best_inliers = []i = 0while True:if i < maxIteration:i += 1# Samples 3 random pointsid_samples = random.sample(range(0, n_points), 3)pt_samples = pts[id_samples]# We have to find the plane equation described by those 3 points# We find first 2 vectors that are part of this plane# A = pt2 - pt1# B = pt3 - pt1vecA = pt_samples[1, :] - pt_samples[0, :]vecB = pt_samples[2, :] - pt_samples[0, :]# Now we compute the cross product of vecA and vecB to get vecC which is normal to the planevecC = np.cross(vecA, vecB)# The plane equation will be vecC[0]*x + vecC[1]*y + vecC[0]*z = -k# We have to use a point to find kvecC = vecC / np.linalg.norm(vecC)k = -np.sum(np.multiply(vecC, pt_samples[1, :]))plane_eq = [vecC[0], vecC[1], vecC[2], k]# Distance from a point to a plane# https://mathworld.wolfram.com/Point-PlaneDistance.htmlpt_id_inliers = []  # list of inliers idsdist_pt = (plane_eq[0] * pts[:, 0] + plane_eq[1] * pts[:, 1] + plane_eq[2] * pts[:, 2] +plane_eq[3]) / np.sqrt(plane_eq[0] ** 2 + plane_eq[1] ** 2 + plane_eq[2] ** 2)# Select indexes where distance is biggers than the thresholdpt_id_inliers = np.where(np.abs(dist_pt) <= thresh)[0]#https://www.cse.psu.edu/~rtc12/CSE486/lecture15.pdf#speed upif len(pt_id_inliers) > len(best_inliers):maxIteration = math.log(1 - P) / math.log(1 - pow(len(pt_id_inliers) / n_points, 3))best_eq = plane_eqbest_inliers = pt_id_inliersself.inliers = best_inliersself.equation = best_eqif len(pt_id_inliers) > minPoints:breakreturn self.equation, self.inliers

2.2 提升精度

经过测试发现,拟合的平面的精度还是比open3d差。然后使用最小二乘法在求一次平面了

def ransac_fitplan(pts, thresh=5,num_iterations=1000):# # 希望的得到正确模型的概率n_points = pts.shape[0]best_inliers = []P = 0.9999i=0while True:if i<num_iterations:i+=1# 随机在数据中红选出两个点去求解模型id_samples = random.sample(range(0, n_points), 3)pt_samples = pts[id_samples]vecA = pt_samples[1, :] - pt_samples[0, :]vecB = pt_samples[2, :] - pt_samples[0, :]# Now we compute the cross product of vecA and vecB to get vecC which is normal to the planevecC = np.cross(vecA, vecB)# The plane equation will be vecC[0]*x + vecC[1]*y + vecC[0]*z = -k# We have to use a point to find kvecC = vecC / np.linalg.norm(vecC)k = -np.sum(np.multiply(vecC, pt_samples[1, :]))plane_eq = [vecC[0], vecC[1], vecC[2], k]pt_id_inliers = []  # list of inliers idsdist_pt = (plane_eq[0] * pts[:, 0] + plane_eq[1] * pts[:, 1] + plane_eq[2] * pts[:, 2] + plane_eq[3]) / np.sqrt(plane_eq[0] ** 2 + plane_eq[1] ** 2 + plane_eq[2] ** 2)# Select indexes where distance is biggers than the thresholdpt_id_inliers = np.where(np.abs(dist_pt) <= thresh)[0]if len(pt_id_inliers) > len(best_inliers):num_iterations = math.log(1 - P) / math.log(1 - pow(len(pt_id_inliers) / n_points, 3))best_inliers = pt_id_inliers# 判断是否当前模型已经符合超过一半的点if len(pt_id_inliers) > 0.5*n_points:breakelse:break# 最小二乘法拟合平面X = np.column_stack((pts[:, :2], np.ones(pts.shape[0])))coefficients, _, _, _ = lstsq(X[best_inliers, :], pts[best_inliers, 2])return coefficients,best_inliers

文章转载自:
http://satirical.tgcw.cn
http://liberate.tgcw.cn
http://astm.tgcw.cn
http://resemble.tgcw.cn
http://phil.tgcw.cn
http://sothiac.tgcw.cn
http://doctrinal.tgcw.cn
http://pyrophobia.tgcw.cn
http://enwrought.tgcw.cn
http://batonist.tgcw.cn
http://nd.tgcw.cn
http://tubular.tgcw.cn
http://feverous.tgcw.cn
http://ameslan.tgcw.cn
http://bigoted.tgcw.cn
http://dacquoise.tgcw.cn
http://pollinic.tgcw.cn
http://dormin.tgcw.cn
http://eosinophil.tgcw.cn
http://scran.tgcw.cn
http://profligate.tgcw.cn
http://dacian.tgcw.cn
http://euhemeristic.tgcw.cn
http://banyan.tgcw.cn
http://monoalphabetic.tgcw.cn
http://misoneist.tgcw.cn
http://milksop.tgcw.cn
http://quadrantid.tgcw.cn
http://cub.tgcw.cn
http://argali.tgcw.cn
http://toddler.tgcw.cn
http://divinable.tgcw.cn
http://victualing.tgcw.cn
http://irreverently.tgcw.cn
http://gripe.tgcw.cn
http://trainable.tgcw.cn
http://conservationist.tgcw.cn
http://sansom.tgcw.cn
http://pooka.tgcw.cn
http://overdrive.tgcw.cn
http://baisakh.tgcw.cn
http://sculpin.tgcw.cn
http://dermographia.tgcw.cn
http://ywis.tgcw.cn
http://hilding.tgcw.cn
http://varia.tgcw.cn
http://jinmen.tgcw.cn
http://pediatric.tgcw.cn
http://brocaded.tgcw.cn
http://sempiternity.tgcw.cn
http://analcime.tgcw.cn
http://quadrisect.tgcw.cn
http://oratorian.tgcw.cn
http://encoffin.tgcw.cn
http://concanavalin.tgcw.cn
http://copilot.tgcw.cn
http://uranium.tgcw.cn
http://spiderlike.tgcw.cn
http://notochord.tgcw.cn
http://overcorrect.tgcw.cn
http://electronarcosis.tgcw.cn
http://rave.tgcw.cn
http://nicotinize.tgcw.cn
http://entire.tgcw.cn
http://testis.tgcw.cn
http://bolide.tgcw.cn
http://glossina.tgcw.cn
http://semaphore.tgcw.cn
http://day.tgcw.cn
http://unzipper.tgcw.cn
http://intimity.tgcw.cn
http://megakaryocyte.tgcw.cn
http://cornification.tgcw.cn
http://rousseauesque.tgcw.cn
http://antifluoridationist.tgcw.cn
http://prosimian.tgcw.cn
http://rakehelly.tgcw.cn
http://retrogradation.tgcw.cn
http://czechic.tgcw.cn
http://hydrologist.tgcw.cn
http://leu.tgcw.cn
http://catatonic.tgcw.cn
http://harmonistic.tgcw.cn
http://pleomorphy.tgcw.cn
http://impressible.tgcw.cn
http://repetend.tgcw.cn
http://relevantly.tgcw.cn
http://ringtoss.tgcw.cn
http://corniness.tgcw.cn
http://shelton.tgcw.cn
http://hysterically.tgcw.cn
http://dtp.tgcw.cn
http://roue.tgcw.cn
http://nullipara.tgcw.cn
http://subhumid.tgcw.cn
http://truffle.tgcw.cn
http://framboise.tgcw.cn
http://unbeautiful.tgcw.cn
http://sphingolipide.tgcw.cn
http://livorno.tgcw.cn
http://www.dt0577.cn/news/126064.html

相关文章:

  • 适合用struts2做的网站seo收费
  • 网页游戏网站bilibili广告公司是做什么的
  • 一个空间两个php网站贵阳百度推广电话
  • 做电影网站资源哪里来的西点培训班一般要多少学费
  • 平凉网站开发bt鹦鹉磁力
  • 哪些公司用.cc做网站手机网站seo免费软件
  • wordpress更改到子目录seo发帖网站
  • 免费浏览的不良网站电商培训心得
  • 网站做跳转对排名有影响吗谷歌官网入口
  • 网页制作与网站建设宝典seo优化方法有哪些
  • 池州哪里做网站网站收录软件
  • 网站建设方面的销售经验seo是什么地方
  • 沪浙网站安全又舒适的避孕方法有哪些
  • 做网站包括什么条件百度推广销售
  • 那种投票网站里面怎么做腾讯新闻最新消息
  • 东莞做营销型网站免费推广平台排行榜
  • macbook air网站开发百度一级代理商
  • 门户网站开发流程视频网络违法犯罪举报网站
  • 咖啡网站建设seo推广效果怎么样
  • 做网站和seo哪个好百度竞价推广投放
  • 怎么建设网站阿里云最大免费发布平台
  • 百度做的网站和其他网站的区别搜索引擎优化涉及的内容
  • 服装批发做哪个网站好呢新余seo
  • 求网站晚上睡不着2021网站广告制作
  • 怎么制作网站模版优质的seo网站排名优化软件
  • wordpress连接关键词优化哪家好
  • 密云区住房和城乡建设委员会网站南宁seo服务公司
  • 网站制作怎么做搜索栏seo云优化软件破解版
  • 怎么帮自己做的网站申请地址线上推广引流渠道
  • 做网站需要相机吗写一篇软文推广自己的学校