Beispiel #1
0
def verify(args):
  payload = {
    transactino_constants.SCHEMA: {
      model_constants.MODELS: {
        model_constants.ACCOUNT: {
          method_constants.METHODS: {
            account_constants.VERIFY: {},
          },
        },
      },
    },
  }

  response = requests.post(
    settings.URL,
    headers=make_headers(),
    data=json.dumps(payload),
  )

  check_for_announcements(response)

  response_json = json.loads(response.text)
  verify_json = get_path(response_json, [
    transactino_constants.SCHEMA,
    model_constants.MODELS,
    model_constants.ACCOUNT,
    method_constants.METHODS,
    account_constants.VERIFY,
  ])

  print(json.dumps(verify_json, indent=2))
Beispiel #2
0
def get(args):
    payload = {
        transactino_constants.SCHEMA: {
            model_constants.MODELS: {
                model_constants.ANNOUNCEMENT: {
                    method_constants.METHODS: {
                        announcement_constants.GET: {},
                    },
                },
            },
        },
    }

    response = requests.post(
        settings.URL,
        headers=make_headers(),
        data=json.dumps(payload),
    )

    check_for_announcements(response)

    response_json = json.loads(response.text)
    instances_json = get_path(response_json, [
        transactino_constants.SCHEMA,
        model_constants.MODELS,
        model_constants.ANNOUNCEMENT,
        model_constants.INSTANCES,
    ])

    if instances_json is None:
        print(json.dumps(response_json, indent=2))
        return

    print(json.dumps(instances_json, indent=2))
Beispiel #3
0
def get(args):
    inactive = 'inactive' in args

    payload = {
        transactino_constants.SCHEMA: {
            model_constants.MODELS: {
                model_constants.SUBSCRIPTION: {
                    method_constants.METHODS: {
                        subscription_constants.GET: {
                            subscription_constants.IS_ACTIVE: not inactive,
                        },
                    },
                },
            },
        },
    }

    response = requests.post(
        settings.URL,
        headers=make_headers(),
        data=json.dumps(payload),
    )

    check_for_announcements(response)

    response_json = json.loads(response.text)
    instances_json = get_path(response_json, [
        transactino_constants.SCHEMA,
        model_constants.MODELS,
        model_constants.SUBSCRIPTION,
        model_constants.INSTANCES,
    ])

    print(json.dumps(instances_json, indent=2))
Beispiel #4
0
def create(args):
    print(
        'INFO: Run this method leaving arguments blank to generate a Challenge for this method'
    )
    create_args = input_args({
        subscription_constants.ACTIVATION_DATE: {
            method_constants.INPUT: 'Enter the activation date',
            method_constants.TYPE: str,
        },
        subscription_constants.DURATION_IN_DAYS: {
            method_constants.INPUT:
            'Enter the number of days the Subscription will be active',
            method_constants.TYPE: int,
        },
    })

    if subscription_constants.ACTIVATION_DATE in create_args:
        activation_date = create_args.get(
            subscription_constants.ACTIVATION_DATE)
        unaware_datetime = parser.parse(activation_date)
        aware_datetime = unaware_datetime.replace(tzinfo=tz.gettz())
        iso_datetime = aware_datetime.isoformat()

        create_args.update({
            subscription_constants.ACTIVATION_DATE:
            iso_datetime,
        })

    payload = {
        transactino_constants.SCHEMA: {
            model_constants.MODELS: {
                model_constants.SUBSCRIPTION: {
                    method_constants.METHODS: {
                        subscription_constants.CREATE: create_args,
                    },
                },
            },
        },
    }

    response = requests.post(
        settings.URL,
        headers=make_headers(),
        data=json.dumps(payload),
    )

    check_for_announcements(response)

    response_json = json.loads(response.text)
    create_json = get_path(response_json, [
        transactino_constants.SCHEMA,
        model_constants.MODELS,
        model_constants.SUBSCRIPTION,
        method_constants.METHODS,
        subscription_constants.CREATE,
    ])

    print(json.dumps(create_json, indent=2))
Beispiel #5
0
def compute_accuracy(threshold=117):
    # print(wb.sheetnames)
    # print(ws['A1'].value)
    correct = 0
    i = 0
    for filename in os.listdir(with_coloration_path):
        # print("Filename: ", filename)
        # print("Inside first for loop")
        i += 1
        im_path = with_coloration_path + filename
        predicted_path = get_path(cv2.imread(im_path), threshold)
        ws['A{}'.format(i + 1)] = filename
        ws['C{}'.format(i + 1)] = predicted_path
        correct_path = ws['B{}'.format(i + 1)].value
        if predicted_path == correct_path:
            ws['D{}'.format(i + 1)] = "Yes"
            correct += 1
        else:
            # pass
            ws['D{}'.format(i + 1)] = "No"

    for filename in os.listdir(without_coloration_path):
        # print("Inside second loop")
        i += 1
        im_path = without_coloration_path + filename
        predicted_path = get_path(
            cv2.imread(im_path),
            threshold)  # pass threshold as well to get_path()
        ws['A{}'.format(i + 1)] = filename
        ws['C{}'.format(i + 1)] = predicted_path
        correct_path = ws['B{}'.format(i + 1)].value
        if predicted_path == correct_path:
            ws['D{}'.format(i + 1)] = "Yes"
            correct += 1
        else:
            # pass
            ws['D{}'.format(i + 1)] = "No"

    accuracy = (correct / i) * 100
    # return accuracy

    wb.save(excel_path)
    print("Script complete and excel saved!")
    print("Path prediction Accuracy for threshold {}: {} ".format(
        threshold, accuracy))
Beispiel #6
0
def get(args):
    get_args = input_args({
        transaction_report_constants.TRANSACTION_REPORT_ID: {
            method_constants.INPUT:
            'Enter the TransactionReport ID or leave blank for all',
            method_constants.TYPE: str,
        },
        transaction_report_constants.IS_ACTIVE: {
            method_constants.INPUT:
            'Enter the active status of the TransactionReport',
            method_constants.TYPE: bool,
        },
    })

    payload = {
        transactino_constants.SCHEMA: {
            model_constants.MODELS: {
                model_constants.TRANSACTION_REPORT: {
                    method_constants.METHODS: {
                        transaction_report_constants.GET: get_args,
                    },
                },
            },
        },
    }

    response = requests.post(
        settings.URL,
        headers=make_headers(),
        data=json.dumps(payload),
    )

    check_for_announcements(response)

    response_json = json.loads(response.text)
    instances_json = get_path(response_json, [
        transactino_constants.SCHEMA,
        model_constants.MODELS,
        model_constants.TRANSACTION_REPORT,
        model_constants.INSTANCES,
    ])

    if not instances_json:
        print(json.dumps(response_json, indent=2))
        return

    print(json.dumps(instances_json, indent=2))
Beispiel #7
0
def create(args):
    print(
        'INFO: Run this method leaving arguments blank to generate a Challenge for this method'
    )
    create_args = input_args({
        fee_report_constants.BLOCKS_TO_INCLUDE: {
            method_constants.INPUT:
            'Enter the number of blocks to include in the FeeReport',
            method_constants.TYPE: int,
        },
    })

    if create_args:
        create_args.update({
            fee_report_constants.IS_ACTIVE: True,
        })

    payload = {
        transactino_constants.SCHEMA: {
            model_constants.MODELS: {
                model_constants.FEE_REPORT: {
                    method_constants.METHODS: {
                        method_constants.CREATE: create_args,
                    },
                },
            },
        },
    }

    response = requests.post(
        settings.URL,
        headers=make_headers(),
        data=json.dumps(payload),
    )

    check_for_announcements(response)

    response_json = json.loads(response.text)
    create_json = get_path(response_json, [
        transactino_constants.SCHEMA,
        model_constants.MODELS,
        model_constants.FEE_REPORT,
        method_constants.METHODS,
        method_constants.CREATE,
    ])

    print(json.dumps(create_json, indent=2))
Beispiel #8
0
def activate(args):
    activate_args = input_args({
        fee_report_constants.FEE_REPORT_ID: {
            method_constants.INPUT: 'Enter the FeeReport ID to activate',
            method_constants.TYPE: str,
        },
        fee_report_constants.IS_ACTIVE: {
            method_constants.INPUT:
            'Indicate whether the FeeReport should be active',
            method_constants.TYPE: bool,
        },
    })

    payload = {
        transactino_constants.SCHEMA: {
            model_constants.MODELS: {
                model_constants.FEE_REPORT: {
                    method_constants.METHODS: {
                        fee_report_constants.ACTIVATE: activate_args,
                    },
                },
            },
        },
    }

    response = requests.post(
        settings.URL,
        headers=make_headers(),
        data=json.dumps(payload),
    )

    check_for_announcements(response)

    response_json = json.loads(response.text)
    activate_json = get_path(response_json, [
        transactino_constants.SCHEMA,
        model_constants.MODELS,
        model_constants.FEE_REPORT,
        method_constants.METHODS,
        fee_report_constants.ACTIVATE,
    ])

    print(json.dumps(activate_json, indent=2))
Beispiel #9
0
def create(args):
  payload = {
    transactino_constants.SCHEMA: {
      model_constants.MODELS: {
        model_constants.ACCOUNT: {
          method_constants.METHODS: {
            account_constants.CREATE: {
              account_constants.PUBLIC_KEY: settings.PUBLIC_KEY,
            },
          },
        },
      },
    },
  }

  response = requests.post(
    settings.URL,
    headers=make_headers(),
    data=json.dumps(payload),
  )

  check_for_announcements(response)

  response_json = json.loads(response.text)
  create_json = get_path(response_json, [
    transactino_constants.SCHEMA,
    model_constants.MODELS,
    model_constants.ACCOUNT,
    method_constants.METHODS,
    account_constants.CREATE,
  ])

  if create_json is None:
    print('Account already exists.')
    return

  disclaimer = create_json.get(account_constants.DISCLAIMER)
  ip = create_json.get(account_constants.IP)
  long_key_id = create_json.get(account_constants.LONG_KEY_ID)

  print('The IP used to create this account: {}'.format(ip))
  print('The long key ID of your GPG public key: {}'.format(long_key_id))
  print('Disclaimer:\n\n{}'.format(disclaimer))
Beispiel #10
0
def create(args):
  print('INFO: Run this method leaving arguments blank to generate a Challenge for this method')
  create_args = input_args({
    ip_constants.VALUE: {
      method_constants.INPUT: 'Enter the value of the IP address',
      method_constants.TYPE: str,
    },
  })

  payload = {
    transactino_constants.SCHEMA: {
      model_constants.MODELS: {
        model_constants.IP: {
          method_constants.METHODS: {
            method_constants.CREATE: create_args,
          },
        },
      },
    },
  }

  response = requests.post(
    settings.URL,
    headers=make_headers(),
    data=json.dumps(payload),
  )

  check_for_announcements(response)

  response_json = json.loads(response.text)
  instances_json = get_path(response_json, [
    transactino_constants.SCHEMA,
    model_constants.MODELS,
    model_constants.IP,
    model_constants.INSTANCES,
  ])

  if not instances_json:
    print(json.dumps(response_json, indent=2))
    return

  print(json.dumps(instances_json, indent=2))
Beispiel #11
0
def get(args):
    get_args = input_args({
        ip_constants.IP_ID: {
            method_constants.INPUT:
            'Enter the IP address ID or leave blank for all',
            method_constants.TYPE: str,
        },
    })

    payload = {
        transactino_constants.SCHEMA: {
            model_constants.MODELS: {
                model_constants.IP: {
                    method_constants.METHODS: {
                        payment_constants.GET: get_args,
                    },
                },
            },
        },
    }

    response = requests.post(
        settings.URL,
        headers=make_headers(),
        data=json.dumps(payload),
    )

    check_for_announcements(response)

    response_json = json.loads(response.text)
    instances_json = get_path(response_json, [
        transactino_constants.SCHEMA,
        model_constants.MODELS,
        model_constants.IP,
        model_constants.INSTANCES,
    ])

    if not instances_json:
        print(json.dumps(response_json, indent=2))
        return

    print(json.dumps(instances_json, indent=2))
Beispiel #12
0
def get(args):
  get_args = input_args({
    address_constants.ADDRESS_ID: {
      method_constants.INPUT: 'Enter an Address ID',
      method_constants.TYPE: str,
    },
  })

  payload = {
    transactino_constants.SCHEMA: {
      model_constants.MODELS: {
        model_constants.ADDRESS: {
          method_constants.METHODS: {
            address_constants.GET: get_args,
          },
        },
      },
    },
  }

  response = requests.post(
    settings.URL,
    headers=make_headers(),
    data=json.dumps(payload),
  )

  check_for_announcements(response)

  response_json = json.loads(response.text)
  instances_json = get_path(response_json, [
    transactino_constants.SCHEMA,
    model_constants.MODELS,
    model_constants.ADDRESS,
    model_constants.INSTANCES,
  ])

  if instances_json is None:
    print(json.dumps(response_json, indent=2))
    return

  print(json.dumps(instances_json, indent=2))
Beispiel #13
0
def activate(args):
    activate_args = input_args({
        subscription_constants.SUBSCRIPTION_ID: {
            method_constants.INPUT: 'Enter the Subscription ID to activate',
            method_constants.TYPE: str,
        },
    })

    payload = {
        transactino_constants.SCHEMA: {
            model_constants.MODELS: {
                model_constants.SUBSCRIPTION: {
                    method_constants.METHODS: {
                        subscription_constants.ACTIVATE: activate_args,
                    },
                },
            },
        },
    }

    response = requests.post(
        settings.URL,
        headers=make_headers(),
        data=json.dumps(payload),
    )

    check_for_announcements(response)

    response_json = json.loads(response.text)
    activate_json = get_path(response_json, [
        transactino_constants.SCHEMA,
        model_constants.MODELS,
        model_constants.SUBSCRIPTION,
        method_constants.METHODS,
        subscription_constants.ACTIVATE,
    ])

    print(json.dumps(activate_json, indent=2))
