delucaide
Posts: 11
Joined: Mon Nov 06, 2017 4:07 pm

Control an IP camera Onvif compliant

Mon Nov 20, 2017 3:03 pm

Hi guys,
i'm trying to control an ip camera using the Python libraries https://github.com/quatanium/python-onvif

I'm able to connect to the camera and change his name using the example:

Interactive mode

$ onvif-cli -u 'admin' -a '12345' --host '192.168.0.112' --port 80 --wsdl /etc/onvif/wsdl/
ONVIF >>> cmd
analytics devicemgmt events imaging media ptz
ONVIF >>> cmd devicemgmt GetWsdlUrl
True: http://www.onvif.org/
ONVIF >>> cmd devicemgmt SetHostname {'Name': 'NewHostname'}
ONVIF >>> cmd devicemgmt GetHostname
True: {'Name': 'NewHostName'}

but when i try to control the camera PTZ i'm not sure on how can i give the right command. For example to control the zoom in/Out.
I tried to understand the onvif manual but without success after a week of tests.

Anybody can please help me?

delucaide
Posts: 11
Joined: Mon Nov 06, 2017 4:07 pm

Re: Control an IP camera Onvif compliant

Mon Nov 20, 2017 8:53 pm

Nobody can help me?


User avatar
elParaguayo
Posts: 1905
Joined: Wed May 16, 2012 12:46 pm
Location: London, UK

Re: Control an IP camera Onvif compliant

Tue Nov 21, 2017 8:02 am

Go easy on the bumping. It hasn't even been 24 hours since your first post. Everyone here is a volunteer who answers questions whenever they can so please give people a chance to read your post in their own time.

One comment: your example isn't really python related (other than the tool being written in python). Your question is more about using the tool itself and I wonder if you may have more luck in a different subforum (maybe "Graphics, Sound and Multimedia").
RPi Information Screen: plugin based system for displaying weather, travel information, football scores etc.

delucaide
Posts: 11
Joined: Mon Nov 06, 2017 4:07 pm

Re: Control an IP camera Onvif compliant

Tue Nov 21, 2017 9:09 am

Thanks for your reply.
I’m sorry but i’m playing on it for 2 weeks now without any solution.

User avatar
elParaguayo
Posts: 1905
Joined: Wed May 16, 2012 12:46 pm
Location: London, UK

Re: Control an IP camera Onvif compliant

Tue Nov 21, 2017 12:21 pm

I've just noticed you posted your question in a different subforum a couple of weeks ago so I understand your anxiety. Unfortunately, I would guess that the lack of response means that (so far) no one who has seen your post is familiar with onvif camera and the relevant python library.

I note that you've also posted a question on the project's Github page. I think that's a very sensible idea and hopefully you'll have more luck there.

Lastly, the code on this issue on the project page seems to include some zoom commands so you may be able to work something out from that.

Good luck.
RPi Information Screen: plugin based system for displaying weather, travel information, football scores etc.

delucaide
Posts: 11
Joined: Mon Nov 06, 2017 4:07 pm

Re: Control an IP camera Onvif compliant

Tue Nov 21, 2017 9:50 pm

I'm tryng to give this kind of xml soap request:
[codes:
Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<ContinuousMove xmlns="http://www.onvif.org/ver20/ptz/wsdl">
<ProfileToken>defaultPrimary</ProfileToken>
<Velocity>
<Zoom x="0.5" xmlns="http://www.onvif.org/ver10/schema"/>
</Velocity>
</ContinuousMove>
</s:Body>][/code]

that should be like a tree as per soap request form .
I'm trying with this CMD Python code:

Code: Select all

