Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
477 views
in Technique[技术] by (71.8m points)

python - USE np.loadtxt() IndexError: index 391 is out of bounds for axis 0 with size 4

My error is :

Point3D = np.vstack((Point3D, np.hstack((EMap[ID, 3:].reshape(-1, 2), np.zeros((4, 1))))))
IndexError: index 391 is out of bounds for axis 0 with size 4

This is the source code:

import numpy as np
import cv2
import cv2.aruco as aruco

np.set_printoptions(suppress=True, precision=4)
parameters = cv2.aruco.DetectorParameters_create()
dict = aruco.getPredefinedDictionary(aruco.DICT_4X4_1000)

EMap = np.loadtxt('EMap.txt')


def DealMarker(Img):
 
    Corners, IDs, rejectedCandidates = aruco.detectMarkers(Img, dict, parameters=parameters)
    if len(Corners) >= 4:  
        Point3D = np.empty((0, 3))
        Point2D = np.empty((0, 2))
        for i, Corner in enumerate(Corners):
            Point2D = np.vstack((Point2D, Corner.reshape(-1, 2)))
            ID = IDs.flatten()[i]
            Point3D = np.vstack((Point3D, np.hstack((EMap[ID, 3:].reshape(-1, 2), np.zeros((4, 1))))))
        
    return XXX

This is the content of the EMap.txt

  0.00       0.00       0.00     -27.00     -27.00      27.00     -27.00      27.00      27.00     -27.00      27.00
  1.00      87.00       0.00      60.00     -27.00     114.00     -27.00     114.00      27.00      60.00      27.00
  2.00       0.00      74.00     -27.00      47.00      27.00      47.00      27.00     101.00     -27.00     101.00
  3.00      87.00      74.00      60.00      47.00     114.00      47.00     114.00     101.00      60.00     101.00

index 391 is so weird that I can not solve the error

question from:https://stackoverflow.com/questions/65951166/use-np-loadtxt-indexerror-index-391-is-out-of-bounds-for-axis-0-with-size-4

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...