ADEEPT AWR Wheeled Robot Manual page 108

4wd smart robot kit compatible with raspberry pi 4 3 model b+ b, opencv target tracking
Table of Contents

Advertisement

99
Set target color, HSV color space
'''
colorUpper =
np.array([44, 255,
colorLower =
np.array([24, 100,
font = cv2.FONT_HERSHEY_SIMPLEX
class
Camera(BaseCamera):
video_source = 0
def
__init__(self):
if
os.environ.get('OPENCV_CAMERA_SOURCE'):
Camera.set_video_source(int(os.environ['OPENCV_CAMERA_SOURCE']))
super(Camera, self).__init__()
@staticmethod
def
set_video_source(source):
Camera.video_source = source
@staticmethod
def
frames():
camera = cv2.VideoCapture(Camera.video_source)
if not
camera.isOpened():
raise
RuntimeError('Could not start camera.')
while True:
# read current frame
img = camera.read()
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
mask = cv2.inRange(hsv, colorLower, colorUpper)
color space, and turn these color blocks into masks
mask = cv2.erode(mask, None, iterations=2)
becomes small (small pieces of color or noise disappear)
mask = cv2.dilate(mask, None, iterations=2)
previous step to its original size
cnts = cv2.findContours(mask.copy(), cv2.RETR_EXTERNAL,
cv2.CHAIN_APPROX_SIMPLE)[-2]
center =
if len(cnts) > 0:
'''
Find the coordinates of the center point of the object of the target color and the size of the object in
the picture
255])
100])
#Get the picture captured by the camera
None
#If the number of whole masks in the picture is greater than one
#Convert captured images to HSV color space
#Traverse the colors in the target color range in the HSV
#Corrosion of small pieces of mask (noise) in the picture
#Inflate, and resize the large mask that was reduced in the
#Find a few masks in the picture

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the AWR Adeept Wheeled Robot and is the answer not in the manual?

This manual is also suitable for:

Picar-b

Table of Contents

Save PDF