Script EMMC access
This example requires a device with onboard EMMC memory (e.g. OAK-1-POE). To check whether your device has EMMC memory, run the bootloader version script at Bootloader Version and check whether the output contains
Memory.EMMC
./media/mmcsd-0-0/
. The first script in the pipeline works by writing an image to EMMC memory. The second script starts a webserver on :/media/mmcsd-0-0/
directory and serves the image from EMMC memory.Setup
Please run the install script to download all required dependencies. Please note that this script must be ran from git context, so you have to download the depthai-python repository first and then run the scriptCommand Line
1git clone https://github.com/luxonis/depthai-python.git
2cd depthai-python/examples
3python3 install_requirements.py
Prerequisites
We first need to enable the EMMC memory as storage on the device. To do so, we need to flash the device with an application that has EMMC enabled.Example application:Command Line
1import depthai as dai
2
3 # Create pipeline
4 pipeline = dai.Pipeline()
5
6 # Set board config
7 board = dai.BoardConfig()
8 board.emmc = True
9 config = dai.Device.Config()
10 config.board = board
11 pipeline.setBoardConfig(board)
12
13 (f, bl) = dai.DeviceBootloader.getFirstAvailableDevice()
14 bootloader = dai.DeviceBootloader(bl)
15 progress = lambda p : print(f'Flashing progress: {p*100:.1f}%')
16 (r, errmsg) = bootloader.flash(progress, pipeline, memory=dai.DeviceBootloader.Memory.EMMC)
17 if r: print("Flash OK")
Source code
Python
Python
PythonGitHub
1import depthai as dai
2import cv2
3
4# Start defining a pipeline
5pipeline = dai.Pipeline()
6
7board = dai.BoardConfig()
8board.emmc = True
9pipeline.setBoardConfig(board)
10
11# Define source and output
12camRgb = pipeline.create(dai.node.ColorCamera)
13jpegEncoder = pipeline.create(dai.node.VideoEncoder)
14
15# Properties
16camRgb.setResolution(dai.ColorCameraProperties.SensorResolution.THE_4_K)
17jpegEncoder.setDefaultProfilePreset(1, dai.VideoEncoderProperties.Profile.MJPEG)
18
19#Set a write script
20script_write = pipeline.createScript()
21script_write.setProcessor(dai.ProcessorType.LEON_CSS)
22script_write.setScript("""
23
24 import os
25 index = 1000
26 import time
27 while True:
28 # Find an unused file name first
29 while True:
30 path = '/media/mmcsd-0-0/' + str(index) + '.jpg'
31 if not os.path.exists(path):
32 break
33 index += 1
34 frame = node.io['jpeg'].get()
35 node.warn(f'Saving to EMMC: {path}')
36 with open(path, 'wb') as f:
37 f.write(frame.getData())
38 index += 1
39 time.sleep(3)
40
41""")
42
43#Set a read script
44script_read = pipeline.createScript()
45script_read.setProcessor(dai.ProcessorType.LEON_CSS)
46script_read.setScript("""
47
48 import http.server
49 import socketserver
50 import socket
51 import fcntl
52 import struct
53 import os
54
55 def get_ip_address(ifname):
56 s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
57 return socket.inet_ntoa(fcntl.ioctl(
58 s.fileno(),
59 -1071617759, # SIOCGIFADDR
60 struct.pack('256s', ifname[:15].encode())
61 )[20:24])
62
63 # Note: `chdir` here will prevent unmount, this should be improved!
64 os.chdir('/media/mmcsd-0-0')
65
66 PORT = 80
67 Handler = http.server.SimpleHTTPRequestHandler
68
69 with socketserver.TCPServer(("", PORT), Handler) as httpd:
70 ip = get_ip_address('re0')
71 node.warn(f'===== HTTP file server accessible at: http://{ip}')
72 httpd.serve_forever()
73
74""")
75
76# Linking
77
78camRgb.video.link(jpegEncoder.input)
79jpegEncoder.bitstream.link(script_write.inputs['jpeg'])
80script_write.inputs['jpeg'].setBlocking(False)
81xout = pipeline.create(dai.node.XLinkOut)
82xout.setStreamName("rgb")
83script_read.outputs['jpeg'].link(xout.input)
84
85
86# Pipeline defined, now the device is connected to
87with dai.Device(pipeline) as device:
88 # Output queue will be used to get the rgb frames from the output defined above
89 qRgb = device.getOutputQueue(name="rgb", maxSize=100, blocking=False)
90
91 while True:
92 inRgb = qRgb.tryGet()
93
94 if inRgb is not None:
95 cv2.imshow("rgb", inRgb.getCvFrame())
96
97 if cv2.waitKey(1) == ord('q'):
98 break
Pipeline
Need assistance?
Head over to Discussion Forum for technical support or any other questions you might have.