Exemple #1
0
def main():

    parser = argparse.ArgumentParser(description='An MQTT based camera controller')
    parser.add_argument('--lat', type=float, help="Latitude of camera")
    parser.add_argument('--lon', type=float, help="Longitude of camera")
    parser.add_argument('--alt', type=float, help="altitude of camera in METERS!", default=0)
    parser.add_argument('--mark-lat', type=float, help="Latitude of landmark")
    parser.add_argument('--mark-lon', type=float, help="Longitude of landmark")
    parser.add_argument('--mark-alt', type=float, help="altitude of landmark in METERS!", default=0)
    parser.add_argument('-u', '--axis-username', help="Username for the Axis camera", required=True)
    parser.add_argument('-p', '--axis-password', help="Password for the Axis camera", required=True)
    parser.add_argument('-a', '--axis-ip', help="IP address for the Axis camera", required=True)
    args = parser.parse_args()
    print(args)
    camera = vapix_control.CameraControl(args.axis_ip, args.axis_username, args.axis_password)

    print(camera)
    camera_longitude = args.lon
    camera_latitude = args.lat
    camera_altitude = args.alt # Altitude is in METERS
    landmark_longitude = args.mark_lon
    landmark_latitude = args.mark_lat
    landmark_altitude = args.mark_alt # Altitude is in METERS
    print(landmark_longitude)
    distance2d = coordinate_distance(camera_latitude, camera_longitude, landmark_latitude, landmark_longitude)
    print(distance2d)
    cameraTilt  = elevation(distance2d, cameraAltitude=camera_altitude, airplaneAltitude=landmark_altitude)

    print(cameraTilt)
    cameraPan = cameraPanFromCoordinate(cameraPosition=[camera_latitude, camera_longitude], airplanePosition=[landmark_latitude, landmark_longitude])
    print("about to move")
    camera.absolute_move(cameraPan, cameraTilt, 9999, 99)
    print("All done!")
Exemple #2
0
def moveCamera(ip, username, password):

    movePeriod = 250  # milliseconds
    capturePeriod = 1000  # milliseconds
    moveTimeout = datetime.now()
    captureTimeout = datetime.now()
    camera = vapix_control.CameraControl(ip, username, password)

    while True:
        if active:
            if not "icao24" in currentPlane:
                logging.info(" 🚨 Active but Current Plane is not set")
                continue
            if moveTimeout <= datetime.now():
                calculateCameraPosition()
                camera.absolute_move(cameraPan, cameraTilt, cameraZoom,
                                     cameraMoveSpeed)
                #logging.info("Moving to Pan: {} Tilt: {}".format(cameraPan, cameraTilt))
                moveTimeout = moveTimeout + timedelta(milliseconds=movePeriod)
                if moveTimeout <= datetime.now():
                    lag = datetime.now() - moveTimeout
                    logging.info(
                        " 🚨 Move execution time was greater that Move Period - lag: {}"
                        .format(lag))
                    moveTimeout = datetime.now() + timedelta(
                        milliseconds=movePeriod)

            if captureTimeout <= datetime.now():
                time.sleep(cameraDelay)
                get_jpeg_request()
                captureTimeout = captureTimeout + timedelta(
                    milliseconds=capturePeriod)
                if captureTimeout <= datetime.now():
                    lag = datetime.now() - captureTimeout
                    logging.info(
                        " 🚨 Capture execution time was greater that Capture Period - lag: {}"
                        .format(lag))
                    captureTimeout = datetime.now() + timedelta(
                        milliseconds=capturePeriod)
            delay = 0.005
            time.sleep(delay)
        else:
            delay = 1
            time.sleep(delay)
