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/11/30 20:52] – 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 429: | Ligne 442: | ||
</ | </ | ||
- | =====Page suivante: | + | =====Transfert d'une image ou d'un json===== |
- | * **[[twisted_perspective_broker_et_kivy|Twisted Perspective Broker et Kivy]]** | + | 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(): | ||
+ | clt = Client() | ||
+ | factory = pb.PBClientFactory() | ||
+ | reactor.connectTCP(" | ||
+ | factory.getRootObject().addCallback(clt.on_start) | ||
+ | reactor.run() | ||
+ | |||
+ | main() | ||
+ | </ | ||
+ | |||
+ | =====Page suivante: | ||
+ | * **[[pb_copyable_passing_complex_types|PB Copyable Passing Complex Types]]** | ||
{{tag> | {{tag> |
using_perspective_broker.1669841522.txt.gz · Dernière modification : 2022/11/30 20:52 de serge