viz: fix BGR/RGB channel swap in readCloud PLY, add PLY I/O and traje…#4119
Open
rtkartista wants to merge 1 commit into
Open
viz: fix BGR/RGB channel swap in readCloud PLY, add PLY I/O and traje…#4119rtkartista wants to merge 1 commit into
rtkartista wants to merge 1 commit into
Conversation
…ctory tests
- readCloud() returned colors in RGB order (PLY spec) instead of BGR
(OpenCV convention). Fix: swap channels 0 and 2 after sink->Write().
- writeCloud() was already correct (BGR->RGB on write).
- Add test_ply_io.cpp covering:
* ASCII PLY position roundtrip with 1e-4 tolerance
* Binary PLY position roundtrip (bit-exact)
* Binary PLY color roundtrip (catches the BGR/RGB bug)
* Large cloud (500k pts) binary perf smoke test
* Empty cloud no-crash
* Affine3d trajectory write/read roundtrip
* Affine3f trajectory write/read roundtrip (float precision)
* Non-zero start index for writeTrajectory/readTrajectory
* readTrajectory early stop on missing file
* Empty range returns empty result (also surfaces convertTo
depth==-1 bug when OutputArray is untyped and traj is empty)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix a long-standing BGR/RGB channel swap bug in
cv::viz::readCloud()for PLY files,and add a test suite for PLY cloud I/O and trajectory read/write roundtrips.
Bug fixed
readCloud()returns colors in RGB order (as stored in PLY spec) rather thanBGR (OpenCV convention).
writeCloud()correctly converts BGR→RGB on write,but the inverse conversion was missing on read. Every color channel 0 and 2
were silently swapped for all callers.
Fix: swap channels 0↔2 in-place after
sink->Write()invizcore.cpp.Tests added (
modules/viz/test/test_ply_io.cpp)PLY cloud I/O
Trajectory I/O
Affine3dwrite/read roundtrip — 1e-9 toleranceAffine3fwrite/read roundtrip — 1e-5 tolerancereadTrajectorystops cleanly on missing fileSecondary issue noted
readTrajectory()with an untypedstd::vectorOutputArray and zero resultscalls
Mat(traj).convertTo(_traj, _traj.depth())where_traj.depth()returns-1, causing undefined behavior. Guard withif (!traj.empty())or assign atyped empty array. Tracked separately.
Related
Contributes toward the SLAM module I/O test coverage noted in the
GSoC 2026 / 2026 wiki.
Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
Patch to opencv_extra has the same branch name.