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
Command Line
1git clone https://github.com/luxonis/depthai-python.git
2cd depthai-python/examples
3python3 install_requirements.pyPrerequisites
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
1#!/usr/bin/env python3
2
3import depthai as dai
4import cv2
5
6# Start defining a pipeline
7pipeline = dai.Pipeline()
8
9board = dai.BoardConfig()
10board.emmc = True
11pipeline.setBoardConfig(board)
12
13# Define source and output
14camRgb = pipeline.create(dai.node.ColorCamera)
15jpegEncoder = pipeline.create(dai.node.VideoEncoder)
16
17# Properties
18camRgb.setResolution(dai.ColorCameraProperties.SensorResolution.THE_4_K)
19jpegEncoder.setDefaultProfilePreset(1, dai.VideoEncoderProperties.Profile.MJPEG)
20
21#Set a write script
22script_write = pipeline.createScript()
23script_write.setProcessor(dai.ProcessorType.LEON_CSS)
24script_write.setScript("""
25
26 import os
27 index = 1000
28 import time
29 while True:
30 # Find an unused file name first
31 while True:
32 path = '/media/mmcsd-0-0/' + str(index) + '.jpg'
33 if not os.path.exists(path):
34 break
35 index += 1
36 frame = node.io['jpeg'].get()
37 node.warn(f'Saving to EMMC: {path}')
38 with open(path, 'wb') as f:
39 f.write(frame.getData())
40 index += 1
41 time.sleep(3)
42
43""")
44
45#Set a read script
46script_read = pipeline.createScript()
47script_read.setProcessor(dai.ProcessorType.LEON_CSS)
48script_read.setScript("""
49
50 import http.server
51 import socketserver
52 import socket
53 import fcntl
54 import struct
55 import os
56
57 def get_ip_address(ifname):
58 s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
59 return socket.inet_ntoa(fcntl.ioctl(
60 s.fileno(),
61 -1071617759, # SIOCGIFADDR
62 struct.pack('256s', ifname[:15].encode())
63 )[20:24])
64
65 # Note: `chdir` here will prevent unmount, this should be improved!
66 os.chdir('/media/mmcsd-0-0')
67
68 PORT = 80
69 Handler = http.server.SimpleHTTPRequestHandler
70
71 with socketserver.TCPServer(("", PORT), Handler) as httpd:
72 ip = get_ip_address('re0')
73 node.warn(f'===== HTTP file server accessible at: http://{ip}')
74 httpd.serve_forever()
75
76""")
77
78# Linking
79
80camRgb.video.link(jpegEncoder.input)
81jpegEncoder.bitstream.link(script_write.inputs['jpeg'])
82script_write.inputs['jpeg'].setBlocking(False)
83xout = pipeline.create(dai.node.XLinkOut)
84xout.setStreamName("rgb")
85script_read.outputs['jpeg'].link(xout.input)
86
87
88# Pipeline defined, now the device is connected to
89with dai.Device(pipeline) as device:
90 # Output queue will be used to get the rgb frames from the output defined above
91 qRgb = device.getOutputQueue(name="rgb", maxSize=100, blocking=False)
92
93 while True:
94 inRgb = qRgb.tryGet()
95
96 if inRgb is not None:
97 cv2.imshow("rgb", inRgb.getCvFrame())
98
99 if cv2.waitKey(1) == ord('q'):
100 breakPipeline
Need assistance?
Head over to Discussion Forum for technical support or any other questions you might have.