Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update examples using new framework #126

Merged
merged 39 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
f7174a2
show RGP steam from new recorder service
OloFuchs Aug 8, 2023
a629b1a
template for loading camera stream
OloFuchs Aug 9, 2023
506391c
polish image viewer
edgarriba Aug 10, 2023
3220a0a
remove camera pipeline
edgarriba Aug 10, 2023
ce2266e
update file_converter
edgarriba Aug 10, 2023
5ea6f0a
update read camera calibration
edgarriba Aug 10, 2023
446806b
apply pre-commit
edgarriba Aug 10, 2023
9ad7062
add camera settings example
edgarriba Aug 11, 2023
383538f
update the camera client example
edgarriba Aug 11, 2023
4093510
add camera pointcloud example
edgarriba Sep 20, 2023
33ea4cd
cleanup working
edgarriba Sep 21, 2023
5da6997
add service / client example
edgarriba Sep 21, 2023
ce64663
update with experimental callback
edgarriba Sep 21, 2023
44c665e
add service propagation example
edgarriba Sep 21, 2023
8b757b5
remove added file
edgarriba Sep 21, 2023
a902046
add a service counter example
edgarriba Sep 22, 2023
502fe1b
working propagation
edgarriba Sep 25, 2023
37c3074
update camera example
edgarriba Sep 25, 2023
a6c7f50
more updates
edgarriba Sep 25, 2023
1861caf
apply pre-commit
edgarriba Sep 25, 2023
057cac8
decode calibration
edgarriba Sep 25, 2023
bb18538
decode calibration
edgarriba Sep 25, 2023
00e4a93
decode request reply
edgarriba Sep 25, 2023
042a7a4
fix await
edgarriba Sep 25, 2023
73a1e4a
add readme and requirements in calibration example
edgarriba Sep 26, 2023
f13463a
add readme and requirements.txt to camera settings example
edgarriba Sep 26, 2023
7987541
update pointcloud requirements file
edgarriba Sep 26, 2023
66b97a5
remove annotations reader and people detection
edgarriba Sep 26, 2023
f35708b
clean service callback code
edgarriba Sep 26, 2023
95301ab
Playback changes (#139)
Hackerman342 Sep 26, 2023
c772742
Factor out ImageDecoder until segmentation faults are resolved (#140)
Hackerman342 Sep 26, 2023
f015024
Update motor_states_stream example
Hackerman342 Sep 26, 2023
9a72167
Update motor_states readme
Hackerman342 Sep 26, 2023
7b0ea4e
Revive the vehicle_twist example (w/ virtual keyboard)
Hackerman342 Sep 26, 2023
fe5241b
Add vehicle twist readme
Hackerman342 Sep 26, 2023
1a92864
Fix ADK docs links
Hackerman342 Sep 26, 2023
27a6d82
Remove duplicated readme's (point to adk website)
Hackerman342 Sep 26, 2023
fbedc99
Add readme's w/ links for service / client examples
Hackerman342 Sep 26, 2023
fc1814c
Match new path in docs
Hackerman342 Sep 26, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions py/examples/camera_calibration/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Amiga Brain Reade Camera Calibration Example

URL: https://amiga.farm-ng.com/docs/examples/camera_calibration/
45 changes: 45 additions & 0 deletions py/examples/camera_calibration/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
"""Example of requesting the camera calibration from the camera service."""
# Copyright (c) farm-ng, inc.
#
# Licensed under the Amiga Development Kit License (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://github.com/farm-ng/amiga-dev-kit/blob/main/LICENSE
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import argparse
import asyncio
from pathlib import Path

from farm_ng.core.event_client import EventClient
from farm_ng.core.event_service_pb2 import EventServiceConfig
from farm_ng.core.events_file_reader import proto_from_json_file
from farm_ng.oak import oak_pb2
from google.protobuf.empty_pb2 import Empty


async def main(service_config_path: Path) -> None:
"""Request the camera calibration from the camera service.

Args:
service_config_path (Path): The path to the camera service config.
"""
# create a client to the camera service
config: EventServiceConfig = proto_from_json_file(service_config_path, EventServiceConfig())

# get the calibration message
calibration: oak_pb2.OakCalibration = await EventClient(config).request_reply("/calibration", Empty(), decode=True)
print(calibration)


if __name__ == "__main__":
parser = argparse.ArgumentParser(prog="amiga-camera-calibration")
parser.add_argument("--service-config", type=Path, required=True, help="The camera config.")
args = parser.parse_args()

asyncio.run(main(args.service_config))
46 changes: 0 additions & 46 deletions py/examples/camera_calibration/read_oak_calibration.py

This file was deleted.

1 change: 1 addition & 0 deletions py/examples/camera_calibration/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
farm-ng-amiga
6 changes: 6 additions & 0 deletions py/examples/camera_calibration/service_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "oak0",
"port": 50010,
"host": "localhost",
"log_level": "INFO"
}
2 changes: 1 addition & 1 deletion py/examples/camera_client/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Amiga Brain Camera example

URL: https://farm-ng.github.io/amiga-dev-kit/docs/examples/camera_client/
URL: https://amiga.farm-ng.com/docs/examples/camera_client/
76 changes: 35 additions & 41 deletions py/examples/camera_client/main.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""Example of a camera service client."""
# Copyright (c) farm-ng, inc.
#
# Licensed under the Amiga Development Kit License (the "License");
Expand All @@ -15,59 +16,52 @@

import argparse
import asyncio
from pathlib import Path

import cv2
import numpy as np
from farm_ng.oak import oak_pb2
from farm_ng.oak.camera_client import OakCameraClient
from farm_ng.service import service_pb2
from farm_ng.service.service_client import ClientConfig
from farm_ng.core.event_client import EventClient
from farm_ng.core.event_service_pb2 import EventServiceConfig
from farm_ng.core.events_file_reader import proto_from_json_file
from farm_ng.core.stamp import get_stamp_by_semantics_and_clock_type
from farm_ng.core.stamp import StampSemantics


async def main(address: str, port: int, stream_every_n: int) -> None:
# configure the camera client
config = ClientConfig(address=address, port=port)
client = OakCameraClient(config)
async def main(service_config_path: Path) -> None:
"""Run the camera service client.

# Get the streaming object from the service
response_stream = client.stream_frames(every_n=stream_every_n)
Args:
service_config_path (Path): The path to the camera service config.
"""
# create a client to the camera service
config: EventServiceConfig = proto_from_json_file(service_config_path, EventServiceConfig())

while True:
# check the service state
state = await client.get_state()
if state.value != service_pb2.ServiceState.RUNNING:
print("Camera is not streaming!")
continue
async for event, message in EventClient(config).subscribe(config.subscriptions[0], decode=True):
# Find the monotonic driver receive timestamp, or the first timestamp if not available.
stamp = (
get_stamp_by_semantics_and_clock_type(event, StampSemantics.DRIVER_RECEIVE, "monotonic")
or event.timestamps[0].stamp
)

response: oak_pb2.StreamFramesReply = await response_stream.read()
# print the timestamp and metadata
print(f"Timestamp: {stamp}\n")
print(f"Meta: {message.meta}")
print("###################\n")

if response:
# get the sync frame
frame: oak_pb2.OakSyncFrame = response.frame
print(f"Got frame: {frame.sequence_num}")
print(f"Device info: {frame.device_info}")
print(f"Timestamp: {frame.rgb.meta.timestamp}")
print("#################################\n")
# cast image data bytes to numpy and decode
image = cv2.imdecode(np.frombuffer(message.image_data, dtype="uint8"), cv2.IMREAD_UNCHANGED)
if event.uri.path == "/disparity":
image = cv2.applyColorMap(image * 3, cv2.COLORMAP_JET)

try:
# cast image data bytes to numpy and decode
# NOTE: explore frame.[rgb, disparity, left, right]
image = np.frombuffer(frame.rgb.image_data, dtype="uint8")
image = cv2.imdecode(image, cv2.IMREAD_UNCHANGED)

# visualize the image
cv2.namedWindow("image", cv2.WINDOW_NORMAL)
cv2.imshow("image", image)
cv2.waitKey(1)
except Exception as e:
print(e)
# visualize the image
cv2.namedWindow("image", cv2.WINDOW_NORMAL)
cv2.imshow("image", image)
cv2.waitKey(1)


if __name__ == "__main__":
parser = argparse.ArgumentParser(prog="amiga-camera-app")
parser.add_argument("--port", type=int, required=True, help="The camera port.")
parser.add_argument("--address", type=str, default="localhost", help="The camera address")
parser.add_argument("--stream-every-n", type=int, default=1, help="Streaming frequency")
parser = argparse.ArgumentParser(prog="amiga-camera-stream")
parser.add_argument("--service-config", type=Path, required=True, help="The camera config.")
args = parser.parse_args()

asyncio.run(main(args.address, args.port, args.stream_every_n))
asyncio.run(main(args.service_config))
15 changes: 15 additions & 0 deletions py/examples/camera_client/service_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "oak0",
"port": 50010,
"host": "localhost",
"log_level": "INFO",
"subscriptions": [
{
"uri": {
"path": "/rgb",
"query": "service_name=oak0"
},
"every_n": 1
}
]
}
13 changes: 0 additions & 13 deletions py/examples/camera_pipeline/__init__.py

This file was deleted.

123 changes: 0 additions & 123 deletions py/examples/camera_pipeline/main.py

This file was deleted.

3 changes: 3 additions & 0 deletions py/examples/camera_pointcloud/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Amiga Brain Camera example

URL: https://amiga.farm-ng.com/docs/examples/camera_pointcloud/
Loading
Loading