-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
85 additions
and
18 deletions.
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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import rospy | ||
from sensor_msgs.msg import Image | ||
from cv_bridge import CvBridge | ||
from pyrealsense2 import pyrealsense2 as rs | ||
from vision_msgs.msg import Detection2DArray | ||
from std_msgs.msg import Float32 | ||
import cv2 | ||
import numpy as np | ||
import os | ||
# Modeli yükleme | ||
import joblib | ||
|
||
|
||
|
||
class Estimator: | ||
def __init__(self): | ||
self.model = joblib.load("/home/cenk/regression_model2.joblib") #import pretrained model | ||
self.bridge = CvBridge() | ||
self.depth_scale = 0.001 | ||
rospy.init_node('regression_node') | ||
rospy.Subscriber('/yolov7/yolov7', Detection2DArray, self.image_callback) | ||
rospy.Subscriber('/camera/aligned_depth_to_color/image_raw', Image, self.depth_callback) | ||
self.pub = rospy.Publisher("/radius_estimator", Float32, queue_size=10) | ||
|
||
|
||
def image_callback(self,detection_array): | ||
# Bbox to numpy | ||
for detection in detection_array.detections: | ||
if detection.results[0].id == 32: # nesne ID'si 32 ise | ||
bbox = detection.bbox | ||
depth = (self.depth_image[int(bbox.center.y), int(bbox.center.x)]) * self.depth_scale | ||
features = np.array([depth, bbox.size_x, bbox.size_y]) | ||
features = features.reshape(1, -1) # add an extra dimension | ||
predict=self.model.predict(features) | ||
self.pub.publish(predict) #check | ||
print("Radius of ball predicted as %d cm" % predict) | ||
|
||
|
||
def depth_callback(self, depth_image): | ||
self.depth_image = self.bridge.imgmsg_to_cv2(depth_image, desired_encoding="passthrough") | ||
|
||
|
||
|
||
if __name__ == '__main__': | ||
estimator=Estimator() | ||
rospy.spin() |
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