Skip to content

lib: pixel: distort: add distortion aka defisheye aka dewarp #88840

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

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

josuah
Copy link
Collaborator

@josuah josuah commented Apr 21, 2025

Dependencies:

This performs a distortion operation over an input frame according to a grid, and produces a corrected output frame.

Using a low-res 200x200 pixel preview:
scrot_20250421_032353_537x806

Use-case is to correct the distortion introduced by a fish-eye lens, required to reach very large field of views (a distortion-free image at 180° FoV would have an infinite size).

Planned evolution:

  • Compute the distortion grid at run-time to allow scrolling through the image via PTZ controls, which does not introduce any runtime overhead, just computing a new distortion grid every time a new orientation is desired.
  • Skip the output framebuffer and load the output on-the-fly into the pipeline.

@josuah
Copy link
Collaborator Author

josuah commented Apr 21, 2025

A high-level illustration of how it is performed:

Re-computing the coordinates for every pixel is a lot of number crunching. Instead, this is pre-computed as a grid, and intermediate pixels are interpolated. That is, it works tile-per-tile performing a perspective transform to get the correct orientation, just like switching between two map projections:

world_map_with_major_cities_annotated

Each zone in red becomes an (i.e.) 20x20 pixel square after conversion.
Detailed comments in the source.

From NXP AN13075 for i.MXRT, anything with the "projective transform" can perform the required acceleration:
scrot_20250430_234323_1514x674

@kartben kartben requested a review from Copilot April 21, 2025 03:29
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces defisheye/dewarp distortion functionality into the pixel library. Key changes include new distortion routines in lib/pixel/distort.c and corresponding header updates, additional image processing functions in the pixel library, and updates to maintainers and metadata files.

Reviewed Changes

Copilot reviewed 55 out of 59 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
lib/pixel/stats.c Added statistics functions; note typo in copyright header.
lib/pixel/formats.c New pixel format conversion functions; note typo in header.
lib/pixel/bayer.c Bayer conversion functions update; note typo in header.
lib/pixel/distort.c Introduced distortion routines for defisheye/dewarp support.
MAINTAINERS.yml Added Pixel library group with maintainers and test metadata.
Other include files (pixel/*.h) Headers updated to support new features and conversions.
Files not reviewed (4)
  • lib/CMakeLists.txt: Language not supported
  • lib/Kconfig: Language not supported
  • lib/pixel/CMakeLists.txt: Language not supported
  • lib/pixel/Kconfig: Language not supported
Comments suppressed due to low confidence (2)

lib/pixel/formats.c:2

  • Typo in header comment: 'Copyir' should be corrected to 'Copyright'.
 * Copyir (c) 2025 tinyVision.ai Inc.

lib/pixel/bayer.c:2

  • Typo in header comment: 'Copyir' should be corrected to 'Copyright'.
 * Copyir (c) 2025 tinyVision.ai Inc.

josuah added 9 commits April 30, 2025 21:12
Introduce the YUV24 format following the Linux V4L2 naming and
fourcc definition.

Signed-off-by: Josuah Demangeon <me@josuah.net>
Introduce the RGB332 format following the Linux V4L2 naming and
fourcc definition.

Signed-off-by: Josuah Demangeon <me@josuah.net>
THe RGB565X (big-endian) did not have an entry for the function
video_byte_per_pixel(). Fix it by adding the missing entry.

Signed-off-by: Josuah Demangeon <me@josuah.net>
The "pixel" library aims facilitating the implementation of all image
processing tasks, such as pixel conversion, with a focus on low-resource
environments. The processing functions scale down to per-pixel "kernels"
to line-based conversion to full streams of several frames.

Signed-off-by: Josuah Demangeon <me@josuah.net>
The newly introduced lib/pixel features utilities that help composing
video pipelines together for the purpose of stream processing, as well
as debug utilities.

Signed-off-by: Josuah Demangeon <me@josuah.net>
The tests use data generated by the ffmpeg command line utilty in order
to avoid bias by having the same person implementing the tests and the
source code.

Signed-off-by: Josuah Demangeon <me@josuah.net>
Add "Pixel library" area, which covers the newly introduced lib/pixel
and associated tests and samples.

Signed-off-by: Josuah Demangeon <me@josuah.net>
Add a distort pixel library module givesto correct the perspective of a
fish-eye lens, used to get around 180deg of field of view.

Signed-off-by: Josuah Demangeon <me@josuah.net>
The sample uses OpenCV to calibrate a fish-eye lens according to a the
OpenCV tutorial, and generates C code usable by the lib/pixel/distort
code that will apply at runtime the distortion computed by OpenCV at
build-time.

Signed-off-by: Josuah Demangeon <me@josuah.net>
@josuah josuah force-pushed the pr-lib-pixel-fisheye branch from 5628f7f to e7f75ed Compare May 1, 2025 23:46
@josuah josuah added the In progress For PRs: is work in progress and should not be merged yet. For issues: Is being worked on label May 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Process area: Samples Samples In progress For PRs: is work in progress and should not be merged yet. For issues: Is being worked on
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants