事情是這樣的
小弟,我目前在做一個無人機相關的小專題
想用AprilTag結合PID的方式來做定位
以及讓無人機朝指定的方向前進
但是目前每當April_Tag判斷一段時間後就會自動跳出
然後就出現
File "D:\Code\apriltag\AprilPy\lib\site-packages\pupil_apriltags\bindings.py", line 336, in init
dll_dir = os.add_dll_directory(dll_path)
File "C:\Users\sting\AppData\Local\Programs\Python\Python310\lib\os.py", line 1117, in add_dll_directory
cookie = nt._add_dll_directory(path)
FileNotFoundError: [WinError 206] 檔名或副檔名太長。: 'D:\Code\apriltag\AprilPy\Lib\site-packages\pupil_apriltags\lib'
請各位大大能給點開示,感謝!
這是程式碼的部分
from djitellopy import tello
import cv2
import numpy as np
from pupil_apriltags import Detector
import math
import importlib
# me = tello.Tello()
# me.connect
# me.streamon()
def calcu_line(fir , sec):
delta_X = math.pow((fir[0] - sec[0]), 2)
delta_Y = math.pow((fir[1] - sec[1]), 2)
ans = math.pow((delta_X + delta_Y), 0.5)
return ans
cap = cv2.VideoCapture(0)
if not cap.isOpened():
print("Cannot open camera")
exit()
w, h = 720, 480
fbRange = [2500, 3000]
pid = [0.3, 0.3, 0]
pError = 0
test = []
while True:
if cv2.waitKey(1) == ord('q'): break
ret, img = cap.read()
# img = me.get_frame_read().frame
reimg = cv2.resize(img, (w, h))
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
try:
result = Detector().detect(gray)
for tag in result:
for point in tag.corners:
cv2.circle(img, tuple(point.astype(int)), 4, (255, 0, 0), -1)
P1 = [tuple(tag.corners[0].astype(int))[0], tuple(tag.corners[0].astype(int))[0]]
P2 = [tuple(tag.corners[1].astype(int))[0], tuple(tag.corners[1].astype(int))[0]]
P3 = [tuple(tag.corners[2].astype(int))[0], tuple(tag.corners[2].astype(int))[0]]
P4 = [tuple(tag.corners[3].astype(int))[0], tuple(tag.corners[3].astype(int))[0]]
height = int(calcu_line(P2, P1))
width = int(calcu_line(P3, P2))
diagonal = int(calcu_line(P3, P1))
area = height*width
if area > fbRange[0] and area < fbRange[1]:
print(f"stop, {area}")
elif area > fbRange[1]:
print(f"move back, {area}")
elif area < fbRange[0] and area !=0 :
print(f"move forword, {area}")
except:
result = 0
print("206 Error")
break
cv2.imshow("out_img", img)
cv2.waitKey(10)
cap.release()
cv2.destroyAllWindows()
因為 Windows 系統有 260 個字元的檔案名長度限制,檔案名或路徑太長。
你的DLL檔案名稱或路徑太長導致發生的錯誤。
你可以
最簡單的作法是將安裝目錄移至路徑更短的地方
例如 C:\apriltag\