Beispiel #14
0
def delete(args):
  delete_args = input_args({
    fee_report_constants.FEE_REPORT_ID: {
      method_constants.INPUT: 'Enter the FeeReport ID to delete',
      method_constants.TYPE: str,
    },
  })

  payload = {
    transactino_constants.SCHEMA: {
      model_constants.MODELS: {
        model_constants.FEE_REPORT: {
          method_constants.METHODS: {
            method_constants.DELETE: delete_args,
          },
        },
      },
    },
  }

  response = requests.post(
    settings.URL,
    headers=make_headers(),
    data=json.dumps(payload),
  )

  check_for_announcements(response)

  response_json = json.loads(response.text)
  delete_json = get_path(response_json, [
    transactino_constants.SCHEMA,
    model_constants.MODELS,
    model_constants.FEE_REPORT,
    method_constants.METHODS,
    method_constants.DELETE,
  ])

  print(json.dumps(delete_json, indent=2))
Beispiel #15
0
def dismiss(args):
  dismiss_args = input_args(get_config)

  payload = {
    transactino_constants.SCHEMA: {
      model_constants.MODELS: {
        model_constants.TRANSACTION_MATCH: {
          method_constants.METHODS: {
            transaction_match_constants.DISMISS: dismiss_args,
          },
        },
      },
    },
  }

  response = requests.post(
    settings.URL,
    headers=make_headers(),
    data=json.dumps(payload),
  )

  check_for_announcements(response)

  response_json = json.loads(response.text)
  dismiss_json = get_path(response_json, [
    transactino_constants.SCHEMA,
    model_constants.MODELS,
    model_constants.TRANSACTION_MATCH,
    method_constants.METHODS,
    transaction_match_constants.DISMISS,
  ])

  if dismiss_json is None:
    print(json.dumps(response_json, indent=2))
    return

  print(json.dumps(dismiss_json, indent=2))
Beispiel #16
0
def get(args):
    payload = {
        transactino_constants.SCHEMA: {
            model_constants.MODELS: {
                model_constants.SYSTEM: {
                    method_constants.METHODS: {
                        system_constants.GET: {},
                    },
                },
            },
        },
    }

    response = requests.post(
        settings.URL,
        headers=make_headers(),
        data=json.dumps(payload),
    )

    check_for_announcements(response)

    response_json = json.loads(response.text)
    instances_json = get_path(response_json, [
        transactino_constants.SCHEMA,
        model_constants.MODELS,
        model_constants.SYSTEM,
        model_constants.INSTANCES,
    ])

    if instances_json is None:
        print(json.dumps(response_json, indent=2))
        return

    for system_id, attributes_json in instances_json.items():
        print('System ID: ', system_id, '\n')

        public_key = get_path(attributes_json, [
            model_constants.ATTRIBUTES,
            system_constants.PUBLIC_KEY,
        ])

        print('PUBLIC KEY:')
        print(public_key + '\n')
        print('--------')

        guarantee = get_path(attributes_json, [
            model_constants.ATTRIBUTES,
            system_constants.GUARANTEE,
        ])

        print('GUARANTEE')
        print(guarantee + '\n')
        print('--------')

        guarantee_signature = get_path(attributes_json, [
            model_constants.ATTRIBUTES,
            system_constants.GUARANTEE_SIGNATURE,
        ])

        print('GUARANTEE SIGNATURE')
        print(guarantee_signature + '\n')
        print('--------')

        disclaimer = get_path(attributes_json, [
            model_constants.ATTRIBUTES,
            system_constants.DISCLAIMER,
        ])

        print('DISCLAIMER')
        print(disclaimer + '\n')
        print('--------')

        disclaimer_signature = get_path(attributes_json, [
            model_constants.ATTRIBUTES,
            system_constants.DISCLAIMER_SIGNATURE,
        ])

        print('DISCLAIMER SIGNATURE')
        print(disclaimer_signature + '\n')
        print('--------')
