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

[RSDK-4333] negative resolutions ignored in camera configs. #3811

Merged

Conversation

randhid
Copy link
Member

@randhid randhid commented Apr 16, 2024

Adds negative resolution validation checks to the camera drivers.

TODO:

  • Get tests passing.
  • Test with webcam and transform.

@randhid randhid requested review from seanavery and hexbabe April 16, 2024 22:58
@viambot viambot added the safe to test This pull request is marked safe to test from a trusted zone label Apr 16, 2024
go.mod Outdated
@@ -2,6 +2,8 @@ module go.viam.com/rdk

go 1.21

toolchain go1.21.7
Copy link
Member Author

Choose a reason for hiding this comment

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

revert before merge.

Copy link
Member

@hexbabe hexbabe Apr 17, 2024

Choose a reason for hiding this comment

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

Why was this needed?

Copy link
Member Author

Choose a reason for hiding this comment

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

go 1.21 and further uses toolchains to manage the dependencies, running make lint-go sometimes adds this I've noticed. Abe is trying to figure out how to handle adding a toolchain to the go.mod file. Until then I'll remove the toolchain when it's added.

Copy link
Member

Choose a reason for hiding this comment

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

go mod tidy adds the toolchain directive to any go.mod file with go 1.21 or higher (golang/go#62409)

I think we rely strictly on go 1.21 now (we're using new libraries) and so it's okay to add this; any downstream projects that can't handle the toolchain directive are already broken I suspect

would want to test locally on a mac to make sure it doesn't break

@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Apr 16, 2024
@randhid randhid requested a review from bhaney April 16, 2024 23:08
// Validate ensures all parts of the config are valid.
func (c fileSourceConfig) Validate(path string) ([]string, error) {
if c.CameraParameters.Width < 0 || c.CameraParameters.Height < 0 {
return nil, fmt.Errorf(" webcam width %v, and height %v must be non-zero and positive",
Copy link
Member

Choose a reason for hiding this comment

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

CameraParameters are from the intrinsics right? Should we mention intrinsics explicitly in the error message?

Also should we change webcam -> image_file cam or something

Copy link
Member Author

Choose a reason for hiding this comment

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

done, I'm struggling with the phrasing, which I copied from aligns. Do we like a specific phrasing more out of the possible error messages here?

Copy link
Member Author

@randhid randhid Apr 17, 2024

Choose a reason for hiding this comment

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

likely running make lint-go with my machine's go triggered the addition.

this was meant as a reply to go mod.

@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Apr 16, 2024
@@ -60,7 +60,6 @@ func init() {

// transformConfig specifies a stream and list of transforms to apply on images/pointclouds coming from a source camera.
type transformConfig struct {
resource.TriviallyValidateConfig
Copy link
Member Author

@randhid randhid Apr 16, 2024

Choose a reason for hiding this comment

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

this was weird. We had a double implementation of Validate in pipeline, so I don't know which one it could have called, if it was deterministic at all.

Copy link
Member

Choose a reason for hiding this comment

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

Golang moment

@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Apr 17, 2024
@randhid randhid requested a review from hexbabe April 17, 2024 13:46
Copy link
Member

@hexbabe hexbabe left a comment

Choose a reason for hiding this comment

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

LGTM! Sounds good to actually test with devices tho

@@ -60,7 +60,6 @@ func init() {

// transformConfig specifies a stream and list of transforms to apply on images/pointclouds coming from a source camera.
type transformConfig struct {
resource.TriviallyValidateConfig
Copy link
Member

Choose a reason for hiding this comment

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

Golang moment

Copy link
Member

@bhaney bhaney left a comment

Choose a reason for hiding this comment

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

cool cool, just a small suggestion

func (cfg *Config) Validate(path string) ([]string, error) {
if cfg.CameraParameters != nil {
if cfg.CameraParameters.Height < 0 || cfg.CameraParameters.Width < 0 {
return nil, fmt.Errorf(
Copy link
Member

Choose a reason for hiding this comment

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

[optional] errors.Errorf does the same thing as fmt.Errorf and you won't need to import a new package

Copy link
Member Author

Choose a reason for hiding this comment

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

That's part of "github.com/pkg/errors" not the standard "errors" go library (always gets me too). Not changing since that's a public archive.

We'll move away from the archived package in static.go eventually.

func (c fileSourceConfig) Validate(path string) ([]string, error) {
if c.CameraParameters != nil {
if c.CameraParameters.Width < 0 || c.CameraParameters.Height < 0 {
return nil, fmt.Errorf(
Copy link
Member

Choose a reason for hiding this comment

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

same here for fmt vs errors package

@viambot viambot removed the safe to test This pull request is marked safe to test from a trusted zone label Apr 17, 2024
@viambot viambot added the safe to test This pull request is marked safe to test from a trusted zone label Apr 17, 2024
@randhid
Copy link
Member Author

randhid commented Apr 18, 2024

Adds negative resolution validation checks to the camera drivers.

TODO:

* [x]  Get tests passing.

* [x]  Test with webcam and transform.
Screenshot 2024-04-18 at 18 35 48

@randhid randhid force-pushed the 20240401-RSDK-4333-negative-reoslution-ignored branch from 0036a2c to b8f691d Compare April 18, 2024 22:38
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Apr 18, 2024
@randhid randhid merged commit 6df8916 into viamrobotics:main Apr 19, 2024
17 checks passed
@randhid randhid deleted the 20240401-RSDK-4333-negative-reoslution-ignored branch April 19, 2024 17:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
safe to test This pull request is marked safe to test from a trusted zone
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants