Compare commits
5
Commits
s2
...
van-lier-patch-1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
eb31139059 | ||
|
|
9ac3822ed8 | ||
|
|
0abd2e8ade | ||
|
|
a64ecc83e8 | ||
|
|
b77a85d7f6 |
@@ -0,0 +1,145 @@
|
||||
#!/usr/bin/env python
|
||||
from __future__ import print_function
|
||||
|
||||
import roslib
|
||||
import sys
|
||||
import rospy
|
||||
import cv2
|
||||
import argparse
|
||||
from std_msgs.msg import String
|
||||
from sensor_msgs.msg import Image
|
||||
from cv_bridge import CvBridge, CvBridgeError
|
||||
from geometry_msgs.msg import Twist
|
||||
|
||||
|
||||
ARUCO_DICT = {
|
||||
"DICT_4X4_50": cv2.aruco.DICT_4X4_50,
|
||||
"DICT_4X4_100": cv2.aruco.DICT_4X4_100,
|
||||
"DICT_4X4_250": cv2.aruco.DICT_4X4_250,
|
||||
"DICT_4X4_1000": cv2.aruco.DICT_4X4_1000,
|
||||
"DICT_5X5_50": cv2.aruco.DICT_5X5_50,
|
||||
"DICT_5X5_100": cv2.aruco.DICT_5X5_100,
|
||||
"DICT_5X5_250": cv2.aruco.DICT_5X5_250,
|
||||
"DICT_5X5_1000": cv2.aruco.DICT_5X5_1000,
|
||||
"DICT_6X6_50": cv2.aruco.DICT_6X6_50,
|
||||
"DICT_6X6_100": cv2.aruco.DICT_6X6_100,
|
||||
"DICT_6X6_250": cv2.aruco.DICT_6X6_250,
|
||||
"DICT_6X6_1000": cv2.aruco.DICT_6X6_1000,
|
||||
"DICT_7X7_50": cv2.aruco.DICT_7X7_50,
|
||||
"DICT_7X7_100": cv2.aruco.DICT_7X7_100,
|
||||
"DICT_7X7_250": cv2.aruco.DICT_7X7_250,
|
||||
"DICT_7X7_1000": cv2.aruco.DICT_7X7_1000,
|
||||
"DICT_ARUCO_ORIGINAL": cv2.aruco.DICT_ARUCO_ORIGINAL,
|
||||
"DICT_APRILTAG_16h5": cv2.aruco.DICT_APRILTAG_16h5,
|
||||
"DICT_APRILTAG_25h9": cv2.aruco.DICT_APRILTAG_25h9,
|
||||
"DICT_APRILTAG_36h10": cv2.aruco.DICT_APRILTAG_36h10,
|
||||
"DICT_APRILTAG_36h11": cv2.aruco.DICT_APRILTAG_36h11,
|
||||
}
|
||||
|
||||
cascade = cv2.CascadeClassifier(r"/home/ros/catkin_ws/src/turtle_control/scripts/ges.xml")
|
||||
|
||||
|
||||
class image_converter:
|
||||
def __init__(self):
|
||||
self.bridge = CvBridge()
|
||||
self.image_sub = rospy.Subscriber(
|
||||
"/camera/color/image_raw", Image, self.callback
|
||||
)
|
||||
|
||||
ap = argparse.ArgumentParser()
|
||||
ap.add_argument(
|
||||
"-t",
|
||||
"--type",
|
||||
type=str,
|
||||
default="DICT_4X4_50",
|
||||
help="type of ArCUo tag to detect",
|
||||
)
|
||||
args = vars(ap.parse_args())
|
||||
|
||||
#self.arucoDict = cv2.aruco.getPredefinedDictionary(ARUCO_DICT[args["type"]])
|
||||
#self.arucoParams = cv2.aruco.DetectorParameters()
|
||||
#self.detector = cv2.aruco.ArucoDetector(self.arucoDict, self.arucoParams)
|
||||
|
||||
### For turtle controll
|
||||
self.pub = rospy.Publisher("/cmd_vel_mux/input/navi", Twist, queue_size=1)
|
||||
rospy.init_node("turtle_control", anonymous=True)
|
||||
self.rate = rospy.Rate(100) # update
|
||||
self.t = Twist()
|
||||
|
||||
### Markers haven been detected, now do something
|
||||
def markDetected(self, ids):
|
||||
ids = ids.flatten()
|
||||
if [1] in ids: # ID:1
|
||||
self.t.angular.z = 0.0
|
||||
self.t.linear.x = 0.3
|
||||
elif [2] in ids:
|
||||
self.t.angular.z = 0.0
|
||||
self.t.linear.x = -0.3
|
||||
elif [3] in ids:
|
||||
self.t.angular.z = 0.9
|
||||
self.t.linear.x = 0.0
|
||||
else:
|
||||
return
|
||||
self.pub.publish(self.t)
|
||||
|
||||
def callback(self, data):
|
||||
try:
|
||||
cv_image = self.bridge.imgmsg_to_cv2(data, "bgr8")
|
||||
except CvBridgeError as e:
|
||||
print(e)
|
||||
if cv_image is not 0:
|
||||
capture2 = cv2.cvtColor(cv_image, cv2.COLOR_BGR2GRAY)
|
||||
|
||||
gesucht = cascade.detectMultiScale(capture2)
|
||||
print(capture2.size)
|
||||
for (x,y,w,h) in gesucht:
|
||||
print(x)
|
||||
for (x,y,w,h) in gesucht:
|
||||
|
||||
if len(gesucht) > 0:
|
||||
if 300*1.1<x:
|
||||
self.t.angular.z=-0.9
|
||||
self.t.linear.x=0.2
|
||||
self.pub.publish(self.t)
|
||||
elif 300*0.9>x:
|
||||
self.t.angular.z=0.9
|
||||
self.t.linear.x=0.2
|
||||
self.pub.publish(self.t)
|
||||
else:
|
||||
self.t.linear.x=0.2
|
||||
for (x,y,w,h) in gesucht:
|
||||
cv2.rectangle(cv_image,(x,y),(x+w,y+h),color=(255,255,255), thickness=10)
|
||||
(rows, cols, channels) = cv_image.shape
|
||||
#if cols > 60 and rows > 60:
|
||||
# cv2.circle(cv_image, (50, 50), 10, 255)
|
||||
# pass
|
||||
#(corners, ids, rejected) = self.detector.detectMarkers(cv_image)
|
||||
|
||||
#idString = "IDs:" + str(ids)
|
||||
|
||||
#####
|
||||
# verify *at least* one ArUCo marker was detected
|
||||
# if len(corners) > 0:
|
||||
# self.markDetected(ids)
|
||||
# else:
|
||||
# self.t.angular.z = 0.8
|
||||
# self.t.linear.x = 0.2
|
||||
# self.pub.publish(self.t)
|
||||
#####
|
||||
|
||||
self.rate.sleep()
|
||||
cv2.imshow("Image window", cv_image)
|
||||
cv2.waitKey(3)
|
||||
|
||||
|
||||
def main(args):
|
||||
ic = image_converter()
|
||||
try:
|
||||
rospy.spin()
|
||||
except KeyboardInterrupt:
|
||||
print("Shutting down")
|
||||
cv2.destroyAllWindows()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main(sys.argv)
|
||||
+33314
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,9 @@
|
||||
Dies ist eine frühe version des Proramms mit gestenerkennung.
|
||||
|
||||
Zur benutzung muss die Adresse in Zeile 39 auf eine der xml Dateien im Ordner umgestellt werden.
|
||||
Entweder wird erkannt ob eine Faust oder eine offene Hand gezeigt wird.
|
||||
|
||||
Der Turtlebot wird dann auf die Hand zufahren.
|
||||
Dies implemtentation beinhaltet auch das frühere Fahrtsystem welches von Fabian van Lier entwickelt wurde,welches in ähnlicher Version auch in der Endversion benutzt wurde.
|
||||
|
||||
Man kann dies auch in der Node der finalen abgabe benutzen, dafür müsste man aber einige Codeänderungen vornehmen.
|
||||
+145
@@ -0,0 +1,145 @@
|
||||
#!/usr/bin/env python
|
||||
from __future__ import print_function
|
||||
|
||||
import roslib
|
||||
import sys
|
||||
import rospy
|
||||
import cv2
|
||||
import argparse
|
||||
from std_msgs.msg import String
|
||||
from sensor_msgs.msg import Image
|
||||
from cv_bridge import CvBridge, CvBridgeError
|
||||
from geometry_msgs.msg import Twist
|
||||
|
||||
|
||||
ARUCO_DICT = {
|
||||
"DICT_4X4_50": cv2.aruco.DICT_4X4_50,
|
||||
"DICT_4X4_100": cv2.aruco.DICT_4X4_100,
|
||||
"DICT_4X4_250": cv2.aruco.DICT_4X4_250,
|
||||
"DICT_4X4_1000": cv2.aruco.DICT_4X4_1000,
|
||||
"DICT_5X5_50": cv2.aruco.DICT_5X5_50,
|
||||
"DICT_5X5_100": cv2.aruco.DICT_5X5_100,
|
||||
"DICT_5X5_250": cv2.aruco.DICT_5X5_250,
|
||||
"DICT_5X5_1000": cv2.aruco.DICT_5X5_1000,
|
||||
"DICT_6X6_50": cv2.aruco.DICT_6X6_50,
|
||||
"DICT_6X6_100": cv2.aruco.DICT_6X6_100,
|
||||
"DICT_6X6_250": cv2.aruco.DICT_6X6_250,
|
||||
"DICT_6X6_1000": cv2.aruco.DICT_6X6_1000,
|
||||
"DICT_7X7_50": cv2.aruco.DICT_7X7_50,
|
||||
"DICT_7X7_100": cv2.aruco.DICT_7X7_100,
|
||||
"DICT_7X7_250": cv2.aruco.DICT_7X7_250,
|
||||
"DICT_7X7_1000": cv2.aruco.DICT_7X7_1000,
|
||||
"DICT_ARUCO_ORIGINAL": cv2.aruco.DICT_ARUCO_ORIGINAL,
|
||||
"DICT_APRILTAG_16h5": cv2.aruco.DICT_APRILTAG_16h5,
|
||||
"DICT_APRILTAG_25h9": cv2.aruco.DICT_APRILTAG_25h9,
|
||||
"DICT_APRILTAG_36h10": cv2.aruco.DICT_APRILTAG_36h10,
|
||||
"DICT_APRILTAG_36h11": cv2.aruco.DICT_APRILTAG_36h11,
|
||||
}
|
||||
|
||||
cascade = cv2.CascadeClassifier(r"/home/ros/catkin_ws/src/turtle_control/scripts/ges.xml")
|
||||
|
||||
|
||||
class image_converter:
|
||||
def __init__(self):
|
||||
self.bridge = CvBridge()
|
||||
self.image_sub = rospy.Subscriber(
|
||||
"/camera/color/image_raw", Image, self.callback
|
||||
)
|
||||
|
||||
ap = argparse.ArgumentParser()
|
||||
ap.add_argument(
|
||||
"-t",
|
||||
"--type",
|
||||
type=str,
|
||||
default="DICT_4X4_50",
|
||||
help="type of ArCUo tag to detect",
|
||||
)
|
||||
args = vars(ap.parse_args())
|
||||
|
||||
#self.arucoDict = cv2.aruco.getPredefinedDictionary(ARUCO_DICT[args["type"]])
|
||||
#self.arucoParams = cv2.aruco.DetectorParameters()
|
||||
#self.detector = cv2.aruco.ArucoDetector(self.arucoDict, self.arucoParams)
|
||||
|
||||
### For turtle controll
|
||||
self.pub = rospy.Publisher("/cmd_vel_mux/input/navi", Twist, queue_size=1)
|
||||
rospy.init_node("turtle_control", anonymous=True)
|
||||
self.rate = rospy.Rate(100) # update
|
||||
self.t = Twist()
|
||||
|
||||
### Markers haven been detected, now do something
|
||||
def markDetected(self, ids):
|
||||
ids = ids.flatten()
|
||||
if [1] in ids: # ID:1
|
||||
self.t.angular.z = 0.0
|
||||
self.t.linear.x = 0.3
|
||||
elif [2] in ids:
|
||||
self.t.angular.z = 0.0
|
||||
self.t.linear.x = -0.3
|
||||
elif [3] in ids:
|
||||
self.t.angular.z = 0.9
|
||||
self.t.linear.x = 0.0
|
||||
else:
|
||||
return
|
||||
self.pub.publish(self.t)
|
||||
|
||||
def callback(self, data):
|
||||
try:
|
||||
cv_image = self.bridge.imgmsg_to_cv2(data, "bgr8")
|
||||
except CvBridgeError as e:
|
||||
print(e)
|
||||
if cv_image is not 0:
|
||||
capture2 = cv2.cvtColor(cv_image, cv2.COLOR_BGR2GRAY)
|
||||
|
||||
gesucht = cascade.detectMultiScale(capture2)
|
||||
print(capture2.size)
|
||||
for (x,y,w,h) in gesucht:
|
||||
print(x)
|
||||
for (x,y,w,h) in gesucht:
|
||||
|
||||
if len(gesucht) > 0:
|
||||
if 300*1.1<x:
|
||||
self.t.angular.z=-0.9
|
||||
self.t.linear.x=0.2
|
||||
self.pub.publish(self.t)
|
||||
elif 300*0.9>x:
|
||||
self.t.angular.z=0.9
|
||||
self.t.linear.x=0.2
|
||||
self.pub.publish(self.t)
|
||||
else:
|
||||
self.t.linear.x=0.2
|
||||
for (x,y,w,h) in gesucht:
|
||||
cv2.rectangle(cv_image,(x,y),(x+w,y+h),color=(255,255,255), thickness=10)
|
||||
(rows, cols, channels) = cv_image.shape
|
||||
#if cols > 60 and rows > 60:
|
||||
# cv2.circle(cv_image, (50, 50), 10, 255)
|
||||
# pass
|
||||
#(corners, ids, rejected) = self.detector.detectMarkers(cv_image)
|
||||
|
||||
#idString = "IDs:" + str(ids)
|
||||
|
||||
#####
|
||||
# verify *at least* one ArUCo marker was detected
|
||||
# if len(corners) > 0:
|
||||
# self.markDetected(ids)
|
||||
# else:
|
||||
# self.t.angular.z = 0.8
|
||||
# self.t.linear.x = 0.2
|
||||
# self.pub.publish(self.t)
|
||||
#####
|
||||
|
||||
self.rate.sleep()
|
||||
cv2.imshow("Image window", cv_image)
|
||||
cv2.waitKey(3)
|
||||
|
||||
|
||||
def main(args):
|
||||
ic = image_converter()
|
||||
try:
|
||||
rospy.spin()
|
||||
except KeyboardInterrupt:
|
||||
print("Shutting down")
|
||||
cv2.destroyAllWindows()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main(sys.argv)
|
||||
Reference in New Issue
Block a user