-
Notifications
You must be signed in to change notification settings - Fork 9
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
Implemented vision_msgs #40
Open
Nalwa-Jayesh
wants to merge
3
commits into
develop
Choose a base branch
from
Nalwa-Jayesh/vision_msgs
base: develop
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 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 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 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 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 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 |
---|---|---|
|
@@ -7,8 +7,7 @@ | |
from rclpy.node import Node | ||
|
||
from sensor_msgs.msg import Image | ||
#from vision_msgs.msg import BoundingBox2D | ||
|
||
from vision_msgs.msg import Detection2D, Detection2DArray, ObjectHypothesisWithPose, Pose2D, Point2D, ObjectHypothesis | ||
from cv_bridge import CvBridge | ||
import cv2 | ||
|
||
|
@@ -30,6 +29,7 @@ def __init__(self): | |
('input_img_topic', ""), | ||
('output_bb_topic', ""), | ||
('output_img_topic', ""), | ||
('output_vision_topic', ""), | ||
('model_params.detector_type', ""), | ||
('model_params.model_dir_path', ""), | ||
('model_params.weight_file_name', ""), | ||
|
@@ -42,6 +42,7 @@ def __init__(self): | |
self.input_img_topic = self.get_parameter('input_img_topic').value | ||
self.output_bb_topic = self.get_parameter('output_bb_topic').value | ||
self.output_img_topic = self.get_parameter('output_img_topic').value | ||
self.output_vision_topic = self.get_parameter('output_vision_topic').value | ||
|
||
# model params | ||
self.detector_type = self.get_parameter('model_params.detector_type').value | ||
|
@@ -50,6 +51,9 @@ def __init__(self): | |
self.confidence_threshold = self.get_parameter('model_params.confidence_threshold').value | ||
self.show_fps = self.get_parameter('model_params.show_fps').value | ||
|
||
print(f"Model dir: {self.model_dir_path}") | ||
print(f"Model: {self.weight_file_name}") | ||
|
||
# raise an exception if specified detector was not found | ||
if self.detector_type not in self.available_detectors: | ||
raise ModuleNotFoundError(self.detector_type + " Detector specified in config was not found. " + | ||
|
@@ -62,6 +66,8 @@ def __init__(self): | |
self.bb_pub = None | ||
self.img_sub = self.create_subscription(Image, self.input_img_topic, self.detection_cb, 10) | ||
|
||
self.vision_msg_pub = self.create_publisher(Detection2DArray, self.output_vision_topic, 10) | ||
|
||
self.bridge = CvBridge() | ||
|
||
|
||
|
@@ -91,6 +97,9 @@ def detection_cb(self, img_msg): | |
cv_image = self.bridge.imgmsg_to_cv2(img_msg, "bgr8") | ||
|
||
predictions = self.detector.get_predictions(cv_image=cv_image) | ||
|
||
|
||
detection_arr = Detection2DArray() | ||
|
||
if predictions == None : | ||
print("Image input from topic : {} is empty".format(self.input_img_topic)) | ||
|
@@ -100,12 +109,39 @@ def detection_cb(self, img_msg): | |
right = left + width | ||
bottom = top + height | ||
|
||
class_id = str(prediction['class_id']) | ||
conf = float(prediction['confidence']) | ||
|
||
detection_msg = Detection2D() | ||
detection_msg.bbox.size_x = float(width) | ||
detection_msg.bbox.size_y = float(height) | ||
|
||
position_msg = Point2D() | ||
position_msg.x = float((left + right) / 2) | ||
position_msg.y = float((bottom + top) / 2) | ||
|
||
center_msg = Pose2D() | ||
center_msg.position = position_msg | ||
|
||
detection_msg.bbox.center = center_msg | ||
|
||
results_msg = ObjectHypothesisWithPose() | ||
hypothesis_msg = ObjectHypothesis() | ||
hypothesis_msg.class_id = class_id | ||
hypothesis_msg.score = conf | ||
|
||
results_msg.hypothesis = hypothesis_msg | ||
detection_msg.results.append(results_msg) | ||
|
||
detection_arr.detections.append(detection_msg) | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add comments to everyline to make code understandable to others. |
||
#Draw the bounding box | ||
cv_image = cv2.rectangle(cv_image,(left,top),(right, bottom),(0,255,0),1) | ||
|
||
output = self.bridge.cv2_to_imgmsg(cv_image, "bgr8") | ||
self.img_pub.publish(output) | ||
print(predictions) | ||
self.vision_msg_pub.publish(detection_arr) | ||
|
||
|
||
def main(): | ||
|
This file contains 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 |
---|---|---|
|
@@ -7,6 +7,8 @@ | |
<maintainer email="[email protected]">singh</maintainer> | ||
<license>TODO: License declaration</license> | ||
|
||
<depend>vision_msgs</depend> | ||
|
||
<test_depend>ament_copyright</test_depend> | ||
<test_depend>ament_flake8</test_depend> | ||
<test_depend>ament_pep257</test_depend> | ||
|
This file contains 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 |
---|---|---|
|
@@ -16,7 +16,7 @@ | |
(os.path.join('share', package_name, 'launch'), glob('launch/*.launch.py')), | ||
|
||
], | ||
install_requires=['setuptools'], | ||
install_requires=['setuptools', 'vision_msgs'], | ||
zip_safe=True, | ||
maintainer='singh', | ||
maintainer_email='[email protected]', | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should rename the topic to
object_detection/detection_info
as it might be more self explanatory.