[ONVIF >>> [b]cmd ptz ContinuousMove {'ProfileToken': 'defaultPrimary' , 'Velocity' [ 'Zoom' : 'x="0.5"']}[/b]
Traceback (most recent call last):
  File "/usr/local/bin/onvif-cli", line 11, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.5/dist-packages/onvif/cli.py", line 165, in main
    cli.cmdloop()
  File "/usr/lib/python3.5/cmd.py", line 138, in cmdloop
    stop = self.onecmd(line)
  File "/usr/lib/python3.5/cmd.py", line 217, in onecmd
    return func(arg)
  File "/usr/local/lib/python3.5/dist-packages/onvif/cli.py", line 75, in do_cmd
    args.params = dict(literal_eval(match.group(1)))
  File "/usr/lib/python3.5/ast.py", line 46, in literal_eval
    node_or_string = parse(node_or_string, mode='eval')
  File "/usr/lib/python3.5/ast.py", line 35, in parse
    return compile(source, filename, mode, PyCF_ONLY_AST)
  File "<unknown>", line 1
    {'ProfileToken':'defaultPrimary','Velocity'['Zoom':'x="0.5"']}
    


but the terminal show me something wrong, highlighting the last parenthesis.

User avatar
elParaguayo
Posts: 1905
Joined: Wed May 16, 2012 12:46 pm
Location: London, UK

Re: Control an IP camera Onvif compliant

Wed Nov 22, 2017 10:11 am

Well, if you're doing a ContinuousMove operation, you should look at the example in Github.

Having looked at that, here's a guess for doing it from python:

Code: Select all

from onvif import ONVIFCamera

def perform_move(ptz, request, timeout):
    # Start continuous move
    ptz.ContinuousMove(request)
    # Wait a certain time
    sleep(timeout)
    # Stop continuous move
    ptz.Stop({'ProfileToken': request.ProfileToken})

# Set up camera - you'll need to change these as necessary
mycam = ONVIFCamera('192.168.0.112', 80, 'admin', '12345')
# Create media service object
media = mycam.create_media_service()
# Create ptz service object
ptz = mycam.create_ptz_service()

# Get target profile
media_profile = media.GetProfiles()[0];

# Get PTZ configuration options for getting continuous move range
request = ptz.create_type('GetConfigurationOptions')
request.ConfigurationToken = media_profile.PTZConfiguration._token
ptz_configuration_options = ptz.GetConfigurationOptions(request)

request = ptz.create_type('ContinuousMove')
request.ProfileToken = media_profile._token

ptz.Stop({'ProfileToken': media_profile._token})


# THIS BIT IS MY GUESS!
request.Velocity.Zoom._x = 0.5
perform_move(ptz, request, 1)
RPi Information Screen: plugin based system for displaying weather, travel information, football scores etc.

delucaide
Posts: 11
Joined: Mon Nov 06, 2017 4:07 pm

Re: Control an IP camera Onvif compliant

Wed Nov 22, 2017 11:29 am

elParaguayo wrote:
Wed Nov 22, 2017 10:11 am
Well, if you're doing a ContinuousMove operation, you should look at the example in Github.

Having looked at that, here's a guess for doing it from python:

Code: Select all

from onvif import ONVIFCamera

def perform_move(ptz, request, timeout):
    # Start continuous move
    ptz.ContinuousMove(request)
    # Wait a certain time
    sleep(timeout)
    # Stop continuous move
    ptz.Stop({'ProfileToken': request.ProfileToken})

# Set up camera - you'll need to change these as necessary
mycam = ONVIFCamera('192.168.0.112', 80, 'admin', '12345')
# Create media service object
media = mycam.create_media_service()
# Create ptz service object
ptz = mycam.create_ptz_service()

# Get target profile
media_profile = media.GetProfiles()[0];

# Get PTZ configuration options for getting continuous move range
request = ptz.create_type('GetConfigurationOptions')
request.ConfigurationToken = media_profile.PTZConfiguration._token
ptz_configuration_options = ptz.GetConfigurationOptions(request)

request = ptz.create_type('ContinuousMove')
request.ProfileToken = media_profile._token

ptz.Stop({'ProfileToken': media_profile._token})


# THIS BIT IS MY GUESS!
request.Velocity.Zoom._x = 0.5
perform_move(ptz, request, 1)
Hi elParaguayo and man thanks for your reply,

i tried that code including the right ip address , username and password but this is what i get:

Code: Select all

Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/onvif/client.py", line 24, in wrapped
    return func(*args, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/onvif/client.py", line 180, in wrapped
    return call(params, callback)
  File "/usr/local/lib/python3.5/dist-packages/onvif/client.py", line 167, in call
    ret = func(**params)
  File "/usr/local/lib/python3.5/dist-packages/zeep/client.py", line 41, in __call__
    self._op_name, args, kwargs)
  File "/usr/local/lib/python3.5/dist-packages/zeep/wsdl/bindings/soap.py", line 121, in send
    return self.process_reply(client, operation_obj, response)
  File "/usr/local/lib/python3.5/dist-packages/zeep/wsdl/bindings/soap.py", line 185, in process_reply
    result = operation.process_reply(doc)
  File "/usr/local/lib/python3.5/dist-packages/zeep/wsdl/bindings/soap.py", line 366, in process_reply
    return self.output.deserialize(envelope)
  File "/usr/local/lib/python3.5/dist-packages/zeep/wsdl/messages/soap.py", line 90, in deserialize
    body_result = self._deserialize_body(body)
  File "/usr/local/lib/python3.5/dist-packages/zeep/wsdl/messages/soap.py", line 411, in _deserialize_body
    result = self.body.parse(xmlelement, self.wsdl.types)
  File "/usr/local/lib/python3.5/dist-packages/zeep/xsd/elements/element.py", line 114, in parse
    schema_type=self.type)
  File "/usr/local/lib/python3.5/dist-packages/zeep/xsd/types/complex.py", line 169, in parse_xmlelement
    elements, schema, name, context=context)
  File "/usr/local/lib/python3.5/dist-packages/zeep/xsd/elements/indicators.py", line 600, in parse_xmlelements
    xmlelements, schema, name, context=context)
  File "/usr/local/lib/python3.5/dist-packages/zeep/xsd/elements/element.py", line 160, in parse_xmlelements
    xmlelement, schema, allow_none=True, context=context)
  File "/usr/local/lib/python3.5/dist-packages/zeep/xsd/elements/element.py", line 114, in parse
    schema_type=self.type)
  File "/usr/local/lib/python3.5/dist-packages/zeep/xsd/types/complex.py", line 169, in parse_xmlelement
    elements, schema, name, context=context)
  File "/usr/local/lib/python3.5/dist-packages/zeep/xsd/elements/indicators.py", line 600, in parse_xmlelements
    xmlelements, schema, name, context=context)
  File "/usr/local/lib/python3.5/dist-packages/zeep/xsd/elements/element.py", line 160, in parse_xmlelements
    xmlelement, schema, allow_none=True, context=context)
  File "/usr/local/lib/python3.5/dist-packages/zeep/xsd/elements/element.py", line 114, in parse
    schema_type=self.type)
  File "/usr/local/lib/python3.5/dist-packages/zeep/xsd/types/complex.py", line 169, in parse_xmlelement
    elements, schema, name, context=context)
  File "/usr/local/lib/python3.5/dist-packages/zeep/xsd/elements/indicators.py", line 600, in parse_xmlelements
    xmlelements, schema, name, context=context)
  File "/usr/local/lib/python3.5/dist-packages/zeep/xsd/elements/element.py", line 160, in parse_xmlelements
    xmlelement, schema, allow_none=True, context=context)
  File "/usr/local/lib/python3.5/dist-packages/zeep/xsd/elements/element.py", line 114, in parse
    schema_type=self.type)
  File "/usr/local/lib/python3.5/dist-packages/zeep/xsd/types/complex.py", line 169, in parse_xmlelement
    elements, schema, name, context=context)
  File "/usr/local/lib/python3.5/dist-packages/zeep/xsd/elements/indicators.py", line 600, in parse_xmlelements
    xmlelements, schema, name, context=context)
  File "/usr/local/lib/python3.5/dist-packages/zeep/xsd/elements/element.py", line 160, in parse_xmlelements
    xmlelement, schema, allow_none=True, context=context)
  File "/usr/local/lib/python3.5/dist-packages/zeep/xsd/elements/element.py", line 114, in parse
    schema_type=self.type)
  File "/usr/local/lib/python3.5/dist-packages/zeep/xsd/types/complex.py", line 169, in parse_xmlelement
    elements, schema, name, context=context)
  File "/usr/local/lib/python3.5/dist-packages/zeep/xsd/elements/indicators.py", line 600, in parse_xmlelements
    xmlelements, schema, name, context=context)
  File "/usr/local/lib/python3.5/dist-packages/zeep/xsd/elements/element.py", line 160, in parse_xmlelements
    xmlelement, schema, allow_none=True, context=context)
  File "/usr/local/lib/python3.5/dist-packages/zeep/xsd/elements/element.py", line 114, in parse
    schema_type=self.type)
  File "/usr/local/lib/python3.5/dist-packages/zeep/xsd/types/complex.py", line 169, in parse_xmlelement
    elements, schema, name, context=context)
  File "/usr/local/lib/python3.5/dist-packages/zeep/xsd/elements/indicators.py", line 600, in parse_xmlelements
    xmlelements, schema, name, context=context)
  File "/usr/local/lib/python3.5/dist-packages/zeep/xsd/elements/element.py", line 160, in parse_xmlelements
    xmlelement, schema, allow_none=True, context=context)
  File "/usr/local/lib/python3.5/dist-packages/zeep/xsd/elements/element.py", line 114, in parse
    schema_type=self.type)
  File "/usr/local/lib/python3.5/dist-packages/zeep/xsd/types/complex.py", line 189, in parse_xmlelement
    init_kwargs[name] = attribute.parse(value)
  File "/usr/local/lib/python3.5/dist-packages/zeep/xsd/elements/attribute.py", line 22, in parse
    return self.type.pythonvalue(value)
  File "/usr/local/lib/python3.5/dist-packages/zeep/xsd/types/simple.py", line 68, in pythonvalue
    '%s.pytonvalue() not implemented' % self.__class__.__name__)
