Beispiel #1
0
def start_mapping():
    global kondisi
    kondisi = 'start'
    if kondisi == 'start':
        node = Node("localhost", 3000)
        try:
            # Start a task
            print("Uploading images...")
            task = node.create_task(open_file, {
                'dsm': True,
                'orthophoto-resolution': 3
            })
            print(task.info())

            try:
                # This will block until the task is finished
                # or will raise an exception
                task.wait_for_completion()

                print("Task completed, downloading results...")

                # Retrieve results
                task.download_assets("results")

                print("Assets saved in ./results (%s)" % os.listdir("results"))

                # Restart task and this time compute dtm
                task.restart({'dtm': True})
                task.wait_for_completion()

                print("Task completed, downloading results...")

                task.download_assets("./results_with_dtm")

                print("Assets saved in ./results_with_dtm (%s)" %
                      os.listdir("./results_with_dtm"))
            except exceptions.TaskFailedError as e:
                print("\n".join(task.output()))

        except exceptions.NodeConnectionError as e:
            print("Cannot connect: %s" % e)
        except exceptions.NodeResponseError as e:
            print("Error: %s" % e)
Beispiel #2
0
    def test_token_auth(self):
        def wait_for_status(api,
                            uuid,
                            status,
                            num_retries=10,
                            error_description="Failed to wait for status"):
            retries = 0
            while True:
                try:
                    task_info = api.get_task(uuid).info()
                    if task_info.status.value == status:
                        return True
                except (NodeResponseError, NodeServerError):
                    pass

                time.sleep(0.5)
                retries += 1
                if retries >= num_retries:
                    self.assertTrue(False, error_description)
                    return False

        with start_processing_node(['--token', 'test_token']):
            api = Node("localhost", 11223, "test_token")
            online_node = ProcessingNode.objects.get(pk=3)

            self.assertTrue(online_node.update_node_info(),
                            "Could update info")

            # Cannot call info(), options()  without tokens
            api.token = "invalid"
            self.assertRaises(NodeResponseError, api.info)
            self.assertRaises(NodeResponseError, api.options)

            # Cannot call create_task() without token
            import glob
            self.assertRaises(NodeResponseError, api.create_task,
                              glob.glob("nodeodm/fixtures/test_images/*.JPG"))

            # Can call create_task() with token
            api.token = "test_token"
            res = api.create_task(
                glob.glob("nodeodm/fixtures/test_images/*.JPG"))
            uuid = res.uuid
            self.assertTrue(uuid != None)

            # Can call task_info() with token
            task_info = api.get_task(uuid).info()
            self.assertTrue(isinstance(task_info.date_created, datetime))

            # Cannot call task_info() without token
            api.token = "invalid"
            try:
                api.get_task(uuid).info()
            except NodeResponseError as e:
                self.assertTrue('token does not match' in str(e))

            # Here we are waiting for the task to be completed
            api.token = "test_token"
            wait_for_status(api, uuid, status_codes.COMPLETED, 10,
                            "Could not download assets")

            # Cannot download assets without token
            api.token = "invalid"
            task = api.get_task(uuid)
            self.assertRaises(NodeResponseError, task.download_assets,
                              settings.MEDIA_TMP)

            api.token = "test_token"
            asset_archive = task.download_zip(settings.MEDIA_TMP)
            self.assertTrue(os.path.exists(asset_archive))
            os.unlink(asset_archive)

            # Cannot get task output without token
            api.token = "invalid"
            self.assertRaises(NodeResponseError, task.output, 0)

            api.token = "test_token"
            res = task.output()
            self.assertTrue(isinstance(res, list))

            # Cannot restart task without token
            online_node.token = "invalid"
            self.assertRaises(NodeResponseError, online_node.restart_task,
                              uuid)

            online_node.token = "test_token"
            self.assertTrue(online_node.restart_task(uuid))

            # Cannot cancel task without token
            online_node.token = "invalid"
            self.assertRaises(NodeResponseError, online_node.cancel_task, uuid)
            online_node.token = "test_token"
            self.assertTrue(online_node.cancel_task(uuid))

            # Wait for task to be canceled
            wait_for_status(api, uuid, status_codes.CANCELED, 5,
                            "Could not cancel task")

            # Cannot delete task without token
            online_node.token = "invalid"
            self.assertRaises(NodeResponseError, online_node.remove_task,
                              "invalid token")
            online_node.token = "test_token"
            self.assertTrue(online_node.remove_task(uuid))
Beispiel #3
0
    def test_client_api_and_task_methods(self):
        def wait_for_status(api,
                            uuid,
                            status,
                            num_retries=10,
                            error_description="Failed to wait for status"):
            retries = 0
            while True:
                try:
                    task_info = api.get_task(uuid).info()
                    if task_info.status.value == status:
                        return True
                except (NodeServerError, NodeResponseError):
                    pass

                time.sleep(0.5)
                retries += 1
                if retries >= num_retries:
                    self.assertTrue(False, error_description)
                    return False

        with start_processing_node():
            api = Node("localhost", 11223)
            online_node = ProcessingNode.objects.get(pk=1)

            # Can call info(), options()
            self.assertTrue(type(api.info().version) == str)
            self.assertTrue(len(api.options()) > 0)

            # Can call new_task()
            import glob
            res = api.create_task(
                glob.glob("nodeodm/fixtures/test_images/*.JPG"),
                {'force-ccd': 6.16}, "test")
            uuid = res.uuid
            self.assertTrue(uuid != None)

            # Can call task_info()
            task = api.get_task(uuid)
            task_info = task.info()
            self.assertTrue(isinstance(task_info.date_created, datetime))
            self.assertTrue(isinstance(task_info.uuid, str))

            # Can download assets?
            # Here we are waiting for the task to be completed
            wait_for_status(api, uuid, status_codes.COMPLETED, 10,
                            "Could not download assets")
            asset = api.get_task(uuid).download_zip(settings.MEDIA_TMP)
            self.assertTrue(os.path.exists(asset))

            # task_output
            self.assertTrue(isinstance(api.get_task(uuid).output(0), list))
            self.assertTrue(
                isinstance(online_node.get_task_console_output(uuid, 0), list))

            self.assertRaises(NodeResponseError,
                              online_node.get_task_console_output,
                              "wrong-uuid", 0)

            # Can restart task
            self.assertTrue(online_node.restart_task(uuid))
            self.assertRaises(NodeResponseError, online_node.restart_task,
                              "wrong-uuid")

            wait_for_status(api, uuid, status_codes.COMPLETED, 10,
                            "Could not restart task")

            # Can restart task by passing options
            self.assertTrue(
                online_node.restart_task(uuid, [{
                    'name': 'mesh-size',
                    'value': 12345
                }, {
                    'name': 'invalid',
                    'value': True
                }]))
            wait_for_status(api, uuid, status_codes.COMPLETED, 10,
                            "Could not restart task with options")

            # Verify that options have been updated after restarting the task
            task_info = api.get_task(uuid).info()
            self.assertTrue(len(
                task_info.options) == 2)  # pc-ept has been added
            self.assertTrue(task_info.options[0]['name'] == 'mesh-size')
            self.assertTrue(task_info.options[0]['value'] == 12345)

            # Can cancel task (should work even if we completed the task)
            self.assertTrue(online_node.cancel_task(uuid))
            self.assertRaises(NodeResponseError, online_node.cancel_task,
                              "wrong-uuid")

            # Wait for task to be canceled
            wait_for_status(api, uuid, status_codes.CANCELED, 5,
                            "Could not remove task")
            self.assertTrue(online_node.remove_task(uuid))
            self.assertRaises(NodeResponseError, online_node.remove_task,
                              "wrong-uuid")

            # Cannot delete task again
            self.assertRaises(NodeResponseError, online_node.remove_task, uuid)

            # Task has been deleted
            self.assertRaises(NodeResponseError, online_node.get_task_info,
                              uuid)

            # Test URL building for HTTPS
            sslApi = Node("localhost", 443, 'abc')
            self.assertEqual(sslApi.url('/info'),
                             'https://localhost/info?token=abc')
Beispiel #4
0
import os
from pyodm import Node

print("Creating Node connection")
nd = Node("localhost", 3000)

print("Creating ODM task...")
path = os.path.realpath("images")
image_list = [
    path + "/1-1.jpg", path + "/1-2.jpg", path + "/1-3.jpg", path + "/1-4.jpg",
    path + "/1-5.jpg", path + "/1-6.jpg", path + "/1-7.jpg", path + "/1-8.jpg",
    path + "/1-9.jpg", path + "/1-10.jpg", path + "/1-11.jpg"
]

image_list_1 = [path + "/1-1.jpg", path + "/1-2.jpg", path + "/1-3.jpg"]

task = nd.create_task(image_list_1)

print("Running task...")
task.wait_for_completion()

print("Completed")
os.listdir(task.download_assets("results"))
Beispiel #5
0
import glob
from pyodm import Node, exceptions

node = Node("localhost", 3000)

try:
    # Get all JPG files in directory
    images = glob.glob("*.JPG") + glob.glob("*.jpg") + glob.glob(
        "*.JPEG") + glob.glob("*.jpeg")

    print("Uploading images...")
    task = node.create_task(images, {'dsm': True, 'orthophoto-resolution': 2})
    print(task.info())

    try:

        def print_status(task_info):
            msecs = task_info.processing_time
            seconds = int((msecs / 1000) % 60)
            minutes = int((msecs / (1000 * 60)) % 60)
            hours = int((msecs / (1000 * 60 * 60)) % 24)
            print("Task is running: %02d:%02d:%02d" %
                  (hours, minutes, seconds),
                  end="\r")

        task.wait_for_completion(status_callback=print_status)

        print("Task completed, downloading results...")

        # Retrieve results
        def print_download(progress):
Beispiel #6
0
import os
import sys
sys.path.append('..')

from pyodm import Node, exceptions

node = Node("localhost", 3000)

try:
    # Start a task
    print("Uploading images...")
    task = node.create_task(['images/image_1.jpg', 'images/image_2.jpg'],
                            {'dsm': True, 'orthophoto-resolution': 4})
    print(task.info())

    try:
        # This will block until the task is finished
        # or will raise an exception
        task.wait_for_completion()

        print("Task completed, downloading results...")

        # Retrieve results
        task.download_assets("./results")

        print("Assets saved in ./results (%s)" % os.listdir("./results"))

        # Restart task and this time compute dtm
        task.restart({'dtm': True})
        task.wait_for_completion()
Beispiel #7
0
result_path = image_dir.split('/')[0] + '_results'
ip = '192.168.99.100'  # 改为自己的ip
port = 3000

start = time.time()
images_name = os.listdir(image_dir)
images_name = [image_dir + image_name for image_name in images_name]
print(images_name)

n = Node(ip, port)
print("Node连接成功,{}张图开始处理".format(len(images_name)))

task = n.create_task(
    images_name, {
        "dsm": False,
        'orthophoto-resolution': 0.0274,
        "ignore-gsd": True,
        "min-num-features": 350
    })
#task = n.create_task(images_name, {'orthophoto-resolution': 0.0274,"min-num-features":3500})
print("任务创建完成")
pbar = tqdm(total=100)
processing = 0
while True:
    info = task.info()
    if info.progress == 100:
        break
    pbar.update(info.progress - processing)
    processing = info.progress
    if info.last_error != '':
        print("error ", info.last_error)