SunFounder PiCrawler Kit
(continued from previous page)
if index == 0:
flag_color = False
Vilib.color_detect('close')
else:
flag_color = True
Vilib.color_detect(color_list[index]) # color_detect(color:str -> color_
˓→name/close)
print('Color detect : %s'%color_list[index])
# face detection
elif key =="f":
flag_face = not flag_face
face_detect(flag_face)
# qrcode detection
elif key =="r":
qr_code_flag = not qr_code_flag
if qr_code_flag == True:
if qrcode_thread == None or not qrcode_thread.is_alive():
qrcode_thread = threading.Thread(target=qrcode_detect)
qrcode_thread.setDaemon(True)
qrcode_thread.start()
else:
if qrcode_thread != None and qrcode_thread.is_alive():
# wait for thread to end
qrcode_thread.join()
print('QRcode Detect: close')
# show detected object information
elif key == "s":
object_show()
sleep(0.5)
if __name__ == "__main__":
main()
How it works?
The first thing you need to pay attention to here is the following function. These two functions allow you to start the
camera.
Vilib.camera_start()
Vilib.display()
Functions related to “object detection”:
• Vilib.face_detect_switch(True) : Switch ON/OFF face detection
• Vilib.color_detect(color) : For color detection, only one color detection can be performed at the same
time. The parameters that can be input are: "red", "orange", "yellow", "green", "blue", "purple"
• Vilib.color_detect_switch(False) : Switch OFF color detection
• Vilib.qrcode_detect_switch(False) : Switch ON/OFF QR code detection, Returns the decoded data of
the QR code.
• Vilib.gesture_detect_switch(False) : Switch ON/OFF gesture detection
56 Chapter 3. Play with Python