Exemplo n.º 1
0
def connect_mongodb_database(host, port, database, username, password):
    """
    Connect to the given MongoDB-database.

    Parameters
    ----------
    - host -- The host where MongoDB is running.
    - port -- The port on which MongoDB listens.
    - database -- The database to connect to.

    Returns
    -------
    A reference to the requested database.
    """
    logger = get_root_logger()
    try:
        logger.info('Connecting to MongoDB...')
        # Connect to MongoDB (max. wait 5s for connection to be established)
        url = f'mongodb://{username}:{password}@{host}:{port}/{database}?authSource=admin&authMechanism=SCRAM-SHA-1'
        mongo_client = MongoClient(url, serverSelectionTimeoutMS=5000)

        # request a roundtrip to server because the connection is lazy
        mongo_client.server_info()
        logger.info('Connected to MongoDB on {}:{}/{}'.format(
            host, port, database))

        # Get the requested database from the url
        return mongo_client.get_database()
    except ServerSelectionTimeoutError as err:
        logger.critical(
            'PyMongo could not connect to the database with url {}'.format(
                url))
Exemplo n.º 2
0
def save_features():
    logger = get_root_logger()
    filenames = glob('./datasets/images/dataset_pictures_msk/zaal_*/*.jpg')
    total = len(filenames)
    count = 0

    for path in filenames:
        image = cv2.imread(path)
        filename = basename(path)
        count += 1
        paintings_in_image = get_paintings_for_image(filename)

        for painting in paintings_in_image:
            logger.info('Extracting features of image with id {}'.format(
                painting.get('_id')))
            full_histogram, block_histogram, LBP_histogram = extract_features(
                image, painting.get('corners'), False)

            update_by_id(
                painting.get('_id'), {
                    '$set': {
                        'full_histogram': pickle_serialize(full_histogram),
                        'block_histogram': pickle_serialize(block_histogram),
                        'LBP_histogram': pickle_serialize(LBP_histogram)
                    }
                })

        logger.info(f'{count}/{total} images processed')
Exemplo n.º 3
0
    def __init__(self, processes_to_watch=[]):
        """
        Create a watch for sudden exits of the given processes. This will kill
        all other process in the list as well as the parent process.

        Parameters
        ----------
        - processes_to_watch -- The processes to start and watch for unexpected termination.
        - on_kill -- The function to call when the process is killed.
        """
        self._logger = get_root_logger()
        self._processes = processes_to_watch
        self._pids = []

        # attach the kill signal to listen for
        signal.signal(signal.SIGINT, self.exit_gracefully)
        signal.signal(signal.SIGTERM, self.exit_gracefully)

        # start the child processes
        self.start_processes()
Exemplo n.º 4
0
pyximport.install(language_level='3')

import cv2
from glob import glob
import re
import os
import pickle
import json

from core.logger import get_root_logger
from data.imageRepo import get_all_images, get_painting_count_by_room
from core.detection import detect_quadrilaterals
from core.visualize import resize_image
from core.prediction import predict_room

logger = get_root_logger()


def run_room_calibration():
  filenames = glob('./datasets/images/dataset_pictures_msk/zaal_*/*.jpg')

  probability_per_room = {} # key -> room, value -> count & average probability for the room

  for f in filenames:
    original_image = cv2.imread(f, 1)
    resized_image = resize_image(original_image, 0.2)
    image = resized_image.copy()
    detected_paintings = detect_quadrilaterals(image)

    probabilities = predict_room(resized_image, detected_paintings, 0.5)