Beispiel #17
0
def tmqi_scores():
    i = 0
    for filename in os.listdir(with_coloration_path):
        i += 1
        gt_name = filename[:filename.find(
            '_')] + '.png'  # till the first occurence of underscore
        # print(gt_name)
        # print(gt_path + gt_name)
        gt_img = gt_path + gt_name
        im_path = with_coloration_path + filename
        inp_img = cv2.imread(im_path)
        predicted_path = get_path(inp_img, 117)  # threshold=117
        ws['A{}'.format(i + 1)] = filename
        # ws['B{}'.format(i + 1)] = compute_tmqi(gt_img, im_path)
        # dehazenet_image = dehazenet_coloration_path + '{}_finalWithoutCLAHE.jpg'.format(
        #     filename[:-4])
        # tmqi_dehaze = compute_tmqi(gt_img, dehazenet_image)
        # ws['C{}'.format(i + 1)] = tmqi_dehaze

        if predicted_path == 1:
            # equalized_img = dehazenet_coloration_path + '{}_Equalized.jpg'.format(
            #     filename[:-4])
            enh_path = enhanced_image_save_path + filename
            enhanced_img = cv2.imread(enhanced_image_save_path + filename)
            ws['D{}'.format(i + 1)] = compute_tmqi(gt_img, enh_path)
        else:
            ws['D{}'.format(i + 1)] = ws['C{}'.format(i + 1)].value

        # Comparison with raw input image scores
        if ws['D{}'.format(i + 1)].value > ws['B{}'.format(i + 1)].value:
            ws['E{}'.format(i + 1)] = "Yes"
        elif ws['D{}'.format(i + 1)].value < ws['B{}'.format(i + 1)].value:
            ws['E{}'.format(i + 1)] = "No"
        else:
            ws['E{}'.format(i + 1)] = "Equal"

        # Comparison with DehazeNet scores
        if ws['D{}'.format(i + 1)].value > ws['C{}'.format(i + 1)].value:
            ws['F{}'.format(i + 1)] = "Yes"
        elif ws['D{}'.format(i + 1)].value < ws['C{}'.format(i + 1)].value:
            ws['F{}'.format(i + 1)] = "No"
        else:
            ws['F{}'.format(i + 1)] = "Equal"

        print("TMQI computed for: ", filename)

    for filename in os.listdir(without_coloration_path):
        i += 1
        gt_name = filename[:filename.find(
            '_')] + '.png'  # till the first occurence of underscore
        gt_img = gt_path + gt_name
        im_path = without_coloration_path + filename
        inp_img = cv2.imread(im_path)
        predicted_path = get_path(inp_img, 117)  # threshold=117
        ws['A{}'.format(i + 1)] = filename
        # ws['B{}'.format(i + 1)] = compute_tmqi(im_path, gt_img)
        # dehazenet_image = dehazenet_without_coloration_path + '{}_finalWithoutCLAHE.jpg'.format(
        #     filename[:-4])
        # tmqi_dehaze = compute_tmqi(dehazenet_image, gt_img)
        # ws['C{}'.format(i + 1)] = tmqi_dehaze

        if predicted_path == 1:
            # equalized_img = dehazenet_without_coloration_path + '{}_Equalized.jpg'.format(
            #     filename[:-4])
            enh_path = enhanced_image_save_path + filename
            enhanced_img = cv2.imread(enhanced_image_save_path + filename)
            ws['D{}'.format(i + 1)] = compute_tmqi(gt_img, enh_path)
        else:
            ws['D{}'.format(i + 1)] = ws['C{}'.format(i + 1)].value

        # Comparison with raw input image scores
        if ws['D{}'.format(i + 1)].value > ws['B{}'.format(i + 1)].value:
            ws['E{}'.format(i + 1)] = "Yes"
        elif ws['D{}'.format(i + 1)].value < ws['B{}'.format(i + 1)].value:
            ws['E{}'.format(i + 1)] = "No"
        else:
            ws['E{}'.format(i + 1)] = "Equal"

        # Comparison with DehazeNet scores
        if ws['D{}'.format(i + 1)].value > ws['C{}'.format(i + 1)].value:
            ws['F{}'.format(i + 1)] = "Yes"
        elif ws['D{}'.format(i + 1)].value < ws['C{}'.format(i + 1)].value:
            ws['F{}'.format(i + 1)] = "No"
        else:
            ws['F{}'.format(i + 1)] = "Equal"

        print("TMQI computed for: ", filename)

    wb.save(excel_path)
    print("Script complete and excel saved!")
Beispiel #18
0
def get(args):
    closed = 'closed' in args
    save = 'save' in args

    get_args = input_args({
        challenge_constants.CHALLENGE_ID: {
            method_constants.INPUT:
            'Enter the Challenge ID or leave blank for all',
            method_constants.TYPE: str,
        },
    })

    get_args.update({
        challenge_constants.IS_OPEN: not closed,
    })

    payload = {
        transactino_constants.SCHEMA: {
            model_constants.MODELS: {
                model_constants.CHALLENGE: {
                    method_constants.METHODS: {
                        challenge_constants.GET: get_args,
                    },
                },
            },
        },
    }

    response = requests.post(
        settings.URL,
        headers=make_headers(),
        data=json.dumps(payload),
    )

    check_for_announcements(response)

    response_json = json.loads(response.text)
    instances_json = get_path(response_json, [
        transactino_constants.SCHEMA,
        model_constants.MODELS,
        model_constants.CHALLENGE,
        model_constants.INSTANCES,
    ])

    if instances_json is None:
        print(json.dumps(response_json, indent=2))
        return

    for challenge_id, attributes_json in instances_json.items():
        print('Challenge ID: ', challenge_id, '\n')
        encrypted_content = get_path(attributes_json, [
            model_constants.ATTRIBUTES,
            challenge_constants.ENCRYPTED_CONTENT,
        ])
        print(encrypted_content + '\n')

        if save:
            if not exists(settings.CHALLENGE_PATH):
                os.mkdir(settings.CHALLENGE_PATH)

            challenge_path = join(settings.CHALLENGE_PATH, challenge_id)
            if not exists(challenge_path):
                os.mkdir(challenge_path)

            message_path = join(challenge_path, 'message.asc')
            if not exists(message_path):
                with open(message_path, 'w') as message_file:
                    message_file.write(encrypted_content)
Beispiel #19
0
def respond(args):
    read = 'read' in args

    respond_args = input_args({
        challenge_constants.CHALLENGE_ID: {
            method_constants.INPUT: 'Enter the Challenge ID to respond to',
            method_constants.TYPE: str,
        },
    })

    if not read:
        content = input((
            'Please enter the decrypted string that has been'
            ' re-encrypted to the public key of the System model.'
            ' It should be in ASCII armor format with any newlines'
            ' replaced with their escaped equivalents (\\n). This is'
            ' for the purposes of pasting the text into the command line: \n\n'
        ), )

    if read:
        challenge_id = respond_args.get(challenge_constants.CHALLENGE_ID)
        challenge_path = join(settings.CHALLENGE_PATH, challenge_id)
        if not exists(challenge_path):
            print('Cannot find saved challenge directory...')
            return

        encrypted_content_path = join(challenge_path, 'encrypted.asc')
        if not exists(encrypted_content_path):
            print('Cannot find file {}/encrypted.asc'.format(challenge_id))
            return

        with open(encrypted_content_path, 'r') as encrypted_content_file:
            content = encrypted_content_file.read()

    respond_args.update({
        challenge_constants.CONTENT: content,
    })

    payload = {
        transactino_constants.SCHEMA: {
            model_constants.MODELS: {
                model_constants.CHALLENGE: {
                    method_constants.METHODS: {
                        challenge_constants.RESPOND: respond_args,
                    },
                },
            },
        },
    }

    response = requests.post(
        settings.URL,
        headers=make_headers(),
        data=json.dumps(payload),
    )

    check_for_announcements(response)

    response_json = json.loads(response.text)
    respond_json = get_path(response_json, [
        transactino_constants.SCHEMA,
        model_constants.MODELS,
        model_constants.CHALLENGE,
        method_constants.METHODS,
        challenge_constants.RESPOND,
    ])

    print(json.dumps(respond_json, indent=2))
