- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在开发一个小项目,其中我必须从图像中检测 aruco 标记,然后制作覆盖所有白色框的 3d 圆柱体或立方体。
在下面的代码中,它们是一个 detector_marker() 函数,其中我必须返回 Aruco_list,但我不知道该怎么做。如果有任何教程可以让我学习,您可以推荐我。
def getCameraMatrix():
with np.load('System.npz') as X:
camera_matrix, dist_coeff, _, _ = [X[i] for i in ('mtx','dist','rvecs','tvecs')]
return camera_matrix, dist_coeff
"""
Function Name : sin()
Input: angle (in degrees)
Output: value of sine of angle specified
Purpose: Returns the sine of angle specified in degrees
"""
def sin(angle):
return math.sin(math.radians(angle))
"""
Function Name : cos()
Input: angle (in degrees)
Output: value of cosine of angle specified
Purpose: Returns the cosine of angle specified in degrees
"""
def cos(angle):
return math.cos(math.radians(angle))
################################################################################
"""
Function Name : detect_markers()
Input: img (numpy array), camera_matrix, dist_coeff
Output: aruco list in the form [(aruco_id_1, centre_1, rvec_1, tvec_1),(aruco_id_2,
centre_2, rvec_2, tvec_2), ()....]
Purpose: This function takes the image in form of a numpy array, camera_matrix and
distortion matrix as input and detects ArUco markers in the image. For each
ArUco marker detected in image, paramters such as ID, centre coord, rvec
and tvec are calculated and stored in a list in a prescribed format. The list
is returned as output for the function
"""
def detect_markers(img, camera_matrix, dist_coeff):
markerLength = 100
aruco_list = []
######################## INSERT CODE HERE ########################
##################################################################
return aruco_list
"""
Function Name : drawAxis()
Input: img (numpy array), aruco_list, aruco_id, camera_matrix, dist_coeff
Output: img (numpy array)
Purpose: This function takes the above specified outputs and draws 3 mutually
perpendicular axes on the specified aruco marker in the image and
returns the modified image.
"""
def drawAxis(img, aruco_list, aruco_id, camera_matrix, dist_coeff):
for x in aruco_list:
if aruco_id == x[0]:
rvec, tvec = x[2], x[3]
markerLength = 100
m = markerLength/2
pts = np.float32([[-m,m,0],[m,m,0],[-m,-m,0],[-m,m,m]])
pt_dict = {}
imgpts, _ = cv2.projectPoints(pts, rvec, tvec, camera_matrix, dist_coeff)
for i in range(len(pts)):
pt_dict[tuple(pts[i])] = tuple(imgpts[i].ravel())
src = pt_dict[tuple(pts[0])]; dst1 = pt_dict[tuple(pts[1])];
dst2 = pt_dict[tuple(pts[2])]; dst3 = pt_dict[tuple(pts[3])];
img = cv2.line(img, src, dst1, (0,255,0), 4)
img = cv2.line(img, src, dst2, (255,0,0), 4)
img = cv2.line(img, src, dst3, (0,0,255), 4)
return img
"""
Function Name : drawCube()
Input: img (numpy array), aruco_list, aruco_id, camera_matrix, dist_coeff
Output: img (numpy array)
Purpose: This function takes the above specified outputs and draws a cube
on the specified aruco marker in the image and returns the modified
image.
"""
def drawCube(img, ar_list, ar_id, camera_matrix, dist_coeff):
for x in ar_list:
if ar_id == x[0]:
rvec, tvec = x[2], x[3]
markerLength = 100
m = markerLength/2
######################## INSERT CODE HERE ########################
##################################################################
return img
"""
Function Name : drawCylinder()
Input: img (numpy array), aruco_list, aruco_id, camera_matrix, dist_coeff
Output: img (numpy array)
Purpose: This function takes the above specified outputs and draws a cylinder
on the specified aruco marker in the image and returns the modified
image.
"""
def drawCylinder(img, ar_list, ar_id, camera_matrix, dist_coeff):
for x in ar_list:
if ar_id == x[0]:
rvec, tvec = x[2], x[3]
markerLength = 100
radius = markerLength/2; height = markerLength*1.5
######################## INSERT CODE HERE ########################
##################################################################
return img
"""
MAIN CODE
This main code reads images from the test cases folder and converts them into
numpy array format using cv2.imread. Then it draws axis, cubes or cylinders on
the ArUco markers detected in the images.
"""
if __name__=="__main__":
cam, dist = getCameraMatrix()
img = cv2.imread("..\\TestCases\\image_1.jpg")
aruco_list = detect_markers(img, cam, dist)
for i in aruco_list:
img = drawAxis(img, aruco_list, i[0], cam, dist)
## img = drawCube(img, aruco_list, i[0], cam, dist)
## img = drawCylinder(img, aruco_list, i[0], cam, dist)
cv2.imshow("img", img)
cv2.waitKey(0)
cv2.destroyAllWindows()
我对这些东西很陌生,所以这对我来说似乎有点困难。请帮帮我。
最佳答案
要检测 aruco 标记,您需要图像或框架、用于在您的情况下创建标记的 aruco 字典或 aruco 原始版本或此处的 5x5 更多信息:https://docs.opencv.org/trunk/d5/d0b/classcv_1_1aruco_1_1Dictionary.html
然后你可以使用这个函数来检测aruco标记:
aruco_dict = aruco.Dictionary_get(aruco.YOUR ARUCO DICTIONARY HERE)
parameters = aruco.DetectorParameters_create()
corners, ids, rejectedImgPoints = cv2.aruco.detectMarkers(img, aruco_dict, parameters=parameters)
id 是检测到的 arucos 的列表,角是那里的位置。
关于python - 如何在 ArUco 标记上制作 3D 圆柱体/立方体?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53424332/
我正在对发生在自身包裹的方形网格上的事物进行建模(即,如果您向上走过最高点,您最终会到达最低点,就像一个圆柱体;如果您向右走,您只是击中边界)。我需要跟踪各种代理的位置,不同点的资源量,并根据一定的规
我正在尝试显示具有 3 个圆柱体和 3 种不同颜色的轴。这是我的代码; glDisable(GL_LIGHTING); glClear(GL_COLOR_BUFFER_BIT); glColor3f(
我正在 Matlab 中做一个数学实验,结果应该是 x,y 平面上的一个圆。但有时,圆圈开始螺旋上升。我现在正在尝试将 x,y 平面弯曲成圆柱体(如下图所示)。目前我只有点的 x 和 y 坐标。 我试
我正在尝试在 3D 空间中创建一个圆柱体。我在 3D 中获得起点和终点并放置顶点,我需要为圆柱体的底部和顶部创建 2 个圆。我考虑制作一个坐标为 (1,0,0) 的 vector u 并计算方向 ve
我有以下代码可以在 View 中显示 3D 圆柱体。在设备上查看时,手势会在 x 轴(上下滑动手势)和 y 轴(左右滑动)上旋转圆柱体,但 z 轴被锁定。我相信这是 allowsCameraContr
我需要对我的圆柱体进行纹理处理,我有texture.png并且我已经做了一个多边形网格(带有三角形)。 如果您需要的话,这是代码 pastebin import pyglet import pygle
我是新的 opengl 学习者。我知道有内置函数可以在过剩的情况下绘制圆柱体,比如 GLUquadricObj *quadratic; quadratic=gluNewQuadric(); gluCy
我试图在我的 React 组件中添加圆柱体 3D 图表。但是,我遇到了这个错误。 Error: Highcharts error #17: www.highcharts.com/errors/17/?
我的第一篇文章在这里。 :)我目前正在用 C 语言为我的学校项目编写光线追踪器。我已经可以显示带有一些灯光效果的球体、三角形和平面。现在我想显示圆柱体(然后是圆锥体,但首先是圆柱体!)。我选择有一个平
我正在开发一个小项目,其中我必须从图像中检测 aruco 标记,然后制作覆盖所有白色框的 3d 圆柱体或立方体。 在下面的代码中,它们是一个 detector_marker() 函数,其中我必须返回
我已经计算了索贝尔梯度的大小和方向。但我一直不知道如何进一步使用它来进行形状检测。 图像>灰度>索贝尔过滤>索贝尔梯度和方向计算>下一步? 使用的 Sobel 内核是: Kx = ([[1, 0, -
我想将 Canvas 呈现为圆柱形锥体,您可以像轮子一样在两个方向上旋转。这在 JS/CSS3 中完全可行吗? 最佳答案 您应该看看这个新的 CSS3 功能:自定义过滤器/CSS 着色器。 这里有一些
我是一名优秀的程序员,十分优秀!