Hello,
maybe I am just searching wrong... but I can't find any example how to send picture data to protoserver over LAN. I would like to do it with python. Is there any documentation for this please? (or example)
many thanks
Hello,
maybe I am just searching wrong... but I can't find any example how to send picture data to protoserver over LAN. I would like to do it with python. Is there any documentation for this please? (or example)
many thanks
Greetings
These examples are available
Java: https://hyperion-project.org/w…uffer-Java-client-example
C# https://github.com/hanselb/HyperionScreenCap
An finally the kodi addon as python. https://github.com/hyperion-project/hyperion.kodi
Protobuf python, to get a better idea what proto is.
https://developers.google.com/…ffers/docs/pythontutorial
You want to create a python capture app?
Hi Brindosch, thank you for the links. I am familiar with python a bit, so I try out to sort it out this way. I will check links and maybe I get an idea how it works in other languages. Yes, I am experimenting with capturing, now I test framerates.
Brindosch, please, I am trying to check basic functionality with white.png image with this code, but I am getting "Size of image data does not match with the width and height" error. I tried simple file read as well as read via PIL.
(
I found something like imageData.size() != width*height*3 in cpp file, but even when I save plain white bmp picture 720x576px, it has size of 1 244 214 bytes, and if I understand it good , width*height*3 wants 1 244 160 bytes?
)
Any idea why, please?
'''
Kodi inspired.
'''
import socket
import struct
#protobuf message includes
from message_pb2 import HyperionRequest
from message_pb2 import HyperionReply
from message_pb2 import ColorRequest
from message_pb2 import ImageRequest
from message_pb2 import ClearRequest
import PIL.Image
class Hyperion(object):
'''Hyperion connection class
A Hyperion object will connect to the Hyperion server and provide
easy to use functions to send requests
Note that the function will block until a reply has been received
from the Hyperion server (or the call has timed out)
'''
def __init__(self):
'''Constructor
- server : server address of Hyperion
- port : port number of Hyperion
'''
# create a new socket
self.__socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.__socket.settimeout(2)
server = "192.168.1.119"
port = 19445
# Connect socket to the provided server
self.__socket.connect((server, port))
print 'b'
self.sendImage()
print 'bc'
def __del__(self):
'''Destructor
'''
# close the socket
self.__socket.close()
#def sendImage(self, width, height, data, priority, duration = -1):
def sendImage(self):
'''Send an image to Hyperion
- width : width of the image
- height : height of the image
- data : image data (byte string containing 0xRRGGBB pixel values)
- priority : the priority channel to use
- duration : duration the leds should be set
'''
priority = 100
duration = 5
width = 180
height = 144
# f = open('white.png', 'r+')
# data = f.read()
# f.close()
data = PIL.Image.open("white.png")
#read data
#data =
# create the request
request = HyperionRequest()
request.command = HyperionRequest.IMAGE
imageRequest = request.Extensions[ImageRequest.imageRequest]
imageRequest.imagewidth = width
imageRequest.imageheight = height
imageRequest.imagedata = str(data)
imageRequest.priority = priority
imageRequest.duration = duration
print imageRequest.imagedata
# send the message
self.__sendMessage(request)
def __sendMessage(self, message):
'''Send the given proto message to Hyperion. A RuntimeError will
be raised if the reply contains an error
- message : proto request to send
'''
#print "send message to Hyperion (%d):\n%s" % (len(message.SerializeToString()), message)
# send message to Hyperion"
binaryRequest = message.SerializeToString()
binarySize = struct.pack(">I", len(binaryRequest))
self.__socket.sendall(binarySize)
self.__socket.sendall(binaryRequest);
# receive a reply from Hyperion
size = struct.unpack(">I", self.__socket.recv(4))[0]
reply = HyperionReply()
reply.ParseFromString(self.__socket.recv(size))
print'a'
# check the reply
#print "Reply received:\n%s" % (reply)
if not reply.success:
raise RuntimeError("Hyperion server error: " + reply.error)
hyperiongo = Hyperion()
Alles anzeigen
Some header junk at the start of the "file" ? Does PIL have a raw image data method ? Maybe your data has some PIL object info in it
@penfold42 , thank you pointing me the right direction! I made this and now it works:
Excellent !
It would be great to get your work captured as some examples on the wiki
Excellent !
It would be great to get your work captured as some examples on the wiki
Sure! I am just at the beginning but let you know then.
Sie haben noch kein Benutzerkonto auf unserer Seite? Registrieren Sie sich kostenlos und nehmen Sie an unserer Community teil!