Beispiel #20
0
def ssim_scores():
    i = 0
    for filename in os.listdir(with_coloration_path):
        i += 1
        gt_name = filename[:filename.find(
            '_')] + '.png'  # till the first occurence of underscore
        # print(gt_name)
        # print(gt_path + gt_name)
        gt_img = cv2.imread(gt_path + gt_name)
        im_path = with_coloration_path + filename
        inp_img = cv2.imread(im_path)
        predicted_path = get_path(inp_img, 117)  # threshold=117
        ws['A{}'.format(i + 1)] = filename
        ws['B{}'.format(i + 1)] = structural_similarity(gt_img,
                                                        inp_img,
                                                        multichannel=True)
        dehazenet_image = cv2.imread(
            dehazenet_coloration_path +
            '{}_finalWithoutCLAHE.jpg'.format(filename[:-4]))
        ssim_dehaze = structural_similarity(gt_img,
                                            dehazenet_image,
                                            multichannel=True)
        ws['C{}'.format(i + 1)] = ssim_dehaze

        if predicted_path == 1:
            ws['D{}'.format(i + 1)] = structural_similarity(
                gt_img,
                apply_CLAHE(adaptive_enhance(inp_img)),
                multichannel=True)
        else:
            ws['D{}'.format(i + 1)] = ssim_dehaze

        # Comparison with raw input image scores
        if ws['D{}'.format(i + 1)].value > ws['B{}'.format(i + 1)].value:
            ws['E{}'.format(i + 1)] = "Yes"
        elif ws['D{}'.format(i + 1)].value < ws['B{}'.format(i + 1)].value:
            ws['E{}'.format(i + 1)] = "No"
        else:
            ws['E{}'.format(i + 1)] = "Equal"

        # Comparison with DehazeNet scores
        if ws['D{}'.format(i + 1)].value > ws['C{}'.format(i + 1)].value:
            ws['F{}'.format(i + 1)] = "Yes"
        elif ws['D{}'.format(i + 1)].value < ws['C{}'.format(i + 1)].value:
            ws['F{}'.format(i + 1)] = "No"
        else:
            ws['F{}'.format(i + 1)] = "Equal"

        print("SSIM computed for: ", filename)

    for filename in os.listdir(without_coloration_path):
        i += 1
        gt_name = filename[:filename.find(
            '_')] + '.png'  # till the first occurence of underscore
        gt_img = cv2.imread(gt_path + gt_name)
        im_path = without_coloration_path + filename
        inp_img = cv2.imread(im_path)
        predicted_path = get_path(inp_img, 117)  # threshold=117
        ws['A{}'.format(i + 1)] = filename
        ws['B{}'.format(i + 1)] = structural_similarity(gt_img,
                                                        inp_img,
                                                        multichannel=True)
        dehazenet_image = cv2.imread(
            dehazenet_without_coloration_path +
            '{}_finalWithoutCLAHE.jpg'.format(filename[:-4]))
        ssim_dehaze = structural_similarity(gt_img,
                                            dehazenet_image,
                                            multichannel=True)
        ws['C{}'.format(i + 1)] = ssim_dehaze

        if predicted_path == 1:
            ws['D{}'.format(i + 1)] = structural_similarity(
                gt_img,
                apply_CLAHE(adaptive_enhance(inp_img)),
                multichannel=True)
        else:
            ws['D{}'.format(i + 1)] = ssim_dehaze

        # Comparison with raw input image scores
        if ws['D{}'.format(i + 1)].value > ws['B{}'.format(i + 1)].value:
            ws['E{}'.format(i + 1)] = "Yes"
        elif ws['D{}'.format(i + 1)].value < ws['B{}'.format(i + 1)].value:
            ws['E{}'.format(i + 1)] = "No"
        else:
            ws['E{}'.format(i + 1)] = "Equal"

        # Comparison with DehazeNet scores
        if ws['D{}'.format(i + 1)].value > ws['C{}'.format(i + 1)].value:
            ws['F{}'.format(i + 1)] = "Yes"
        elif ws['D{}'.format(i + 1)].value < ws['C{}'.format(i + 1)].value:
            ws['F{}'.format(i + 1)] = "No"
        else:
            ws['F{}'.format(i + 1)] = "Equal"

        print("SSIM computed for: ", filename)

    wb.save(excel_path)
    print("Script complete and excel saved!")
    I = src / 255.0
    dark = DarkChannel(I, 15)
    A = AtmLight(I, dark)
    te = TransmissionEstimate(im_path, height, width)
    t = TransmissionRefine(src, te)
    J = Recover(I, t, A, 0.1)
    dehazed_image = J * 255
    return dehazed_image


if __name__ == '__main__':
    if not len(sys.argv) == 2:
        print('Usage: python DeHazeNet.py haze_img_path')
        exit()
    else:
        im_path = sys.argv[1]
    src = cv2.imread(im_path)
    path = get_path(src, threshold=137)
    if path == 1:
        dehazed_image = apply_CLAHE(src)
    else:
        dehazed_image = dehaze_image(src, im_path)
        # cv2.imshow('TransmissionEstimate', te)
        # cv2.imshow('TransmissionRefine', t)
        # cv2.imshow('Origin', src)
        # cv2.imshow('Dehaze', J)
        # cv2.waitKey(0)
    save_path = im_path[:-4] + '_Dehaze' + im_path[-4:len(im_path)]
    cv2.imwrite(save_path, dehazed_image)
    print("Dehazed image saved!")
Beispiel #22
0
def create(args):
    print(
        'INFO: Run this method leaving arguments blank to generate a Challenge for this method'
    )
    create_args = input_args({
        transaction_report_constants.TARGET_ADDRESS: {
            method_constants.INPUT: 'Enter the target address',
            method_constants.TYPE: str,
        },
        transaction_report_constants.VALUE_EQUAL_TO: {
            method_constants.INPUT:
            'Enter value to match equal (leave blank if not required)',
            method_constants.TYPE: int,
        },
        transaction_report_constants.VALUE_LESS_THAN: {
            method_constants.INPUT:
            'Enter maximum value (leave blank if not required)',
            method_constants.TYPE: int,
        },
        transaction_report_constants.VALUE_GREATER_THAN: {
            method_constants.INPUT:
            'Enter minimum value (leave blank if not required)',
            method_constants.TYPE: int,
        },
    })

    if create_args:
        create_args.update({
            transaction_report_constants.IS_ACTIVE: True,
        })

    payload = {
        transactino_constants.SCHEMA: {
            model_constants.MODELS: {
                model_constants.TRANSACTION_REPORT: {
                    method_constants.METHODS: {
                        transaction_report_constants.CREATE: create_args,
                    },
                },
            },
        },
    }

    response = requests.post(
        settings.URL,
        headers=make_headers(),
        data=json.dumps(payload),
    )

    check_for_announcements(response)

    response_json = json.loads(response.text)
    create_json = get_path(response_json, [
        transactino_constants.SCHEMA,
        model_constants.MODELS,
        model_constants.TRANSACTION_REPORT,
        method_constants.METHODS,
        transaction_report_constants.CREATE,
    ])

    print(json.dumps(create_json, indent=2))
