Exemple #1
0
    def main(self, mex_url=None, bisque_token=None, bq=None):
        #  Allow for testing by passing an alreay initialized session
        if bq is None:
            bq = BQSession().init_mex(mex_url, bisque_token)
        pars = bq.parameters()
        image_url = pars.get('dataset_url', None)
        annotation_type = pars.get('annotation_type', None)
        annotation_attribute = pars.get('annotation_attribute', None)
        value_old = pars.get('value_old', None)

        bq.update_mex('Starting')
        mex_id = mex_url.split('/')[-1]
        if image_url is None or len(image_url) < 2:
            datasets = bq.fetchxml('/data_service/dataset')
            datasets = [d.get('uri') for d in datasets.xpath('dataset')]
        else:
            datasets = [image_url]
        total = 0
        changes = []

        # delete annotations for each element in the dataset
        for ds_url in datasets:
            dataset = bq.fetchxml(ds_url, view='deep')
            dataset_name = dataset.get('name')
            bq.update_mex('processing "%s"' % dataset_name)

            refs = dataset.xpath('value[@type="object"]')
            for r in refs:
                url = r.text
                image = bq.fetchxml(url, view='deep')
                uuid = image.get('resource_uniq')
                modified = delete(image,
                                  value_old,
                                  ann_type=annotation_type,
                                  ann_attr=annotation_attribute)
                if len(modified) > 0:
                    bq.postxml(url, image, method='PUT')
                    total = total + len(modified)
                    changes.append({
                        'name':
                        '%s (%s)' %
                        (image.get('name'), image.get('resource_uniq')),
                        'value':
                        '%s' % len(modified)
                    })

        changes.insert(0, {'name': 'Total', 'value': '%s' % total})
        bq.finish_mex(tags=[{
            'name': 'outputs',
            'tag': [{
                'name': 'deleted',
                'tag': changes,
            }]
        }])
Exemple #2
0
    def main(self, mex_url=None, bisque_token=None, image_url=None, bq=None):
        #  Allow for testing by passing an alreay initialized session
        if bq is None:
            bq = BQSession().init_mex(mex_url, bisque_token)

        bq.update_mex('Classifying...')
        pars = bq.parameters()
        image_url = pars.get('data_url', None)
        model_url = pars.get('model_url', None)
        store_on_image = pars.get('store_on_image', False)
        method = pars.get('method', 'points')

        points = int(pars.get('number_of_points', 10))
        confidence = int(pars.get('confidence', 95))
        border = int(pars.get('border', 0))

        _, image_uniq = image_url.rsplit('/', 1)
        _, model_uniq = model_url.rsplit('/', 1)
        url = '%s/connoisseur/%s/classify:%s/method:%s/points:%s/confidence:%s/border:%s' % (
            bq.bisque_root, model_uniq, image_uniq, method, points, confidence,
            border)

        # dima: the moving of the image is not of the best taste, this should be changed later
        if method != 'segmentation':
            url += '/format:xml'
            txt = bq.c.fetch(url,
                             headers={
                                 'Content-Type': 'text/xml',
                                 'Accept': 'text/xml'
                             })
            gobs = etree.fromstring(txt)
        else:
            color_mode = 'colors'
            url += '/colors:colors'
            filename = '%s_%s_conf%.2f_n%s_b%s.png' % (
                image_uniq, color_mode, confidence, points, border)
            filename = bq.c.fetch(url, path=filename)
            image_url = upload_file(bq, filename) or ''
            gobs = None

        bq.update_mex('Storing results...')
        outputs = etree.Element('tag', name="outputs")
        img = etree.SubElement(outputs,
                               'tag',
                               name="MyImage",
                               type="image",
                               value=image_url)
        if gobs is not None:
            img.append(gobs)
        if store_on_image is True:
            r = bq.postxml(image_url, xml=txt)

        bq.finish_mex(tags=[outputs])