Develop #5
+15
-22
@@ -1,11 +1,4 @@
|
||||
class ColorDetect():
|
||||
def __init__(self):
|
||||
self.color = None
|
||||
|
||||
def getColor(self):
|
||||
return self.color
|
||||
|
||||
def detect_color_callback(self, data, print_type='str'):
|
||||
def color_detection(data, print_type='str'):
|
||||
'''определение цвета'''
|
||||
|
||||
frame = bridge.imgmsg_to_cv2(data, 'bgr8')
|
||||
@@ -25,7 +18,7 @@ class ColorDetect():
|
||||
|
||||
mean_bgr = cv2.mean(cropped_frame)[:3]
|
||||
mean_rgb = (int(mean_bgr[2]), int(mean_bgr[1]), int(mean_bgr[0]))
|
||||
self.color = str(mean_rgb)
|
||||
color = str(mean_rgb)
|
||||
|
||||
|
||||
elif print_type == 'str':
|
||||
@@ -35,20 +28,20 @@ class ColorDetect():
|
||||
b, g, r = int(mean_bgr[0]), int(mean_bgr[1]), int(mean_bgr[2])
|
||||
|
||||
|
||||
if b > g and b > r and b > 100:
|
||||
self.color = 'blue'
|
||||
elif g > b and g > r and g > 100:
|
||||
self.color = 'green'
|
||||
elif r > b and r > g and r > 100:
|
||||
self.color = 'red'
|
||||
if b > g + 20 and b > r + 20 and b > 100 + 20:
|
||||
color = 'blue'
|
||||
elif g > b + 20 and g > r + 20 and g > 100:
|
||||
color = 'green'
|
||||
elif r > b + 20 and r > g + 20 and r > 100:
|
||||
color = 'red'
|
||||
elif r > 150 and g > 150 and g > 150:
|
||||
color= 'white'
|
||||
else:
|
||||
self.color = None
|
||||
color = None
|
||||
|
||||
#в MAIN для вызова функции должно быть:
|
||||
# cd = ColorDetect()
|
||||
#color_sub = rospy.Subscriber('main_camera/image_raw', Image,
|
||||
#lambda img: cd.detect_color_callback(img, print_type='rgb'),
|
||||
#color_sub = rospy.Subscriber('main_camera/image_raw', Image,
|
||||
#lambda img: color_detection(img, print_type='rgb'),
|
||||
#queue_size=1)
|
||||
# print(cd.getColor())
|
||||
#rospy.sleep(2)
|
||||
#color_sub.unregister()
|
||||
#rospy.sleep(2)
|
||||
#color_sub.unregister()
|
||||
|
||||
@@ -17,6 +17,8 @@ get_telemetry = rospy.ServiceProxy('get_telemetry', srv.GetTelemetry) #сеов
|
||||
navigate = rospy.ServiceProxy('navigate', srv.Navigate) #сервис для полета по указаным координатам
|
||||
land = rospy.ServiceProxy('land', Trigger) #сервис для посадки
|
||||
|
||||
rospy.init_node('flight')
|
||||
bridge = CvBridge()
|
||||
|
||||
def navigate_wait(x=0, y=0, z=1, speed=0.5, frame_id='aruco_map', auto_arm=False, tolerance=0.2,sleep=2):
|
||||
"""
|
||||
|
||||
+3
-12
@@ -1,16 +1,7 @@
|
||||
class QrDetect():
|
||||
def __init__(self):
|
||||
self.qr_data = ''
|
||||
|
||||
def getQrData(self):
|
||||
return self.qr_data
|
||||
|
||||
def qr_detection(self,data):
|
||||
'''сканирование qr кода'''
|
||||
if self.qr_data!= '':
|
||||
return
|
||||
def qr_detection(data):
|
||||
cv_image = bridge.imgmsg_to_cv2(data, 'bgr8')
|
||||
barcodes = pyzbar.decode(cv_image)
|
||||
|
||||
if barcodes:
|
||||
self.qr_data = barcodes[0].data.decode('utf-8')
|
||||
qr_data = barcodes[0].data.decode('utf-8')
|
||||
return qr_data
|
||||
+11
-14
@@ -11,14 +11,12 @@ const clickCount = ref(1); // Счетчик нажатий
|
||||
const listOfTrips = ref([]);
|
||||
const isModalVisible = ref(false);
|
||||
let finallyText = "";
|
||||
const qr_sub_text = [
|
||||
"\tqd = QrDetect()\n",
|
||||
"\tqr_sub = rospy.Subscriber('main_camera/image_raw',Image, qd.qr_detection,queue_size=1)\n",
|
||||
"\trospy.sleep(2)\n",
|
||||
"\tqr_sub.unregister()\n"
|
||||
];
|
||||
let is_qr_used = 0;
|
||||
let head = "";
|
||||
const qr_sub_text = `
|
||||
\tqr_sub = rospy.Subscriber('main_camera/image_raw',Image, qr_detection,queue_size=1)\n
|
||||
\trospy.sleep(2)\n
|
||||
\tqr_sub.unregister()\n
|
||||
`
|
||||
let is_qr__head_used = 0;
|
||||
|
||||
onMounted(() => {
|
||||
for (let i = 0; i < 100; i++) {
|
||||
@@ -58,8 +56,8 @@ function saveResult() {
|
||||
for (const item of listOfTrips.value) {
|
||||
navigate_waites += `\tnavigate_wait(${item.x}, ${item.y})\n`;
|
||||
if (item.x===1 && item.y === 1) {
|
||||
navigate_waites += qr_sub_text.join('')
|
||||
is_qr_used=1
|
||||
navigate_waites += qr_sub_text
|
||||
is_qr__head_used=1
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,9 +67,9 @@ function saveResult() {
|
||||
finallyText = textOfCode.replace("<<navigate_wait>>", navigate_waites);
|
||||
});
|
||||
isModalVisible.value = true;
|
||||
if (is_qr_used === 1) {
|
||||
if (is_qr__head_used === 1) {
|
||||
Qr_head()
|
||||
is_qr_used +=1
|
||||
is_qr__head_used +=1
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,8 +77,7 @@ function Qr_head() {
|
||||
fetch("/shablons/qr.txt")
|
||||
.then((response) => response.text())
|
||||
.then((textOfCode) => {
|
||||
head = textOfCode;
|
||||
finallyText = finallyText.replace("<<qr_function>>", head);
|
||||
finallyText = finallyText.replace("<<qr_function>>", textOfCode);
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user