def capture(ip_camera):
    global exit_program

    #url http login axis camera
    ip2 = 'http://' + login + ':' + password + '@' + ip_camera + '/mjpg/1/video.mjpg?'

    #url rtsp axis camera
    #ip2 = 'rtsp://' + login + ':' + password + '@' + ip_camera + '/axis-media/media.amp'

    cap = cv2.VideoCapture(ip2)

    while True:
        ret, frame = cap.read()
        if ret is not False:
            break

    while True:
        ret, frame = cap.read()

        if exit_program == 1:
            sys.exit()

        #cv2.namedWindow('Camera', cv2.WINDOW_NORMAL)
        cv2.imshow('Camera', frame)
        event_keyboard(cv2.waitKey(1) & 0xff)


X = vapix_control.CameraControl(ip, login, password)
t = threading.Thread(target=capture, args=(ip,))
t.start()
Exemple #4
0
def main():
    global args
    global logging
    global pan
    global tilt
    global camera
    global cameraDelay
    global cameraMoveSpeed
    global cameraZoom
    global cameraConfig

    parser = argparse.ArgumentParser(
        description='An MQTT based camera controller')

    parser.add_argument(
        '-b',
        '--bearing',
        help="What bearing is the font of the PI pointed at (0-360)",
        default=0)
    parser.add_argument('-m',
                        '--mqtt-host',
                        help="MQTT broker hostname",
                        default='127.0.0.1')
    parser.add_argument('-t',
                        '--mqtt-topic',
                        help="MQTT topic to subscribe to",
                        default="SkyScan")
    parser.add_argument('-u',
                        '--axis-username',
                        help="Username for the Axis camera",
                        required=True)
    parser.add_argument('-p',
                        '--axis-password',
                        help="Password for the Axis camera",
                        required=True)
    parser.add_argument('-a',
                        '--axis-ip',
                        help="IP address for the Axis camera",
                        required=True)
    parser.add_argument(
        '-s',
        '--camera-move-speed',
        type=int,
        help="The speed at which the Axis will move for Pan/Tilt (0-100)",
        default=50)
    parser.add_argument(
        '-d',
        '--camera-delay',
        type=float,
        help=
        "How many seconds after issuing a Pan/Tilt command should a picture be taken",
        default=0.5)
    parser.add_argument('-z',
                        '--camera-zoom',
                        type=int,
                        help="The zoom setting for the camera (0-9999)",
                        default=9999)
    parser.add_argument('-v',
                        '--verbose',
                        action="store_true",
                        help="Verbose output")

    args = parser.parse_args()

    level = logging.DEBUG if args.verbose else logging.INFO

    styles = {
        'critical': {
            'bold': True,
            'color': 'red'
        },
        'debug': {
            'color': 'green'
        },
        'error': {
            'color': 'red'
        },
        'info': {
            'color': 'white'
        },
        'notice': {
            'color': 'magenta'
        },
        'spam': {
            'color': 'green',
            'faint': True
        },
        'success': {
            'bold': True,
            'color': 'green'
        },
        'verbose': {
            'color': 'blue'
        },
        'warning': {
            'color': 'yellow'
        }
    }
    level = logging.DEBUG if '-v' in sys.argv or '--verbose' in sys.argv else logging.INFO
    if 1:
        coloredlogs.install(
            level=level,
            fmt='%(asctime)s.%(msecs)03d \033[0;90m%(levelname)-8s '
            ''
            '\033[0;36m%(filename)-18s%(lineno)3d\033[00m '
            '%(message)s',
            level_styles=styles)
    else:
        # Show process name
        coloredlogs.install(
            level=level,
            fmt='%(asctime)s.%(msecs)03d \033[0;90m%(levelname)-8s '
            '\033[0;90m[\033[00m \033[0;35m%(processName)-15s\033[00m\033[0;90m]\033[00m '
            '\033[0;36m%(filename)s:%(lineno)d\033[00m '
            '%(message)s')

    logging.info(
        "---[ Starting %s ]---------------------------------------------" %
        sys.argv[0])
    camera = vapix_control.CameraControl(args.axis_ip, args.axis_username,
                                         args.axis_password)
    cameraDelay = args.camera_delay
    cameraMoveSpeed = args.camera_move_speed
    cameraZoom = args.camera_zoom
    cameraConfig = vapix_config.CameraConfiguration(args.axis_ip,
                                                    args.axis_username,
                                                    args.axis_password)

    threading.Thread(target=moveCamera, daemon=True).start()
    # Sleep for a bit so we're not hammering the HAT with updates
    time.sleep(0.005)
    print("connecting to MQTT broker at " + args.mqtt_host + ", channel '" +
          args.mqtt_topic + "'")
    client = mqtt.Client("skyscan-axis-ptz-camera-" + ID)  #create new instance

    client.on_message = on_message  #attach function to callback

    client.connect(args.mqtt_host)  #connect to broker
    client.loop_start()  #start the loop
    client.subscribe(args.mqtt_topic + "/#")
    client.publish("skyscan/registration",
                   "skyscan-axis-ptz-camera-" + ID + " Registration", 0, False)

    #############################################
    ##                Main Loop                ##
    #############################################
    timeHeartbeat = 0
    while True:
        if timeHeartbeat < time.mktime(time.gmtime()):
            timeHeartbeat = time.mktime(time.gmtime()) + 10
            client.publish("skyscan/heartbeat",
                           "skyscan-axis-ptz-camera-" + ID + " Heartbeat", 0,
                           False)
        time.sleep(0.1)
Exemple #5
0
def main():

    global camera
    global cameraConfig

    parser = argparse.ArgumentParser(
        description='An MQTT based camera controller')

    parser.add_argument('-u',
                        '--axis-username',
                        help="Username for the Axis camera",
                        required=True)
    parser.add_argument('-p',
                        '--axis-password',
                        help="Password for the Axis camera",
                        required=True)
    parser.add_argument('-a',
                        '--axis-ip',
                        help="IP address for the Axis camera",
                        required=True)

    args = parser.parse_args()
    print("hello")

    styles = {
        'critical': {
            'bold': True,
            'color': 'red'
        },
        'debug': {
            'color': 'green'
        },
        'error': {
            'color': 'red'
        },
        'info': {
            'color': 'white'
        },
        'notice': {
            'color': 'magenta'
        },
        'spam': {
            'color': 'green',
            'faint': True
        },
        'success': {
            'bold': True,
            'color': 'green'
        },
        'verbose': {
            'color': 'blue'
        },
        'warning': {
            'color': 'yellow'
        }
    }
    level = logging.DEBUG if '-v' in sys.argv or '--verbose' in sys.argv else logging.INFO
    if 1:
        coloredlogs.install(
            level=level,
            fmt='%(asctime)s.%(msecs)03d \033[0;90m%(levelname)-8s '
            ''
            '\033[0;36m%(filename)-18s%(lineno)3d\033[00m '
            '%(message)s',
            level_styles=styles)
    else:
        # Show process name
        coloredlogs.install(
            level=level,
            fmt='%(asctime)s.%(msecs)03d \033[0;90m%(levelname)-8s '
            '\033[0;90m[\033[00m \033[0;35m%(processName)-15s\033[00m\033[0;90m]\033[00m '
            '\033[0;36m%(filename)s:%(lineno)d\033[00m '
            '%(message)s')
    print("hello")
    logging.info(
        "---[ Starting %s ]---------------------------------------------" %
        sys.argv[0])
    camera = vapix_control.CameraControl(args.axis_ip, args.axis_username,
                                         args.axis_password)
    print("hello")
    #############################################
    ##                Main Loop                ##
    #############################################
    while True:
        camera.absolute_move(0, 0, 0, 50)
        time.sleep(5)
        camera.absolute_move(90, 0, 0, 50)
        time.sleep(5)
        camera.absolute_move(180, 0, 0, 50)
        time.sleep(5)
        camera.absolute_move(270, 0, 0, 50)
        time.sleep(5)
        camera.absolute_move(0, 90, 0, 50)
        time.sleep(5)