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

add a __main__ self-test configured with a json file #1134

Merged
merged 3 commits into from
Jun 27, 2023

Conversation

Ezward
Copy link
Contributor

@Ezward Ezward commented Jun 25, 2023

This should be merged after PR #1133

add a __main__ self-test configured with a json file

I created this because I found bugs in the image transformations when I tried to create a chain of them. I needed a test where I could try many combinations easily, so I created a function to create a image transform pipeline from a json file and created the __main__ to use it.

You provide a json file that specifies a transformation pipeline and configures either an single image to be loaded or a camera to be used. The image transformation pipeline is constructed and applied the configured image source and shown in an opencv window.

This json specifies a pipeline that applies canny edge detection to the image.

[
    ["RGB2GRAY"],
    ["BLUR", {}],
    ["CANNY", {}],
    ["CROP", {"left": 0, "top": 45, "right": 0, "bottom": 0}],
    ["GRAY2RGB"]
]

Here the "BLUR" and "CANNY" transforms are using default parameters, so the argument object is empty. The "CROP" transform is supplied with a argument object that specifies all named parameters and their values. The color conversion transforms "RGB2GRAY" and "GRAY2RGB" do not have arguments so no argument object is supplied.

If it was in a json file named canny_pipeline.json in pi home folder the usage would be:

cd donkeycar/parts
python image_transformations.py --width=640 --height=480 --json=/Home/pi/canny_pipeline.json
  • the main self-test can load an image from a file or use the video stream from a camera
  • It takes the path to a json file that specifies a list of image transforms, there order and their arguments
  • functions have been added to load and parse the json file and use it to construct the transform pipeline.
  • The transform pipeline is implemented with a run() method that applies the transforms in order.
  • Comments in the code document the json file format.

@Ezward Ezward requested a review from DocGarbanzo June 25, 2023 04:33
@Ezward Ezward self-assigned this Jun 25, 2023
Copy link
Contributor

@DocGarbanzo DocGarbanzo left a comment

Choose a reason for hiding this comment

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

Looks fine to me, ca you bump our dev version up by one?




def imgTransformListFromJson(transforms_config):
Copy link
Contributor

Choose a reason for hiding this comment

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

Small comment. Camelcase should preferably be replaced by underscore concatenation for python functions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.




def loadImgTransformJson(filepath):
Copy link
Contributor

Choose a reason for hiding this comment

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

As above

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

Base automatically changed from fix-cv-colorspace-transforms to main June 26, 2023 19:47
- the __main__ self-test can load an image from a file
  or use the video stream from a camera
- It takes the path to a json file that specifies a
  list of image transforms, there order and their arguments
- functions have been added to load and parse the json file
  and use it to construct the transform pipeline.
- The transform pipeline is implemented with a run() method
  that applies the transforms in order.
- Comments in the code document the json file format.
@Ezward Ezward force-pushed the add-image-transform-self-test branch from 810f92f to 5d2a841 Compare June 26, 2023 19:52
- no other functional changes, just renaming
@Ezward Ezward merged commit 1398eec into main Jun 27, 2023
@Ezward Ezward deleted the add-image-transform-self-test branch June 27, 2023 07:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants