Jump to content

Metropolis Microservices/RidgeRun Services/PTZ: Difference between revisions

no edit summary
No edit summary
No edit summary
Line 138: Line 138:
#Returns the stream transformed using the same protocol, RTSP, as the output.  
#Returns the stream transformed using the same protocol, RTSP, as the output.  


We can use the modules available in here**, called rrms_utils, to create a client that "talks" to the server created into the ptz microservices, once it is installed and running.  
We can use the module available in here**, called rrms_utils, to talk to the PTZ Microservice.  
 
{{Review|Add link to explanation of how to install rrms-utils?|mortigoza}}


These are the imports, and commands needed to do it: (Below we explain the purpose of each one)
These are the imports, and commands needed to do it: (Below we explain the purpose of each one)
Line 179: Line 181:
     print("Something went wrong")
     print("Something went wrong")


#Receive the PTZ output - RTSP Stream:
vlc rtsp://192.168.100.15:8000/stream_out
</pre>
===Explanation===
In the example above we assume the following;
* There is an RTSP Stream being played in the URI: rtsp://192.168.100.20:4000/sream_in,
* The PTZ microservice is runnig in: (IP) host=192.168.100.15, port=7000
Once installed, we can use the rrms_utils module to create a client that "talks" to the server created into the ptz microservices.
{{Review|Add link to explanation of how to install rrms-utils?|mortigoza}}
First we have to import the required models:
<pre>
from rrms_utils.ptz import PTZ
from rrms_utils.models.ptz.stream import Stream
from rrms_utils.models.ptz.position import Position
from rrms_utils.models.ptz.position import Zoom
</pre>
Then we create the "client" using this command:
<pre>
# Create client
client = PTZ(host=192.168.100.15, port=7000)
</pre>
By default, like this: PTZ(), it will talk to address 127.0.0.1 and port 5020. In this example we are configuring it to talk to address 192.168.100.15 and port 7000
Here we prepare the "stream" model we want to configure into the PTZ Microservice:
<pre>
# Configure Stream
stream = Stream(in_uri="rtsp://192.168.100.20:4000/sream_in", out_port=8000, out_mapping="stream_out")
</pre>
</pre>


* in_uri is the URI where the PTZ Microservice is going to "listen" the incoming RTSP stream
* out_port is the port where the  PTZ Microservice is going to locate its output (RTSP stream transformed with the PTZ specified), in this case is the port 8000
* out_mapping is the mapping where the  PTZ Microservice is going to locate its output (RTSP stream transformed with the PTZ specified), in this case is /stream_out
Once the "stream" model is ready, we send the request to set it into the PTZ Microservice, using this command:
<pre>
set_stream_result = client.set_stream(stream)


if not set_stream_result:
    print("Something went wrong")
</pre>
Using the same logic as in the stream. We can send requests to update the PTZ, using this commands:
<pre>
# Perform PTZ
#Set the Position model to send
position = Position(pan=50, tilt=20)
#Send the request to change pan and tilt
set_position_result = client.set_position(position)
if not set_position_result:
    print("Something went wrong")
</pre>
Using the same logic as in the stream. We can send requests to update the PTZ, using this commands:
<pre>
#Set the Zoom model to send
zoom = Zoom(zoom=0.5)
#Send the request to change the zooom
set_zoom_result = client.set_zoom(zoom)
if not set_zoom_result:
    print("Something went wrong")
</pre>
Finally, we can see the output result with VLC using the commands:
<pre>
#Receive the PTZ output - RTSP Stream:
vlc rtsp://192.168.100.15:8000/stream_out
</pre>
Here the IP, the port and the mapping match with the definitions set in this example.
if you have a different configuration you can modify this command:
<pre>
#Receive the PTZ output - RTSP Stream:
vlc rtsp://ip_addres:port/mapping
</pre>




89

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.