I am experiencing a somewhat similar issue to the above …
Would someone please check where my following (and/or attached) script could be preventing ‘aruco_landing.py’ from lanching (attached)?
I think there may be an issue with ‘except Exception as e:’, etc. In the tutorial, I’m a little confused when we do & do not include ‘as’ …
The attached screenshot includes suggestions from VS Code. I’ve followed the suggestions but the problem is still not being resolved …
file:///home/dronedojo/Downloads/Script%20(1).jpg
Caleb, I have emailed you a copy of this query …
track_aruco.py (2.7 KB)
#!/usr/bin/env python
import rospy
from sensor_msgs.msg import Image
import cv2
import cv2.aruco as aruco
import sys
import time
import math
import numpy as np
import ros_numpy as rnp
newimg_pub = rospy.Publisher(’/camera/color/image_new’, Image, queue_size=10)
id_to_find = 72
marker_size = 20
aruco_dict = aruco.getPredefinedDictionary(aruco.DICT_ARUCO_ORIGINAL)
parameters = aruco.DetectorParameters_create()
horizontal_res = 640
vertical_res = 480
horizontal_fov = 53.5 * (math.pi / 180)
vertical_fov = 41.41 * (math.pi / 180)
found_count=0
notfound_count=0
#CAMERA INTRINSICS#
dist_coeff = [0.0, 0.0, 0.0, 0.0, 0.0]
camera_matrix = [[1061.654, 0.0, 640.5],[0.0, 1061.654, 360.5],[0.0,0.0,1.0 ]]
np_camera_matrix = np.array(camera_matrix)
np_dist_coeff = np.array(dist_coeff)
time_last=0
time_to_wait = .1
def msg_receiver(message):
global notfound_count, found_count, time_last, time_to_wait, id_to_find
if time.time() - time_last > time_to_wait:
np_data = rnp.numpify(message)
gray_img = cv2.cvtColor(np_data. cv2.COLOR_BGR2GRAY)
ids = ''
(corners, ids, rejected) = aruco.detectMarkers(image=gray_img,dictionary=aruco_dict,parameters=parameters)
try:
if ids is not None:
if ids[0]==id_to_find:
ret = aruco.estimatePoseSingleMarkers(corners,marker_size,cameraMatrix=np_camera_matrix,distCoeffs=np_dist_coeff)
(rvec, tvec) = (ret[0][0,0,:],ret[1][0,0,:])
x = '{:.2f}'.format(tvec[0])
y = '{:.2f}'.format(tvec[1])
z = '{:.2f}'.format(tvec[2])
marker_position = 'MARKER POSITION: x='+x+' y='+y+' z='+z
aruco.drawDetectedMarkers(np_data.corners)
aruco.drawAxis(np_data,np_camera_matrix,np_dist_coeff,rvec,tvec,10)
cv2.putText(np_data,marker_position,(10,50),0,.5(255,0,0),thickness=1)
found_count = found_count + 1
else:
notfound_count=notfound_count+1
else:
notfound_count=notfound_count+1
except Exception as e:
print 'Target likely not found'
print e
notfound_count=notfound_count+1
new_msg = rnp.msgify(Image, np_data,encoding='rgb8')
newimg_pub.publish(new_msg)
time_last = time.time()
else:
return None
def subscriber():
rospy.init_node(‘drone_node’,anonymous=False)
sub = rospy.Subscriber(’/camera/color/image_raw’, Image, msg_receiver)
if name==‘main’:
try:
subscriber()
except rospy.ROSInterruptException:
pass