Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VideoSources MaxIris value is Now Iris value #98

Open
hyjeong0818 opened this issue Dec 29, 2020 · 0 comments
Open

VideoSources MaxIris value is Now Iris value #98

hyjeong0818 opened this issue Dec 29, 2020 · 0 comments

Comments

@hyjeong0818
Copy link

hyjeong0818 commented Dec 29, 2020

I made everything to manipulate ptz with python

I wasn't sure about focus in/out. Onvif homepage, it seems like it's shown as focus move.

I don't know what value to get and edit, so I'll upload it.

And even when adjusting the iris (aperture) value, lowering the value is fine, but if you do +, the value doesn't change well

In this case, I think

ptz = mycam.create_imaging_service()

If you look at the options through ptz.GetOptions(), the Iris value is 0 for Max and -22 for Min.

media = mycam.create_media_service()

media_profile = media.GetVideoSources()[0]

Here, the image settings of the camera are loaded with GetVideoSources. From this value, in Imaging.Exposure

There are Iris with the current iris value, MaxIris with the maximum value of Iris, and MinIris with the minimum value.

If the current iris value is -5, MinIris takes -22, but MaxIris brings the current iris value, -5.

It seems that it doesn't change even if I bring it with the changed value every time I load it, but if you know how to fix it, please.

@api_view(['POST'])
def getMovePTZ(request):
    logger.debug("getMovePTZ start : %s", request.data)
    ptz_type = request.data.get('data')['ptz_type']
    ptz_direction = request.data.get('data')['ptz_direction']
    ptz_active = request.data.get('data')['ptz_active']

    Min = {}
    Max = {}

    if ptz_type == 'iris':
        # Create img service object
        ptz = mycam.create_imaging_service()
        imgrequest = ptz.create_type('GetImagingSettings')
        # Get target profile
        media_profile = media.GetVideoSources()[0]
        imgrequest.VideoSourceToken = media_profile.token
        img_configuration_options = ptz.GetOptions(imgrequest)

        moverequest = ptz.create_type('SetImagingSettings')
        moverequest.VideoSourceToken = media_profile.token
        if moverequest.ImagingSettings is None:
            moverequest.ImagingSettings = ptz.GetImagingSettings({'VideoSourceToken': media_profile.token})
            Min['iris'] = img_configuration_options.Exposure.Iris.Min
            Max['iris'] = img_configuration_options.Exposure.Iris.Max
    else:
        # Create ptz service object
        ptz = mycam.create_ptz_service()
        ptzrequest = ptz.create_type('GetConfigurationOptions')
        # Get target profile
        media_profile = media.GetProfiles()[0]
        ptzrequest.ConfigurationToken = media_profile.PTZConfiguration.token
        ptz_configuration_options = ptz.GetConfigurationOptions(ptzrequest)
        moverequest = ptz.create_type('ContinuousMove')
        moverequest.ProfileToken = media_profile.token
        if moverequest.Velocity is None:
            moverequest.Velocity = ptz.GetStatus({'ProfileToken': media_profile.token}).Position
            moverequest.Velocity.PanTilt.space = ptz_configuration_options.Spaces.ContinuousPanTiltVelocitySpace[0].URI
            moverequest.Velocity.Zoom.space = ptz_configuration_options.Spaces.ContinuousZoomVelocitySpace[0].URI
    direction = {
        'panning': move_panning,
        'upleft': move_upleft,
        'up': move_up,
        'upright': move_upright,
        'left': move_left,
        'right': move_right,
        'downleft': move_downleft,
        'down': move_down,
        'downright': move_downright,
        'wide': zoom_wide,
        'tele': zoom_tele,
        'in': iris_in,
        'out': iris_out,
    }
    func = direction[ptz_direction]
    if ptz_type == 'iris':
        func(ptz, moverequest, ptz_active)
    else:
        func(ptz, moverequest, Min, Max)
    return Response(None)


def ptz_move(ptz, request, active):
    if active:
        ptz.ContinuousMove(request)
    else:
        ptz.Stop({'ProfileToken': request.ProfileToken})


def move_panning(ptz, request, active):
    request.Velocity.PanTilt.x = XMOVE
    request.Velocity.PanTilt.y = 0
    request.Velocity.Zoom.x = 0
    ptz_move(ptz, request, active)


def move_up(ptz, request, active):
    request.Velocity.PanTilt.y = YMOVE
    request.Velocity.PanTilt.x = 0
    request.Velocity.Zoom.x = 0
    ptz_move(ptz, request, active)


def move_down(ptz, request, active):
    request.Velocity.PanTilt.y = -YMOVE
    request.Velocity.PanTilt.x = 0
    request.Velocity.Zoom.x = 0
    ptz_move(ptz, request, active)


def move_right(ptz, request, active):
    request.Velocity.PanTilt.x = XMOVE
    request.Velocity.PanTilt.y = 0
    request.Velocity.Zoom.x = 0
    ptz_move(ptz, request, active)


def move_left(ptz, request, active):
    request.Velocity.PanTilt.x = -XMOVE
    request.Velocity.PanTilt.y = 0
    request.Velocity.Zoom.x = 0
    ptz_move(ptz, request, active)


def move_upleft(ptz, request, active):
    request.Velocity.PanTilt.x = -XMOVE
    request.Velocity.PanTilt.y = YMOVE
    request.Velocity.Zoom.x = 0
    ptz_move(ptz, request, active)


def move_upright(ptz, request, active):
    request.Velocity.PanTilt.x = XMOVE
    request.Velocity.PanTilt.y = YMOVE
    request.Velocity.Zoom.x = 0
    ptz_move(ptz, request, active)


def move_downleft(ptz, request, active):
    request.Velocity.PanTilt.x = -XMOVE
    request.Velocity.PanTilt.y = -YMOVE
    request.Velocity.Zoom.x = 0
    ptz_move(ptz, request, active)


def move_downright(ptz, request, active):
    request.Velocity.PanTilt.x = XMOVE
    request.Velocity.PanTilt.y = -YMOVE
    request.Velocity.Zoom.x = 0
    ptz_move(ptz, request, active)


def zoom_wide(ptz, request, active):
    request.Velocity.Zoom.x = -ZMOVE
    request.Velocity.PanTilt.x = 0
    request.Velocity.PanTilt.y = 0
    ptz_move(ptz, request, active)


def zoom_tele(ptz, request, active):
    request.Velocity.Zoom.x = ZMOVE
    request.Velocity.PanTilt.x = 0
    request.Velocity.PanTilt.y = 0
    ptz_move(ptz, request, active)


def iris_in(ptz, request, Min, Max):
    request.ImagingSettings.Exposure.Iris -= 1
    if request.ImagingSettings.Exposure.Iris < Min['iris']:
        request.ImagingSettings.Exposure.Iris = Min['iris']
    ptz.SetImagingSettings(request)


def iris_out(ptz, request, Min, Max):
    request.ImagingSettings.Exposure.Iris += 1
    if request.ImagingSettings.Exposure.Iris > Max['iris']:
        request.ImagingSettings.Exposure.Iris = Max['iris']
    ptz.SetImagingSettings(request)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant