mirror of
https://github.com/openmv/openmv.git
synced 2025-09-26 23:09:13 +08:00
scripts/examples: Update rstp scripts to use the new CSI API.
Also delete the other scripts using disable_fb() as they were meant for the RPC desktop library which has been deleted.
This commit is contained in:
parent
84c3db58a4
commit
6fe99051cb
@ -1,92 +0,0 @@
|
|||||||
# This work is licensed under the MIT license.
|
|
||||||
# Copyright (c) 2013-2023 OpenMV LLC. All rights reserved.
|
|
||||||
# https://github.com/openmv/openmv/blob/master/LICENSE
|
|
||||||
#
|
|
||||||
# Image Transfer - As The Remote Device
|
|
||||||
#
|
|
||||||
# This script is meant to talk to the "image_transfer_jpg_as_the_controller_device.py" on your computer.
|
|
||||||
#
|
|
||||||
# This script shows off how to transfer the frame buffer to your computer as a jpeg image.
|
|
||||||
|
|
||||||
import rpc
|
|
||||||
import sensor
|
|
||||||
import struct
|
|
||||||
|
|
||||||
sensor.reset()
|
|
||||||
sensor.set_pixformat(sensor.RGB565)
|
|
||||||
sensor.set_framesize(sensor.QVGA)
|
|
||||||
sensor.skip_frames(time=2000)
|
|
||||||
|
|
||||||
# The RPC library above is installed on your OpenMV Cam and provides multiple classes for
|
|
||||||
# allowing your OpenMV Cam to be controlled over USB or LAN/WLAN.
|
|
||||||
|
|
||||||
################################################################
|
|
||||||
# Choose the interface you wish to control your OpenMV Cam over.
|
|
||||||
################################################################
|
|
||||||
|
|
||||||
# Uncomment the below line to setup your OpenMV Cam for control over a USB VCP.
|
|
||||||
#
|
|
||||||
interface = rpc.rpc_usb_vcp_slave()
|
|
||||||
|
|
||||||
# Uncomment the below line to setup your OpenMV Cam for control over the lan.
|
|
||||||
# import network
|
|
||||||
#
|
|
||||||
# network_if = network.LAN()
|
|
||||||
# network_if.active(True)
|
|
||||||
# network_if.ifconfig('dhcp')
|
|
||||||
#
|
|
||||||
# interface = rpc.rpc_network_slave(network_if)
|
|
||||||
|
|
||||||
# Uncomment the below line to setup your OpenMV Cam for control over the wlan.
|
|
||||||
#
|
|
||||||
# import network
|
|
||||||
# network_if = network.WLAN(network.STA_IF)
|
|
||||||
# network_if.active(True)
|
|
||||||
# network_if.connect('your-ssid', 'your-password')
|
|
||||||
#
|
|
||||||
# interface = rpc.rpc_network_slave(network_if)
|
|
||||||
|
|
||||||
################################################################
|
|
||||||
# Call Backs
|
|
||||||
################################################################
|
|
||||||
|
|
||||||
|
|
||||||
# When called sets the pixformat and framesize, takes a snapshot
|
|
||||||
# and then returns the frame buffer jpg size to store the image in.
|
|
||||||
#
|
|
||||||
# data is a pixformat string and framesize string.
|
|
||||||
def jpeg_image_snapshot(data):
|
|
||||||
pixformat, framesize = bytes(data).decode().split(",")
|
|
||||||
sensor.set_pixformat(eval(pixformat))
|
|
||||||
sensor.set_framesize(eval(framesize))
|
|
||||||
img = sensor.snapshot()
|
|
||||||
img.to_jpeg(quality=90)
|
|
||||||
return struct.pack("<I", img.size())
|
|
||||||
|
|
||||||
|
|
||||||
def jpeg_image_read_cb():
|
|
||||||
interface.put_bytes(sensor.get_fb().bytearray(), 5000) # timeout
|
|
||||||
|
|
||||||
|
|
||||||
# Read data from the frame buffer given a offset and size.
|
|
||||||
# If data is empty then a transfer is scheduled after the RPC call finishes.
|
|
||||||
#
|
|
||||||
# data is a 4 byte size and 4 byte offset.
|
|
||||||
def jpeg_image_read(data):
|
|
||||||
if not len(data):
|
|
||||||
interface.schedule_callback(jpeg_image_read_cb)
|
|
||||||
return bytes()
|
|
||||||
else:
|
|
||||||
offset, size = struct.unpack("<II", data)
|
|
||||||
return memoryview(sensor.get_fb().bytearray())[offset : offset + size]
|
|
||||||
|
|
||||||
|
|
||||||
# Register call backs.
|
|
||||||
|
|
||||||
interface.register_callback(jpeg_image_snapshot)
|
|
||||||
interface.register_callback(jpeg_image_read)
|
|
||||||
|
|
||||||
# Once all call backs have been registered we can start
|
|
||||||
# processing remote events. interface.loop() does not return.
|
|
||||||
|
|
||||||
interface.loop()
|
|
@ -1,84 +0,0 @@
|
|||||||
# This work is licensed under the MIT license.
|
|
||||||
# Copyright (c) 2013-2023 OpenMV LLC. All rights reserved.
|
|
||||||
# https://github.com/openmv/openmv/blob/master/LICENSE
|
|
||||||
#
|
|
||||||
# Image Transfer - As The Remote Device
|
|
||||||
#
|
|
||||||
# This script is meant to talk to the "image_transfer_jpg_streaming_as_the_controller_device.py" on your computer.
|
|
||||||
#
|
|
||||||
# This script shows off how to transfer the frame buffer to your computer as a jpeg image.
|
|
||||||
|
|
||||||
import rpc
|
|
||||||
import sensor
|
|
||||||
|
|
||||||
sensor.reset()
|
|
||||||
sensor.set_pixformat(sensor.RGB565)
|
|
||||||
sensor.set_framesize(sensor.QVGA)
|
|
||||||
sensor.skip_frames(time=2000)
|
|
||||||
|
|
||||||
# The RPC library above is installed on your OpenMV Cam and provides multiple classes for
|
|
||||||
# allowing your OpenMV Cam to be controlled over USB or LAN/WLAN.
|
|
||||||
|
|
||||||
################################################################
|
|
||||||
# Choose the interface you wish to control your OpenMV Cam over.
|
|
||||||
################################################################
|
|
||||||
|
|
||||||
# Uncomment the below line to setup your OpenMV Cam for control over a USB VCP.
|
|
||||||
#
|
|
||||||
interface = rpc.rpc_usb_vcp_slave()
|
|
||||||
|
|
||||||
# Uncomment the below line to setup your OpenMV Cam for control over the lan.
|
|
||||||
#
|
|
||||||
# import network
|
|
||||||
# network_if = network.LAN()
|
|
||||||
# network_if.active(True)
|
|
||||||
# network_if.ifconfig('dhcp')
|
|
||||||
#
|
|
||||||
# interface = rpc.rpc_network_slave(network_if)
|
|
||||||
|
|
||||||
# Uncomment the below line to setup your OpenMV Cam for control over the wlan.
|
|
||||||
#
|
|
||||||
# import network
|
|
||||||
# network_if = network.WLAN(network.STA_IF)
|
|
||||||
# network_if.active(True)
|
|
||||||
# network_if.connect('your-ssid', 'your-password')
|
|
||||||
#
|
|
||||||
# interface = rpc.rpc_network_slave(network_if)
|
|
||||||
|
|
||||||
################################################################
|
|
||||||
# Call Backs
|
|
||||||
################################################################
|
|
||||||
|
|
||||||
|
|
||||||
# This is called repeatedly by interface.stream_writer().
|
|
||||||
def stream_generator_cb():
|
|
||||||
img = sensor.snapshot()
|
|
||||||
img.to_jpeg(quality=90)
|
|
||||||
return img.bytearray()
|
|
||||||
|
|
||||||
|
|
||||||
# Transmits a stream of bytes()'s generated by stream_generator_cb to the master device.
|
|
||||||
def jpeg_image_stream_cb():
|
|
||||||
interface.stream_writer(stream_generator_cb)
|
|
||||||
|
|
||||||
|
|
||||||
# When called sets the pixformat and framesize, and then schedules
|
|
||||||
# frame streaming to start after the RPC call finishes.
|
|
||||||
#
|
|
||||||
# data is a pixformat string and framesize string.
|
|
||||||
def jpeg_image_stream(data):
|
|
||||||
pixformat, framesize = bytes(data).decode().split(",")
|
|
||||||
sensor.set_pixformat(eval(pixformat))
|
|
||||||
sensor.set_framesize(eval(framesize))
|
|
||||||
interface.schedule_callback(jpeg_image_stream_cb)
|
|
||||||
return bytes()
|
|
||||||
|
|
||||||
|
|
||||||
# Register call backs.
|
|
||||||
|
|
||||||
interface.register_callback(jpeg_image_stream)
|
|
||||||
|
|
||||||
# Once all call backs have been registered we can start
|
|
||||||
# processing remote events. interface.loop() does not return.
|
|
||||||
|
|
||||||
interface.loop()
|
|
@ -12,7 +12,7 @@
|
|||||||
|
|
||||||
import network
|
import network
|
||||||
import rtsp
|
import rtsp
|
||||||
import sensor
|
import csi
|
||||||
import time
|
import time
|
||||||
|
|
||||||
# If you are using VLC on linux you may need to install the live555 library for RTSP support to
|
# If you are using VLC on linux you may need to install the live555 library for RTSP support to
|
||||||
@ -25,10 +25,10 @@ import time
|
|||||||
# "show more options" when you open the network stream in VLC. You can reduce this to like 10ms
|
# "show more options" when you open the network stream in VLC. You can reduce this to like 10ms
|
||||||
# to make the video real-time.
|
# to make the video real-time.
|
||||||
|
|
||||||
sensor.reset()
|
csi0 = csi.CSI()
|
||||||
|
csi0.reset()
|
||||||
sensor.set_pixformat(sensor.RGB565)
|
csi0.pixformat(csi.RGB565)
|
||||||
sensor.set_framesize(sensor.VGA)
|
csi0.framesize(csi.VGA)
|
||||||
|
|
||||||
# Setup Network Interface
|
# Setup Network Interface
|
||||||
|
|
||||||
@ -58,6 +58,7 @@ def setup_callback(pathname, session):
|
|||||||
|
|
||||||
|
|
||||||
def play_callback(pathname, session):
|
def play_callback(pathname, session):
|
||||||
|
global clock
|
||||||
clock.reset()
|
clock.reset()
|
||||||
clock.tick()
|
clock.tick()
|
||||||
print('Playing "%s" in session %d' % (pathname, session))
|
print('Playing "%s" in session %d' % (pathname, session))
|
||||||
@ -79,7 +80,9 @@ server.register_teardown_cb(teardown_callback)
|
|||||||
|
|
||||||
# Called each time a new frame is needed.
|
# Called each time a new frame is needed.
|
||||||
def image_callback(pathname, session):
|
def image_callback(pathname, session):
|
||||||
img = sensor.snapshot()
|
global csi0
|
||||||
|
global clock
|
||||||
|
img = csi0.snapshot(update=False)
|
||||||
# Markup image and/or do various things.
|
# Markup image and/or do various things.
|
||||||
print(clock.fps())
|
print(clock.fps())
|
||||||
clock.tick()
|
clock.tick()
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
|
|
||||||
import network
|
import network
|
||||||
import rtsp
|
import rtsp
|
||||||
import sensor
|
import csi
|
||||||
import time
|
import time
|
||||||
|
|
||||||
# If you are using VLC on linux you may need to install the live555 library for RTSP support to
|
# If you are using VLC on linux you may need to install the live555 library for RTSP support to
|
||||||
@ -25,10 +25,10 @@ import time
|
|||||||
# "show more options" when you open the network stream in VLC. You can reduce this to like 10ms
|
# "show more options" when you open the network stream in VLC. You can reduce this to like 10ms
|
||||||
# to make the video real-time.
|
# to make the video real-time.
|
||||||
|
|
||||||
sensor.reset()
|
csi0 = csi.CSI()
|
||||||
|
csi0.reset()
|
||||||
sensor.set_pixformat(sensor.RGB565)
|
csi0.pixformat(csi.RGB565)
|
||||||
sensor.set_framesize(sensor.VGA)
|
csi0.framesize(csi.VGA)
|
||||||
|
|
||||||
# Setup Network Interface
|
# Setup Network Interface
|
||||||
|
|
||||||
@ -61,6 +61,7 @@ def setup_callback(pathname, session):
|
|||||||
|
|
||||||
|
|
||||||
def play_callback(pathname, session):
|
def play_callback(pathname, session):
|
||||||
|
global clock
|
||||||
clock.reset()
|
clock.reset()
|
||||||
clock.tick()
|
clock.tick()
|
||||||
print('Playing "%s" in session %d' % (pathname, session))
|
print('Playing "%s" in session %d' % (pathname, session))
|
||||||
@ -82,7 +83,9 @@ server.register_teardown_cb(teardown_callback)
|
|||||||
|
|
||||||
# Called each time a new frame is needed.
|
# Called each time a new frame is needed.
|
||||||
def image_callback(pathname, session):
|
def image_callback(pathname, session):
|
||||||
img = sensor.snapshot()
|
global csi0
|
||||||
|
global clock
|
||||||
|
img = csi0.snapshot(update=False)
|
||||||
# Markup image and/or do various things.
|
# Markup image and/or do various things.
|
||||||
print(clock.fps())
|
print(clock.fps())
|
||||||
clock.tick()
|
clock.tick()
|
||||||
|
Loading…
Reference in New Issue
Block a user