using_perspective_broker
Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
| using_perspective_broker [2022/12/01 11:23] – [Page suivante: Twisted Perspective Broker et Kivy] serge | using_perspective_broker [2022/12/16 10:42] (Version actuelle) – [Using Perspective Broker] serge | ||
|---|---|---|---|
| Ligne 1: | Ligne 1: | ||
| ======Using Perspective Broker====== | ======Using Perspective Broker====== | ||
| + | {{ : | ||
| + | |||
| + | {{ ::labo.svg |}} | ||
| + | |||
| <WRAP center round info centeralign 60%> | <WRAP center round info centeralign 60%> | ||
| - | **Niveau Pro et intergalactique !** | + | **Niveau Pro et intergalactique !**\\ |
| + | Cette API: | ||
| + | * a entre 15 et 20 ans | ||
| + | * n'est que vaguement maintenu | ||
| + | * un exemple au moins ne marche pas | ||
| + | * le tranfert de datas simples marche | ||
| + | * le transfert d' | ||
| + | * les exemples ne respectent pas le PEP 8, c'est imbriqué au possible | ||
| </ | </ | ||
| <WRAP center round box 60% > | <WRAP center round box 60% > | ||
| * **{{tagpage> | * **{{tagpage> | ||
| - | * **[[perspective_broker|Page précédente]]** | + | * **[[perspective_broker|Page précédente]]** Python: Twisted Perspective Broker |
| + | * **[[managing_clients_of_perspectives|Page suivante]]** Managing Clients of Perspectives | ||
| + | * **[[https:// | ||
| </ | </ | ||
| Ligne 419: | Ligne 432: | ||
| + | def main(): | ||
| + | clt = Client() | ||
| + | factory = pb.PBClientFactory() | ||
| + | reactor.connectTCP(" | ||
| + | factory.getRootObject().addCallback(clt.on_start) | ||
| + | reactor.run() | ||
| + | |||
| + | main() | ||
| + | </ | ||
| + | |||
| + | =====Transfert d'une image ou d'un json===== | ||
| + | On peut transférer n' | ||
| + | <file python > | ||
| + | from time import sleep | ||
| + | from threading import Thread | ||
| + | |||
| + | import numpy as np | ||
| + | import cv2 | ||
| + | |||
| + | from twisted.internet import reactor | ||
| + | from twisted.spread import pb | ||
| + | |||
| + | class MyImage: | ||
| + | def __init__(self): | ||
| + | self.img = cv2.imread(' | ||
| + | img = cv2.resize(self.img, | ||
| + | encode_param=[int(cv2.IMWRITE_JPEG_QUALITY), | ||
| + | result, imgencode = cv2.imencode(' | ||
| + | data = np.array(imgencode) | ||
| + | print(data.shape) | ||
| + | self.stringData = data.tobytes() | ||
| + | |||
| + | |||
| + | class ObjetPrincipal(pb.Root): | ||
| + | def __init__(self): | ||
| + | self.mi = MyImage() | ||
| + | def remote_image(self): | ||
| + | print(" | ||
| + | return self.mi.stringData | ||
| + | |||
| + | # L' | ||
| + | root_obj = ObjetPrincipal() | ||
| + | |||
| + | reactor.listenTCP(8800, | ||
| + | reactor.run() | ||
| + | </ | ||
| + | |||
| + | <file python > | ||
| + | import numpy as np | ||
| + | import cv2 | ||
| + | import base64 | ||
| + | from twisted.internet import reactor | ||
| + | from twisted.spread import pb | ||
| + | |||
| + | |||
| + | class GetImage(pb.Copyable): | ||
| + | def get_image(self, | ||
| + | image = np.asarray(bytearray(stringData), | ||
| + | image = cv2.imdecode(image, | ||
| + | print(image.shape) | ||
| + | cv2.imshow(' | ||
| + | cv2.waitKey(0) | ||
| + | cv2.destroyAllWindows() | ||
| + | |||
| + | class RemoteGetImage(pb.RemoteCopy): | ||
| + | pass | ||
| + | |||
| + | pb.setUnjellyableForClass(GetImage, | ||
| + | |||
| + | class Client: | ||
| + | """ | ||
| + | def __init__(self): | ||
| + | """ | ||
| + | self.root_obj_client = None | ||
| + | self.gi = GetImage() | ||
| + | def on_start(self, | ||
| + | print(f" | ||
| + | self.root_obj_client = obj | ||
| + | # Transfert d'une image | ||
| + | self.root_obj_client.callRemote(" | ||
| + | | ||
| def main(): | def main(): | ||
| clt = Client() | clt = Client() | ||
using_perspective_broker.1669893809.txt.gz · Dernière modification : de serge
