You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
1.4 KiB

3 months ago
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