Beispiel #23
0
def fade_scores():
    i = 0
    for filename in os.listdir(with_coloration_path):
        # print("Filename: ", filename)
        # print("Inside first for loop")
        i += 1
        im_path = with_coloration_path + filename
        inp_img = cv2.imread(im_path)
        fade_inp_img = compute_fade(inp_img)
        predicted_path = get_path(inp_img, 117)  # threshold=117
        ws['A{}'.format(i + 1)] = filename
        ws['B{}'.format(i + 1)] = fade_inp_img
        dehazenet_image = cv2.imread(
            dehazenet_coloration_path +
            '{}_finalWithoutCLAHE.jpg'.format(filename[:-4]))
        fade_dehazenet = compute_fade(dehazenet_image)
        ws['C{}'.format(i + 1)] = fade_dehazenet

        if predicted_path == 1:
            enhanced_img = apply_CLAHE(adaptive_enhance(inp_img))
            ws['D{}'.format(i + 1)] = compute_fade(enhanced_img)
        else:
            ws['D{}'.format(i + 1)] = fade_dehazenet

        # Comparison with raw input image scores
        # In FADE, lesser score is better
        if ws['D{}'.format(i + 1)].value < ws['B{}'.format(i + 1)].value:
            ws['E{}'.format(i + 1)] = "Yes"
        elif ws['D{}'.format(i + 1)].value > ws['B{}'.format(i + 1)].value:
            ws['E{}'.format(i + 1)] = "No"
        else:
            ws['E{}'.format(i + 1)] = "Equal"

        # Comparison with DehazeNet scores
        if ws['D{}'.format(i + 1)].value < ws['C{}'.format(i + 1)].value:
            ws['F{}'.format(i + 1)] = "Yes"
        elif ws['D{}'.format(i + 1)].value > ws['C{}'.format(i + 1)].value:
            ws['F{}'.format(i + 1)] = "No"
        else:
            ws['F{}'.format(i + 1)] = "Equal"
            # ws['D{}'.format(i + 1)] = niqe(dehaze_image(inp_img, im_path))
            # ws['C{}'.format(i + 1)] = ws['D{}'.format(i + 1)].value

        print("FADE computed for: ", filename)

    for filename in os.listdir(without_coloration_path):
        # print("Filename: ", filename)
        # print("Inside first for loop")
        i += 1
        im_path = without_coloration_path + filename
        inp_img = cv2.imread(im_path)
        fade_inp_img = compute_fade(inp_img)
        predicted_path = get_path(inp_img, 117)  # threshold=117
        ws['A{}'.format(i + 1)] = filename
        ws['B{}'.format(i + 1)] = fade_inp_img
        dehazenet_image = cv2.imread(
            dehazenet_without_coloration_path +
            '{}_finalWithoutCLAHE.jpg'.format(filename[:-4]))
        fade_dehazenet = compute_fade(dehazenet_image)
        ws['C{}'.format(i + 1)] = fade_dehazenet

        if predicted_path == 1:
            enhanced_img = apply_CLAHE(adaptive_enhance(inp_img))
            ws['D{}'.format(i + 1)] = compute_fade(enhanced_img)
        else:
            ws['D{}'.format(i + 1)] = fade_dehazenet

        # Comparison with raw input image scores
        if ws['D{}'.format(i + 1)].value < ws['B{}'.format(i + 1)].value:
            ws['E{}'.format(i + 1)] = "Yes"
        elif ws['D{}'.format(i + 1)].value > ws['B{}'.format(i + 1)].value:
            ws['E{}'.format(i + 1)] = "No"
        else:
            ws['E{}'.format(i + 1)] = "Equal"

        # Comparison with DehazeNet scores
        if ws['D{}'.format(i + 1)].value < ws['C{}'.format(i + 1)].value:
            ws['F{}'.format(i + 1)] = "Yes"
        elif ws['D{}'.format(i + 1)].value > ws['C{}'.format(i + 1)].value:
            ws['F{}'.format(i + 1)] = "No"
        else:
            ws['F{}'.format(i + 1)] = "Equal"

            # op_img = dehaze_image(inp_img, im_path)
            # niqe_score = niqe(op_img)
            # ws['D{}'.format(i + 1)] = niqe_score
            # ws['C{}'.format(i + 1)] = ws['D{}'.format(i + 1)].value
        print("FADE computed for: ", filename)

    wb.save(excel_path)
    print("Script complete and excel saved!")