NotImplementedError: AnySimpleType.pytonvalue() not implemented

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/pi/Desktop/post.py", line 19, in <module>
    media_profile = media.GetProfiles()[0];
  File "/usr/local/lib/python3.5/dist-packages/onvif/client.py", line 28, in wrapped
    raise ONVIFError(err)
onvif.exceptions.ONVIFError: Unknown error: AnySimpleType.pytonvalue() not implemented
There-s something wrong that i really don't understand :O

User avatar
elParaguayo
Posts: 1905
Joined: Wed May 16, 2012 12:46 pm
Location: London, UK

Re: Control an IP camera Onvif compliant

Wed Nov 22, 2017 12:10 pm

That's disappointing (but I would have been amazed if it had worked).

I'm out of ideas and, without a camera of my own, there's little else I can do.

You may want to paste that error onto the Github issues page given that it's an error that arises from a line in their own example code.
RPi Information Screen: plugin based system for displaying weather, travel information, football scores etc.

delucaide
Posts: 11
Joined: Mon Nov 06, 2017 4:07 pm

Re: Control an IP camera Onvif compliant

Wed Nov 22, 2017 12:27 pm

Thanks anyway for your help.
As per your suggestion i’ll try to paste the error code there.

Hope somebody can give me help here too.

Return to “Python”

Who is online

Users browsing this forum: No registered users and 17 guests