-
Notifications
You must be signed in to change notification settings - Fork 2
Test Script for Vision Stack #41
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
Open
WithanagePerera
wants to merge
13
commits into
main
Choose a base branch
from
Praveen-VisionStackTests
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 12 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
4764e65
Bringing the path logic changes that Daniel made for the weights to a…
WithanagePerera c35b190
Added the original vision stack test from mil1.
WithanagePerera 1274a74
Got vision stack subscriber to a working point. Forgot that the front…
WithanagePerera f831bb8
Been following the stack trace and VisionStack can't process the data…
WithanagePerera c6b5878
Brought in cv_bridge to handle conversion of the Image type to an Ope…
WithanagePerera b8ab8dc
Brought in cv_bridge to handle conversion of the Image type to an Ope…
WithanagePerera db8effb
Experimenting with incorporating all layers. Running into an issue wi…
WithanagePerera 539c107
Figured out some of the constructor issues, wasn't sure about ObjectD…
WithanagePerera 7837268
Tested more of the layers and determined which can't be used at the m…
WithanagePerera 3df44d8
Replaced the layer numbers with the class names to make it more obvio…
WithanagePerera 31ae76c
Finally got the object detection layer working.
WithanagePerera a5c28d9
Uncommented some of the VisionStack code that was being problematic f…
WithanagePerera 568301c
Made some fixes based on Daniel's comments, also reverted the changes…
WithanagePerera File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| #!/usr/bin/env python3 | ||
| import rclpy | ||
| from rclpy.node import Node | ||
|
|
||
| from sensor_msgs.msg import Image | ||
|
|
||
| from cv_bridge import CvBridge | ||
|
|
||
| import sys | ||
| from pathlib import Path | ||
|
|
||
| sys.path.append(str(Path(__file__).parent.parent)) | ||
| vision_stack_base_path = str(Path(__file__).parent.parent) | ||
|
|
||
| from vision_stack import VisionStack, BinThresholdingLayer, CannyLayer, ColorMagnificationLayer, CustomLayer, GaussianLayer, GrayscaleLayer, HoughTransformLayer, MinMaxNormalizationLayer, ZScoreNormalizationLayer, RobustScalingLayer, ObjectDetectionLayer, ResizeLayer, RGBMagnificationLayer, SobelLayer, UnderWaterImageEnhancementLayer | ||
|
|
||
| bridge = CvBridge() | ||
|
|
||
| class vision_stack_test(Node): | ||
|
|
||
| def __init__(self): | ||
| super().__init__('Vision_Stack_Subscriber') | ||
|
|
||
| # Creating the subscriber to the front_cam image data | ||
| self.subscription = self.create_subscription( | ||
| Image, | ||
| '/front_cam/image_raw', # You can replace this with down_cam/image_raw if you want | ||
| self.listener_callback, | ||
| 10) | ||
|
|
||
| self.vs = VisionStack( | ||
| layers=[ | ||
| # Include as many layers in any combination as you need | ||
|
|
||
| # Stole the comments and layer initializations below from Daniel's README on the VisionStack repo | ||
|
|
||
| ObjectDetectionLayer(conf_thres=0.5, weights_file=f"{vision_stack_base_path}/vision_stack/weights/test.pt", pass_post_detection_img = False), # Access YOLO weights and make predictions on the image provided by the previous layer. Setting pass_post_processing_img will push the image with bounding boxes to the next layer. | ||
| GrayscaleLayer(), # Convert image to grayscale | ||
| BinThresholdingLayer(150,250), # Converts image to grayscale if image is not grayscale and extracts pixels with values between 150 and 250. | ||
| CannyLayer(50,100), # Simplified canny filter that uses cv2.Canny to pass a canny filter over an image with the low value (50) threshold for soft edge detection and the high value (100) for strong edges detection. | ||
| ColorMagnificationLayer((23,156,234)), # Highlights objects with this color (23,156,234) in an image. | ||
| GaussianLayer((11,11), 50), # Pass a gaussian filter of kernal size (11,11) (kernal size must be of odd numbered dimensions) with a sigma value of 50. | ||
| HoughTransformLayer(threshold=100, min_line_length=20, max_line_gap=10, pass_post_processing_img=True), # Pass a Hough Transform filter over an image to extract lines. Setting pass_post_processing_img will push the image with hough transform lines to the next layer. | ||
| MinMaxNormalizationLayer(), | ||
| ZScoreNormalizationLayer(), | ||
| ResizeLayer(960, 608), # Resize the image from the previous layer. | ||
| RGBMagnificationLayer('G'), # Magnifies the provided channel respectively (options are 'R', 'G', 'B') | ||
| UnderWaterImageEnhancementLayer(), # Uses a generative AI model to improve underwater images (good for murky waters). | ||
|
|
||
|
|
||
| # **********Layers with issues**************** | ||
| # RobustScalingLayer(), This layer produces a floating point encoding type which is not allowed by the publisher, so don't use this alyer | ||
| # SobelLayer(5), @ Fails for the same reason as RobustScalingLayer | ||
| ], | ||
| ) | ||
|
|
||
|
|
||
| # Runs vision stack on every callback | ||
| def listener_callback(self, msg): | ||
|
|
||
| cv_image = bridge.imgmsg_to_cv2(msg, desired_encoding='passthrough') | ||
| self.vs.run(cv_image, True) | ||
|
|
||
|
|
||
| def main(args=None): | ||
| rclpy.init(args=args) | ||
| front_cam_subscriber = vision_stack_test() | ||
| rclpy.spin(front_cam_subscriber) | ||
|
|
||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() |
Binary file not shown.
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
WithanagePerera marked this conversation as resolved.
Show resolved
Hide resolved
|
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,21 +1,21 @@ | ||
| import cv2 | ||
| from .Layer import PreprocessLayer | ||
|
|
||
| class ResizeLayer(PreprocessLayer): | ||
|
|
||
| def __init__(self, new_width, new_height) -> None: | ||
| """ | ||
| Resizes the image to be of new dimensions. | ||
|
|
||
| Parameters: | ||
| new_width: Image width will be resized to the new pixel width value. | ||
| new_height: Image height will be resized to the new pixel height value. | ||
| """ | ||
| super().__init__("resize") | ||
| self.new_width = new_width | ||
| self.new_height = new_height | ||
|
|
||
|
|
||
| def process(self, image): | ||
| resized_image = cv2.resize(image, (self.new_width, self.new_height)) | ||
| import cv2 | ||
| from .Layer import PreprocessLayer | ||
| class ResizeLayer(PreprocessLayer): | ||
| def __init__(self, new_width, new_height) -> None: | ||
| """ | ||
| Resizes the image to be of new dimensions. | ||
| Parameters: | ||
| new_width: Image width will be resized to the new pixel width value. | ||
| new_height: Image height will be resized to the new pixel height value. | ||
| """ | ||
| super().__init__("resize") | ||
| self.new_width = new_width | ||
| self.new_height = new_height | ||
| def process(self, image): | ||
| resized_image = cv2.resize(image, (self.new_width, self.new_height)) | ||
| return (resized_image, None) |
WithanagePerera marked this conversation as resolved.
Show resolved
Hide resolved
|
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
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.
Uh oh!
There was an error while loading. Please reload this page.