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

AP_camera: Camera tracking example scripts (WIP) #27903

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

khanasif786
Copy link
Contributor

@khanasif786 khanasif786 commented Aug 22, 2024

This PR realtes to #27773
There are currently two scripts more scripts may be added.

  1. send_camera_information send the camera information from companion computer to the FC running Ardupilot over network.
  2. the tracking.py scripts runs in parallel thread detecting humans and then sending PITCH YAW commands to FC. You need to specify the gstreamer pipeline command in string format to the example script. By default the example script uses the udp stream. ehich the gstreamer plugin from gazebo uses

@khanasif786 khanasif786 force-pushed the mav_cmd_camera_example_scripts branch from c9c3a19 to 7de2491 Compare August 22, 2024 18:01
@timtuxworth
Copy link
Contributor

Could you use an RTSP stream direct without needing to use gstreamer?

@khanasif786
Copy link
Contributor Author

@timtuxworth , yeah there are workarounds, just need to catch the rtsp stream and give it to cv2 capture

float('nan'), # focal_length
float('nan'), # sensor_size_h
float('nan'), # sensor_size_v
640, # resolution_h
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ideally we should pull these resolutions from the rtsp stream that we're using. Not a blocker though

def __init__(self, video_source=None):
# Set default video source if not provided
if video_source is None:
video_source = 'udpsrc port=5600 ! application/x-rtp,encoding-name=H264,payload=96 ! rtph264depay ! h264parse ! queue ! avdec_h264 ! videoconvert ! appsink'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought that with the siyi cameras, only H265 worked. I don't think H264 streaming works with them

Copy link
Contributor

@peterbarker peterbarker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review data integrity

640, # resolution_h
480, # resolution_v
0, # lens_id
4095, # flags
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SHould use enumeration entries rather than just a number. Maybe create a flags local variable

libraries/AP_Camera/examples/tracking.py Show resolved Hide resolved
libraries/AP_Camera/examples/tracking.py Outdated Show resolved Hide resolved
libraries/AP_Camera/examples/tracking.py Outdated Show resolved Hide resolved
@khanasif786 khanasif786 force-pushed the mav_cmd_camera_example_scripts branch 2 times, most recently from cfc9193 to d70f55d Compare August 30, 2024 06:06
libraries/AP_Camera/examples/send_camera_information.py Outdated Show resolved Hide resolved


def main():
gimbal_control = GimbalControl('127.0.0.1:14560')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some argparse arguments and documentation would be nice

self.out = self.initialize_video_writer()
self.frame = None

self.tracker = cv2.legacy.TrackerCSRT_create() # Change to legacy namespace
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you think it makes sense to add a KCF option here aswell via constructor?

this would allow people more easy to switch for a faster variant on ressource restricted platforms

Copy link
Contributor Author

@khanasif786 khanasif786 Sep 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@julled Thanks, i was thinking similar. 😃

@khanasif786 khanasif786 changed the title AP_camera: Camera tracking example scripts AP_camera: Camera tracking example scripts (WIP) Sep 11, 2024
gstreamer1.0-plugins-ugly gstreamer1.0-libav gstreamer1.0-tools
```

3. default opencv from pip should be uninstalled and again built with gstreamer support (If already did this go to next step)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should avoid requiring a custom build of opencv to include gstreamer support, and instead use standard packages. We can add a class to convert from the gstreamer frames to ones compatible with opencv, such as the example here: https://www.ardusub.com/developers/opencv.html

diff_x = (centre_x_copy - (640 / 2)) / 2
diff_y = -(centre_y_copy - (480 / 2)) / 2

self.send_gimbal_manager_pitch_yaw_angles(float("NaN"), float("NaN"), math.radians(diff_y), math.radians(diff_x))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we're going to need PI(D) controllers to set gains on the conversion from (diff_x, diff_y) to (pitch_rate_rads, yaw_rate_rads). From initial testing with a SIYI A8, P gains of around 0.1 are a reasonable start. Unadjusted, the gimbal overshoots and tracking is lost immediately.

Comment on lines +95 to +98
norm_x = msg.param1
norm_y = msg.param2
norm_w = msg.param3
norm_h = msg.param4
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://mavlink.io/en/messages/common.html#MAV_CMD_CAMERA_TRACK_RECTANGLE

  • param3 is bottom right corner x not width
  • param4 is bottom right corner y not height

@srmainwaring srmainwaring added the GSoC Google Summer of Code label Oct 7, 2024
@srmainwaring
Copy link
Contributor

srmainwaring commented Oct 7, 2024

@khanasif786 - I've rebased this PR on master here: https://github.com/srmainwaring/ardupilot/tree/mav_cmd_camera_example_scripts.

ReadMe.md in this PR must be renamed to README.md before rebasing. This has to be done in a few steps to avoid issues on case insensitive filesystems such as the one used by macOS. The steps are ReadMe.md -> ReadMe_.md -> squash into 2d75399 -> ReadMe_.md -> README.md -> squash, then rebase on master. I tried to force push my branch but don't have permission.

@rmackay9
Copy link
Contributor

rmackay9 commented Oct 23, 2024

A couple of small things:

  1. we should squash the commits
  2. let's change the README file name to match conventional case
  3. resolve merge conflicts at some point

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GSoC Google Summer of Code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants