Beispiel #1
0
    def setupAPI(self):
        self._codec='mq'
        api = Motif(self.CAMERA_IP, self.CAMERA_KEY)
        
        caminfo = pd.DataFrame(api.call('cameras').items()[0][1])
        if len(caminfo) >1:
            self.MULTICAM = True
        else:
            self.MULTICAM = False            
        serials = []
        print caminfo
        for cam in caminfo.index:
            if "Ximea" in caminfo.ix[cam]['name']:
                serials.append(cam['name'].split('(')[1][0])
            else:
                serials.append(caminfo.ix[cam]['serial'])
        self.CAMERA_SERIAL = serials                

        return api   
Beispiel #2
0
def loopbio_record(IP, KEY, FN, DUR, META, SN):
    _codec = 'nvenc-mq'
    api = Motif(IP, KEY)

    camInfo = pd.DataFrame(api.call('cameras').items()[0][1])
    camName = camInfo[camInfo.serial == SN]['name'].values[0]
    if "Ximea" in camName:
        SN = camName.split('(')[1][0]

    if not (api.call('camera/' + SN)['camera_info']['status'] == 'ready'):
        raise Exception('CAMERA IS ALREADY IN USE')
    #camsn = api.call('cameras')['cameras'][0]['serial']
    api.call('camera/' + SN + '/configure',
             AcquisitionFrameRate=40.0,
             ExposureTime=2000.0)
    foo = api.call('camera/' + SN + '/recording/start',
                   duration=DUR,
                   filename=FN,
                   codec=_codec,
                   record_to_store=True,
                   metadata=META)
    return foo
Beispiel #3
0
from __future__ import print_function
import time
import logging
logging.basicConfig(level=logging.INFO)

from motifapi import MotifApi

# You need to fill these out
IP_ADDRESS = None
API_KEY = None

api = MotifApi(IP_ADDRESS, API_KEY)

# get serial number of first connected camera
camsn = api.call('cameras')['cameras'][0]['serial']

# start recording on one camera
print(
    api.call('camera/%s/recording/start' % camsn,
             codec='h264',
             filename='testing_file',
             metadata={
                 'title': 'test file',
                 'description': 'a long description'
             }))
time.sleep(5)
# stop recording on 'all cameras'
print(api.call('camera/%s/recording/stop' % camsn))

# wait for recording to finish (sometimes need to flush the buffer, close video, etc)
while api.is_recording(camsn):
Beispiel #4
0
from __future__ import print_function
import logging
logging.basicConfig(level=logging.DEBUG)

from motifapi import MotifApi

# You need to fill these out
IP_ADDRESS = None
API_KEY = None

api = MotifApi(IP_ADDRESS, API_KEY)

camera_serial = 'FAKE0'

# list all scheduled tasks
print(api.call('schedule'))

# clear one scheduled task by name
# api.call('schedule/%s/clear' % task_name)

# clear all scheduled tasks
# warning: if you share this recording system with others it will also clear their tasks!
api.call('schedule/clear')

# schedule a recording for 10 seconds at :09 between the hours of 16-17h, every day
api.call('schedule/recording/start',
         task_name='record_video',
         cron_expression='09 16-17 * * *',
         codec='libx264',
         duration=10)
Beispiel #5
0
## pip install git+https://github.com/loopbio/python-motifapi


from __future__ import print_function
import time
import logging

logging.basicConfig(level=logging.INFO)

from motifapi import MotifApi

IP_ADDRESS = 
API_KEY = 

api = MotifApi(IP_ADDRESS, API_KEY)


#Note that they suggest using imgstores for synchronization
camera_serials = [cinfo['serial'] for cinfo in api.call('cameras')['cameras']]

# record for one day
# 86400
print(api.call('recording/start', codec='h264', filename='test_store', duration=10, record_to_store=False,
               metadata={'title': 'Script testing', 'description': 'synchronized start'}))

# wait for all cameras to finish recording
while any(api.is_recording(_sn) for _sn in camera_serials):
    print('still recording %r' % (camera_serials,))
    time.sleep(1)
Beispiel #6
0
from __future__ import print_function
from motifapi import MotifApi

if __name__ == "__main__":
    import argparse
    import logging

    parser = argparse.ArgumentParser()
    parser.add_argument('--ip', required=True)
    parser.add_argument('--api-key', required=True)
    parser.add_argument('--verbose', action='store_true', default=False)

    args = parser.parse_args()

    logging.basicConfig(level=logging.DEBUG if args.verbose else logging.INFO)

    api = MotifApi(args.ip, args.api_key)
    print("version: %r" % (api.call('version'), ))
Beispiel #7
0
from __future__ import print_function

import cv2

from motifapi import MotifApi
api = MotifApi(None, None)

stream = api.get_stream(stream_type=MotifApi.STREAM_TYPE_STATE)
if stream is not None:
    while True:
        print(stream.get_next_state())

Beispiel #8
0
# used for testing purposes
from motifapi import MotifApi
import time

IP_ADDRESS = '172.22.131.182'
API_KEY = '796545a75a174cb28e6e5c24e011eccc'

api = MotifApi(IP_ADDRESS, API_KEY)

# get serial number of first connected camera
# camsn = '193500097'#api.call('cameras')['cameras'][0]['serial']
camsn = '194600051'
response = api.call('camera/%s' % camsn)
print(response['camera_info']['stream']['preview']['url'])

# start recording on one camera
# print(api.call('camera/%s/recording/start' % camsn,  codec='h264-hq', filename='testing_file',
#                metadata={'title': 'test file', 'description': 'a long description'}))
# time.sleep(5)
# # stop recording on 'all cameras'
# print(api.call('camera/%s/recording/stop' % camsn))

# # wait for recording to finish (sometimes need to flush the buffer, close video, etc)
# while api.is_recording(camsn):
#     print('%s still recording' % camsn)
#     response = api.call('camera/%s' % camsn)
#     print(response)
#     time.sleep(1)

# # in a multi-camera environment you should record to stores as these allow synchronization and
# # stitching multiple videos
Beispiel #9
0
from __future__ import print_function

import logging
logging.basicConfig(level=logging.DEBUG)

from motifapi import MotifApi

# You need to fill these out
IP_ADDRESS = None
API_KEY = None

api = MotifApi(IP_ADDRESS, API_KEY)

# set the serial number of the first started camera
camsn = api.call('cameras')['cameras'][0]['serial']
print(api.call('camera/%s' % camsn))

# set that camera to 5 fps
api.call('camera/%s/configure' % camsn, AcquisitionFrameRate=5.0)
Beispiel #10
0
    def run(self):
        while True:
            I, md = self._stream.get_next_image(copy=False)
            with self._lock:
                self._img = I.copy()
                self._md = md.copy()

    @property
    def latest_image(self):
        with self._lock:
            if self._img is not None:
                return self._img, self._md


def slow_thing(I, md):
    time.sleep(0.1)
    cv2.imshow('live', I)
    cv2.waitKey(1)


if __name__ == "__main__":
    api = MotifApi(None, None)

    poller = LatestImage(api)
    poller.start()

    while True:
        latest = poller.latest_image
        if latest is not None:
            slow_thing(*latest)
Beispiel #11
0
import time
import pprint

from motifapi import MotifApi, MotifError
api = MotifApi(None, None)

while 1:
    try:
        resp = api.call('cameras')
        for c in resp.get('cameras'):
            pprint.pprint(api.call('camera/%s' % c['serial']))
    except MotifError:
        pass
    time.sleep(2)

Beispiel #12
0
from __future__ import print_function

import time
import random
import logging
logging.basicConfig(level=logging.DEBUG)

from motifapi import MotifApi

# You need to fill these out
IP_ADDRESS = None
API_KEY = None

api = MotifApi(IP_ADDRESS, API_KEY)

# demonstrates how to set the value of an IO output which has been configured
# in the backend by name
#
# i.e. in this example there is one LED Output configured

api.call('io/led/set', value=random.random())
Beispiel #13
0
from __future__ import print_function

import time
import random
import logging
logging.basicConfig(level=logging.DEBUG)

from motifapi import MotifApi

# You need to fill these out
IP_ADDRESS = None
API_KEY = None

api = MotifApi(IP_ADDRESS, API_KEY)

# In single camera mode, with phidgets backend, you can leave the backend
# connection unconfigured and just set its state (0/1) or value (0 - 1)
# explicitly/lazily when required.
#
# This allows easy testing without adjusting the config file
#
# First parameter (-1) is the serial number of the phidget. if you have
# multiple connected, you must set this. Otherwise -1 uses the first
# detected device
#
# the second parameter, '0', is the port the digital output is connected to
#
# you pass state=1 to turn it on, state=0 to turn it off

api.call('io/-1/0/set', state=1)
time.sleep(2)
Beispiel #14
0
from __future__ import print_function

import time
import random
import logging
logging.basicConfig(level=logging.DEBUG)

from motifapi import MotifApi

IP_ADDRESS = None
API_KEY = None

api = MotifApi(IP_ADDRESS, API_KEY)

# demonstrates how to set the value of IO channels that have been
# configured and are associated with one camera, in a multiple camera
# (index, master, or slave) setup

api.call('camera/FAKE0/io/ledgreen/set', value=random.random())
api.call('camera/FAKE1/io/led/set', value=random.random())