Artem-Darius Weber 2 months ago
parent ac27c3ac7d
commit d0dd9759ce

@ -5,6 +5,7 @@
<sourceFolder url="file://$MODULE_DIR$/agentic" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/agentic/real-sense-object-detection-and-track-service" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/infrastructure" isTestSource="false" />
<excludeFolder url="file://$MODULE_DIR$/agentic/real-sense-object-detection-and-track-service/experiments" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />

@ -0,0 +1,41 @@
import requests
import base64
import cv2
import numpy as np
import json
class RealSenseObjectDetectionServer:
def __init__(self, server_url="http://rd1.k-lab.su/follow-vector"):
self.server_url = server_url
self.width = 640
self.height = 480
self.fps = 30
def encode_image_to_base64(self, image: np.ndarray) -> str:
_, buffer = cv2.imencode('.jpg', image)
return base64.b64encode(buffer).decode('utf-8')
def send_images(self, color_matrix, depth_matrix):
if color_matrix is None or depth_matrix is None:
print("Не удалось получить изображения. Проверьте подключение камеры.")
return None
color_base64 = self.encode_image_to_base64(color_matrix)
depth_base64 = self.encode_image_to_base64(depth_matrix)
payload = {
"rgb": color_base64,
"depth": depth_base64
}
with open("./tmp_request_data_log.json", "w") as json_file:
json.dump(payload, json_file, indent=4)
try:
response = requests.post(self.server_url, json=payload)
print(response.text)
response.raise_for_status() # Проверка на ошибки HTTP
return response.json()
except requests.exceptions.RequestException as e:
print(f"Ошибка при отправке данных: {e}")
return None

@ -11,10 +11,18 @@ CORS(app)
data_processor = DataProcessor()
def decode_image_from_base64(self, image_base64: str, color: bool = True) -> np.ndarray:
image_data = base64.b64decode(image_base64)
np_arr = np.frombuffer(image_data, np.uint8)
image = cv2.imdecode(np_arr, cv2.IMREAD_COLOR if color else cv2.IMREAD_GRAYSCALE)
return image
@app.route('/follow-vector', methods=['POST'])
def follow_vector():
try:
data = request.json
data['rgb'] = decode_image_from_base64(data['rgb'], color=True)
data['depth'] = decode_image_from_base64(data['depth'], color=False)
detections_info, annotated_image = data_processor.inline_detection(data)
if not detections_info and annotated_image is None:

@ -0,0 +1,19 @@
from Interfaces.RealSense import RealSenseController
from Server.ServerProvider import RealSenseObjectDetectionServer
def get_shot(controller):
depth_matrix = controller.acquisition.get_depth_image()
color_matrix = controller.acquisition.get_color_image()
print(f"RS Data: {depth_matrix.shape}")
return depth_matrix, color_matrix
if __name__ == "__main__":
controller = RealSenseController()
interface = RealSenseObjectDetectionServer()
depth_matrix, color_matrix = get_shot(controller)
response = interface.send_images(color_matrix, depth_matrix)
if response:
print("Ответ сервера:", response)

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save