Metropolis Microservices/RidgeRun Services/PTZ: Difference between revisions

no edit summary
No edit summary
Line 138: Line 138:
{{Review|Add link to explanation of how to install rrms-utils?|mortigoza}}
{{Review|Add link to explanation of how to install rrms-utils?|mortigoza}}


Following is an example of a typical application using rrms_utils to control the PTZ microservice:
Following is an example of a typical application using rrms_utils to control the PTZ microservice.
 
In the example above we assume the following:
 
* There is an 360-degree 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


<syntaxhighlight lang="python">
<syntaxhighlight lang="python">
Line 149: Line 154:
# Create client (by default will talk to address 127.0.0.1 and port 5020)
# Create client (by default will talk to address 127.0.0.1 and port 5020)
# Change host and port for the IP address and port of the service.
# Change host and port for the IP address and port of the service.
client = PTZ(host=192.168.100.15, port=5020
client = PTZ(host=192.168.100.15, port=7000




Line 177: Line 182:
</syntaxhighlight>
</syntaxhighlight>


The previous example will create an output stream at port 8000 with mapping stream_out. In order to display it you can use a player like VLC:
The previous example will create an output stream at port 8000 with mapping stream_out. To display it you can use a player like VLC:


<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
Line 186: Line 191:


===Code WalkTrough===
===Code WalkTrough===
* 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.
Once installed, we can use the rrms_utils module to create a client that "talks" to the server created into the ptz microservices.
Line 196: Line 197:




First we have to import the required models:
First we have to import the required models and modules:
<pre>
 
<syntaxhighlight lang="python">
from rrms_utils.ptz import PTZ
from rrms_utils.ptz import PTZ
from rrms_utils.models.ptz.stream import Stream
from rrms_utils.models.ptz.stream import Stream
from rrms_utils.models.ptz.position import Position
from rrms_utils.models.ptz.position import Position
from rrms_utils.models.ptz.position import Zoom
from rrms_utils.models.ptz.position import Zoom
</pre>
</syntaxhighlight>


Then we create the "client" using this command:
Then we create the "client" using this command:
<pre>
 
<syntaxhighlight lang="python">
# Create client  
# Create client  
client = PTZ(host=192.168.100.15, port=7000)
client = PTZ(host=192.168.100.15, port=7000)
</pre>
</syntaxhighlight>
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
 
By default, 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:
Here we prepare the "stream" model we want to configure into the PTZ Microservice:
<pre>
 
<syntaxhighlight lang="python">
# Configure Stream
# Configure Stream
stream = Stream(in_uri="rtsp://192.168.100.20:4000/sream_in", out_port=8000, out_mapping="stream_out")
stream = Stream(in_uri="rtsp://192.168.100.20:4000/sream_in", out_port=8000, out_mapping="stream_out")
</pre>
</syntaxhighlight>


* in_uri is the URI where the PTZ Microservice is going to "listen" the incoming RTSP stream
* in_uri is the URI where the PTZ Microservice is going to "listen" to 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_port is the port where the  PTZ Microservice is going to locate its output (RTSP stream transformed with the PTZ specified), in this case, 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
* 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, /stream_out


Once the "stream" model is ready, we send the request to set it into the PTZ Microservice, using this command:
Once the "stream" model is ready, we send the request to the PTZ Microservice, using this command:
<pre>
<syntaxhighlight lang="python">
#Send request to set stream in PTZ Microservice
#Send request to set stream in PTZ Microservice
set_stream_result = client.set_stream(stream)
set_stream_result = client.set_stream(stream)
Line 228: Line 233:
if not set_stream_result:
if not set_stream_result:
     print("Something went wrong")
     print("Something went wrong")
</pre>
</syntaxhighlight>




Using the same logic as in the stream. We can send requests to update the PTZ, using this commands:  
Using the same logic as in the stream. We can send requests to update pan, tilt and zoom, using these commands:  
<pre>
<syntaxhighlight lang="python">
# Perform PTZ
# Perform PTZ


Line 243: Line 248:
if not set_position_result:
if not set_position_result:
     print("Something went wrong")
     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
#Set the Zoom model to send
zoom = Zoom(zoom=0.5)
zoom = Zoom(zoom=0.5)


#Send the request to change the zooom
#Send the request to change the zoom
set_zoom_result = client.set_zoom(zoom)
set_zoom_result = client.set_zoom(zoom)


if not set_zoom_result:
if not set_zoom_result:
     print("Something went wrong")
     print("Something went wrong")
</pre>
</syntaxhighlight>




Finally, we can see the output result with VLC using the commands:
Finally, we can see the output result with VLC using the commands:
<pre>
 
<syntaxhighlight lang="bash">
#Receive the PTZ output - RTSP Stream:
#Receive the PTZ output - RTSP Stream:
vlc rtsp://192.168.100.15:8000/stream_out
vlc rtsp://192.168.100.15:8000/stream_out
</pre>
</syntaxhighlight>


Here the IP, the port and the mapping match with the definitions set in this example.  
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:
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>


<noinclude>
<noinclude>
{{Metropolis Microservices/Foot||}}
{{Metropolis Microservices/Foot||}}
</noinclude>
</noinclude>