Error in imutils __init__.py


#1

i followed the video instructions of the course " Precision Landing and Drone Delivery"
so far
i made sure i have
dronekit2.9.2
MAVProxy1.8.16

installed
imutils
**python-opencv **
python-numpy

i did the camera calibration with the checker board successfully
downloaded the pidronescipts/ from github

i am now doing “Test OpenCV Aruco Tracker on Raspberry Pi” under “precision landing real drone” section, and i get this error when i try to run aruco_tester.py

https://github.com/dronedojo/pidronescripts/blob/master/camera/aruco_tester.py


#2

Hi there iyad,

It looks like you have
self.stream set
when it should be
self.stream.set

Take a look in the file with the init function with this command:

sudo vi /usr/local/lib/python2.7/dist-packages/imutils/video/webcamvideostream.py

And make sure the init function looks like this:


#3

yes i realized that and fixed it
thanks


#4

I cannot figure this out. I got an syntaxError on width=640 but cannot find a way to fix it. Any help :slight_smile:

Running the aruco tester i got syntaxError on width=640

Traceback (most recent call last):
File “aruco_tester.py”, line 4, in
from imutils.video import WebcamVideoStream
File “/usr/local/lib/python2.7/dist-packages/imutils/video/init.py”, line 4, in
from .videostream import VideoStream
File “/usr/local/lib/python2.7/dist-packages/imutils/video/videostream.py”, line 2, in
from .webcamvideostream import WebcamVideoStream
File “/usr/local/lib/python2.7/dist-packages/imutils/video/webcamvideostream.py”, line 6
def init(self, src=0, name=“WebcamVideoStream”)width=640, height=480):

Down below is the scripts:

import cv2
import cv2.aruco as aruco
import numpy as np
from imutils.video import WebcamVideoStream
import imutils

import time
import os
import platform
import sys
#############################

width=640
height=480
cap = WebcamVideoStream(src=0, height=height, width=width).start()
viewVideo=True
if len(sys.argv)>1:
viewVideo=sys.argv[1]
if viewVideo==‘0’ or viewVideo==‘False’ or viewVideo==‘false’:
viewVideo=False
############ARUCO/CV2############
id_to_find=72
marker_size=19 #cm

realWorldEfficiency=.7 ##Iterations/second are slower when the drone is flying. This accounts for that
aruco_dict = aruco.getPredefinedDictionary(aruco.DICT_ARUCO_ORIGINAL)
parameters = aruco.DetectorParameters_create()

calib_path="/home/pi/video2calibration/calibrationFiles/"
cameraMatrix = np.loadtxt(calib_path+‘cameraMatrix.txt’, delimiter=’,’)
cameraDistortion = np.loadtxt(calib_path+‘cameraDistortion.txt’, delimiter=’,’)
#############################

seconds=0
if viewVideo==True:
seconds=1000000
print(“Showing video feed if X11 enabled.”)
print(“Script will run until you exit.”)
print("-------------------------------")
print("")
else:
seconds=5
counter=0
counter=float(counter)

start_time=time.time()
while time.time()-start_time<seconds:
frame = cap.read() #for Threaded webcam

frame = cv2.resize(frame,(width,height))

frame_np = np.array(frame)
gray_img = cv2.cvtColor(frame_np,cv2.COLOR_BGR2GRAY)
ids=''
corners, ids, rejected = aruco.detectMarkers(image=gray_img,dictionary=aruco_dict,parameters=parameters)
if ids is not None:
    print("Found these IDs in the frame:")
    print(ids)
if ids is not None and ids[0] == id_to_find:
    ret = aruco.estimatePoseSingleMarkers(corners,marker_size,cameraMatrix=cameraMatrix,distCoeffs=cameraDistortion)
    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])
    #print("FOUND ARUCO!")
    marker_position="MARKER POSITION: x="+x+" y="+y+" z="+z
    print(marker_position)
    print("")
    if viewVideo==True:
        aruco.drawDetectedMarkers(frame_np,corners)
        aruco.drawAxis(frame_np,cameraMatrix,cameraDistortion,rvec,tvec,10)
        cv2.imshow('frame',frame_np)
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break
else:
    print("ARUCO "+str(id_to_find)+"NOT FOUND IN FRAME.")
    print("")
counter=float(counter+1)

if viewVideo==False:
frequency=realWorldEfficiency*(counter/seconds)
print("")
print("")
print("---------------------------")
print(“Loop iterations per second:”)
print(frequency)
print("---------------------------")

print("Performance Diagnosis:")
if frequency>10:
    print("Performance is more than enough for great precision landing.")
elif frequency>5:
    print("Performance likely still good enough for precision landing.")
    print("This resolution likely maximizes the detection altitude of the marker.")
else:
    print("Performance likely not good enough for precision landing.")
    print("MAKE SURE YOU HAVE A HEAT SINK ON YOUR PI!!!")
print("---------------------------")

cv2.destroyAllWindows()


#5

The error shows a syntax error at line 6, apparently due to a missing comma.

Go into the file below to check and correct this.


#6

@jax200 nailed it.

To be clear, the WebcamVideoStream class does not input width and height by default, so you need to modify this file as shown in the course. The file is most likely located here

/usr/local/lib/python2.7/dist-packages/imutils/video/webcamvideostream.py

10 points @jax200


closed #7