Skip to content

Commit

Permalink
Improvements from review
Browse files Browse the repository at this point in the history
  • Loading branch information
khodand committed Mar 12, 2021
1 parent a0eade8 commit b7fdd29
Showing 1 changed file with 36 additions and 6 deletions.
42 changes: 36 additions & 6 deletions lobeClient/desktopClient.py
@@ -1,6 +1,18 @@
"""
Read https://github.com/lobe/lobe-python#lobe-python-api for help and required dependencies
"""
#!/usr/bin/env python3
""" Copyright 2021 Andrei Khodko, CyberTech Labs Ltd.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. """

# IP робота или студии. Для студии обычно использовать SERVER_IP = '127.0.0.1'
SERVER_IP = '127.0.0.1'
# Борт номер для этого лобе сервера. Выберите не занятый роботами.
Expand All @@ -9,13 +21,27 @@
SERVER_PORT = 8889

# Путь к директории обученной модели Lobe. Работает с TFLite
MODEL_PATH = 'path/to/exported/model'
# По умолчанию ищет в директории этого скрипта.
# Модель это файлы signature.json и например saved_model.tflite. Если хотите прямой указать путь к модели то,
# указывайте путь к папке содержайщей эти файлы, например MODEL_PATH = 'path/to/exported/model'
import sys
MODEL_PATH = sys.path[0]
# Установить True если хотим использовать изображение с камеры ТРИК (нужно запустить mjpg-encoder)
# Установить False если хотим использовать изображение с вебкамеры компьютера
GET_IMAGES_FROM_ROBOT = False
# Номер камеры в ОС Windows. Разные значения активирует разные подключенные камеры (0, 1, 2...)
CAMERA_NUMBER = 0


"""
Простой скрипт для робота или студии.
while True:
predict = mailbox.receive(True)
print(predict)
script.wait(1000)
"""


import subprocess
import sys
import asyncio
Expand Down Expand Up @@ -90,7 +116,7 @@ async def send_prediction(sock):

async def read_data(sock, my_loop):
data = ""
while data != "9:data:quit":
while data.find("9:data:quit") == -1:
await asyncio.sleep(0.2)
try:
data = (await my_loop.sock_recv(sock, 255)).decode("utf-8")
Expand All @@ -105,7 +131,7 @@ async def read_data(sock, my_loop):
CAMERA.release()


if __name__ == '__main__':
def main():
loop = asyncio.get_event_loop()
server = socket.socket()
try:
Expand All @@ -125,3 +151,7 @@ async def read_data(sock, my_loop):
finally:
server.close()
loop.stop()


if __name__ == '__main__':
main()

0 comments on commit b7fdd29

Please sign in to comment.