首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用Python检测Aruco标记的问题

用Python检测Aruco标记的问题
EN

Stack Overflow用户
提问于 2021-12-17 13:35:24
回答 1查看 1.2K关注 0票数 -1

我试着在图像上检测到Aruco码。我在码头的朱庇特笔记本工作,所以我处理图像,而不是视频,无法访问某些功能(例如cv2.imshow('QueryImage', QueryImg) )。

基于代码:https://github.com/kyle-bersani/opencv-examples/blob/master/SimpleMarkerDetection/DetectMarkersAndPrint.py

我准备了这个剧本:

代码语言:javascript
复制
import numpy
import cv2
import cv2.aruco as aruco
from matplotlib import pyplot as plt

im = cv2.imread('ar3.jpg')

ARUCO_PARAMETERS = aruco.DetectorParameters_create()
# OLD:
# ARUCO_DICT = aruco.Dictionary_get(aruco.DICT_6X6_1000)
# NEW
ARUCO_DICT = aruco.Dictionary_get(aruco.DICT_5X5_1000)

plt.figure(figsize = (20,20))
imgplot = plt.imshow(im, interpolation='nearest')
plt.show() 

im = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY)
corners, ids, rejectedImgPoints = aruco.detectMarkers(im, ARUCO_DICT, parameters=ARUCO_PARAMETERS)

if ids is not None and len(ids) == 5:
    for i, corner in zip(ids, corners):
            print('ID: {}; Corners: {}'.format(i, corner))

    im = aruco.drawDetectedMarkers(im, corners, borderColor=(0, 0, 255))
else:
    print("NONE")
plt.figure(figsize = (20,20))
imgplot = plt.imshow(im, interpolation='nearest')
plt.show() 

并使用简单的图像和标记:

但是我的代码没有看到这些标记。

问题是代码,图像还是标记?你知不知道?

更新:我使用以下代码生成标记:

代码语言:javascript
复制
import cv2
import cv2.aruco as aruco

# Create gridboard, which is a set of Aruco markers
# the following call gets a board of markers 5 wide X 7 tall
gridboard = aruco.GridBoard_create(
        markersX=5, 
        markersY=7, 
        markerLength=0.04, 
        markerSeparation=0.01, 
        dictionary=aruco.Dictionary_get(aruco.DICT_5X5_1000))

# Create an image from the gridboard
img = gridboard.draw(outSize=(988, 1400))
cv2.imwrite("test_gridboard.jpg", img)

我得到了这张照片:

接下来,我从该图像复制标记并将其粘贴到图像中(如您在第一张图像中看到的)。此外,我还替换了词典:

代码语言:javascript
复制
# OLD:
# ARUCO_DICT = aruco.Dictionary_get(aruco.DICT_6X6_1000)
# NEW
ARUCO_DICT = aruco.Dictionary_get(aruco.DICT_5X5_1000)

但这段代码仍然不能检测到标记。此外,Google Play的任何应用程序也无法检测到它们。我用应用程序测试这个图像:

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-12-22 23:27:41

现在一切都正常了,改进后的代码:

代码语言:javascript
复制
import numpy
import cv2
import cv2.aruco as aruco
from matplotlib import pyplot as plt

im = cv2.imread('2-03.png')
# im = cv2.imread('1-07.jpg')

ARUCO_PARAMETERS = aruco.DetectorParameters_create()
ARUCO_DICT = aruco.Dictionary_get(aruco.DICT_5X5_1000)

plt.figure(figsize = (20,20))
imgplot = plt.imshow(im, interpolation='nearest')
plt.show() 

im = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY)
corners, ids, rejectedImgPoints = aruco.detectMarkers(im, ARUCO_DICT, parameters=ARUCO_PARAMETERS)

if ids is not None:
    print('detected: {}'.format(len(ids)))
    # for i, corner in zip(ids, corners):
            # print('ID: {}; Corners: {}'.format(i, corner))

    im = aruco.drawDetectedMarkers(im, corners, borderColor=(255, 0, 0))
else:
    print("NONE")
plt.figure(figsize = (20,20))
imgplot = plt.imshow(im, interpolation='nearest')
plt.show() 
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70394023

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档