import cv2
import depthai as dai
pipeline = dai.Pipeline()
board = dai.BoardConfig()
board.emmc = True
pipeline.setBoardConfig(board)
script_node = pipeline.create(dai.node.Script)
script_node.setProcessor(dai.ProcessorType.LEON_CSS)
script_node.setScript("""
import http.server
import socketserver
import socket
import fcntl
import struct
import os
dirs_list = os.listdir()
node.warn(f'{dirs_list}')
def get_ip_address(ifname):
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
return socket.inet_ntoa(fcntl.ioctl(
s.fileno(),
-1071617759, # SIOCGIFADDR
struct.pack('256s', ifname[:15].encode())
)[20:24])
# Note: `chdir` here will prevent unmount, this should be improved!
# os.chdir('/media/mmcsd-0-0')
if os.path.exists('/media/mmcsd-0-0/'):
node.warn('Media Path found')
else:
node.warn('Media Path not found')
PORT = 8080
Handler = http.server.SimpleHTTPRequestHandler
with socketserver.TCPServer(("", PORT), Handler) as httpd:
ip = get_ip_address('re0')
node.warn(f'===== HTTP file server accessible at: http://{ip}:{PORT}')
httpd.serve_forever()
""")
with dai.Device(pipeline) as device:
while True:
if cv2.waitKey(1) == ord('q'):
break