Esempio n. 1
0
    def __get_i18n_hash__(self):
        cache_key = "astrobin_i18n_hash"
        digest = cache.get(cache_key)
        if digest is not None:
            return digest

        hashes = []  # type: List[str]
        project_root = get_project_root()  # type: str

        for language in [x[0] for x in settings.LANGUAGES]:  # type: str
            for app in ['astrobin'] + settings.ASTROBIN_APPS:  # type: str
                po_file = join(project_root, app, 'locale', language,
                               'LC_MESSAGES', 'django.po')  # type: str

                if not os.path.exists(po_file):
                    continue

                language_app_md5 = hashlib.md5()
                try:
                    with open(po_file, "rb") as f:
                        for chunk in read_in_chunks(f, 4096):
                            language_app_md5.update(chunk)
                    hashes.append(language_app_md5.hexdigest())
                except IOError as e:
                    log.error('IOError while reading PO file %s: %s' %
                              (po_file, str(e)))
                    continue

        total_md5 = hashlib.md5()
        total_md5.update(str(hashes).encode('utf-8'))
        digest = total_md5.hexdigest()

        cache.set(cache_key, digest, 3600)

        return digest
Esempio n. 2
0
    def get(self, request, *args, **kwargs):
        code = kwargs.pop('code', 'en')  # type: str

        if code not in [x[0] for x in settings.LANGUAGES]:
            code = 'en'

        if code == 'zh-hans':
            code = 'zh_Hans'

        cache_key = "astrobin_i18n_messages_%s" % code
        content = cache.get(cache_key)
        if content is not None:
            return HttpResponse(content)

        project_root = get_project_root()  # type: str

        content = ''

        for app in ['astrobin'] + settings.ASTROBIN_APPS:
            po_file = join(project_root, app, 'locale', code, 'LC_MESSAGES',
                           'django.po')  # type: str

            try:
                with open(po_file, 'r') as f:
                    for i, line in enumerate(f):
                        if not line.startswith('#'):
                            content += line
            except IOError:
                continue

        cache.set(cache_key, content, 3600)

        return HttpResponse(content)
Esempio n. 3
0
    def blur_results(self):
        root = utils.get_project_root()
        video_name = os.path.basename(os.path.dirname(self.frames_raw))
        os.makedirs(os.path.join(str(root), 'data', 'files', video_name),
                    exist_ok=True)

        blurry_list = []
        blurry_dict = {}
        for t in self.variance_list:
            if t < self.threshold:
                blurry_list.append(self.variance_list.index(t))
                blurry_dict[str(self.variance_list.index(t))] = 'blur'
            else:
                blurry_dict[str(self.variance_list.index(t))] = 'no_blur'
        progressbar_dict = utils.progress_bar_subroutine(
            blurry_dict, len(self.variance_list))
        data = {
            'name':
            video_name,
            'blur_images':
            blurry_dict,
            'blur_percentage':
            str(round(len(blurry_list) / len(self.variance_list) * 100)) +
            ' % ',
            'focused_percentage':
            str(100 - round(len(blurry_list) / len(self.variance_list) * 100))
            + ' % ',
            'total_images':
            str(len(self.variance_list)),
            'progress_bar':
            progressbar_dict,
            'type':
            'blur'
        }
        aws_manager.dynamo_upload(data)
Esempio n. 4
0
    def __get_i18n_hash__(self):
        cache_key = "astrobin_i18n_hash"
        digest = cache.get(cache_key)
        if digest is not None:
            return digest

        hashes = []  # type: List[str]
        project_root = get_project_root()  # type: str

        for language in [x[0] for x in settings.LANGUAGES]:  # type: str
            for app in ['astrobin'] + settings.ASTROBIN_APPS:  # type: str
                po_file = join(project_root, app, 'locale', language,
                               'LC_MESSAGES', 'django.po')  # type: str
                language_app_md5 = hashlib.md5()
                try:
                    with open(po_file, "r") as f:
                        for chunk in iter(lambda: f.read(4096), b""):
                            language_app_md5.update(chunk)
                    hashes.append(language_app_md5.hexdigest())
                except IOError:
                    continue

        total_md5 = hashlib.md5()
        total_md5.update(str(hashes))
        digest = total_md5.hexdigest()

        cache.set(cache_key, digest, 3600)

        return digest
Esempio n. 5
0
    def __get_version__(self):
        # type: () -> str
        version_file = join(get_project_root(), 'VERSION')  # type: str

        f = open(version_file, 'r')  # type: BinaryIO
        version = f.read().strip()  # type: str
        f.close()

        return version
Esempio n. 6
0
def main():
    root = utils.get_project_root()
    videos_folder = os.path.join(str(root), 'data', 'videos', 'chosen_videos',
                                 'for_testing')
    frames_folder = os.path.join(str(root), 'data', 'frames')
    frames_creator = FramesCreator(videos_folder,
                                   frames_folder,
                                   fps=1,
                                   crop=True)
    frames_creator.get_frame()
Esempio n. 7
0
def main():
    root = utils.get_project_root()
    frames_raw = os.path.join(str(root), 'data', 'frames', 'a_video_for_test',
                              'raw')
    frames_res = os.path.join(str(root), 'data', 'frames', 'a_video_for_test',
                              'res')
    color_detector = ColorDetector(frames_raw, frames_res)
    # HSV values
    yellow_low = [18, 25, 25]
    yellow_high = [30, 255, 255]
    color_detector.detect_yellow(yellow_low, yellow_high)
Esempio n. 8
0
def plot_list(l, video_name, plot_name):
    root = utils.get_project_root()
    plt.figure()
    x = np.arange(0, len(l), 1)
    plt.xticks(np.arange(0, len(l), step=2))
    plt.plot(x,
             l,
             color='green',
             linestyle='dashed',
             linewidth=3,
             marker='o',
             markerfacecolor='blue',
             markersize=8)
    for x, y in zip(x, l):
        plt.text(x, y, str(x), color="red", fontsize=6)
    plt.grid()
    os.makedirs(os.path.join(str(root), 'data', 'files', video_name),
                exist_ok=True)
    plt.savefig(
        os.path.join(str(root), 'data', 'files', video_name,
                     plot_name + '.png'))
def __get_driver_path(executable) -> Path:
    root = get_project_root()
    if system().lower() == 'windows':
        executable += __WIN_EXTENSION
    return root.joinpath(__DRIVER_DIR, executable)
Esempio n. 10
0
import cv2
import circle_fit as cf
from matplotlib import pyplot as plt
import numpy as np
from PIL import Image
import os
import common.utils as utils
import src.color_detection as cd

root = utils.get_project_root()


class Images:
    def __init__(self, video_name):
        self.res_image_folder_name = os.path.join(str(root), 'data', 'frames', video_name, 'res')
        self.image_folder_name = os.path.join(str(root), 'data', 'frames', video_name, 'raw')
        self.scatter_image_folder_name = os.path.join(str(root), 'data', 'frames', video_name, 'scatter')
        self.circle_image_folder_name = os.path.join(str(root), 'data', 'frames', video_name, 'circles')

    pixel_value = 20


class ScatterImages(Images):
    scatter_image_folder_name = str()
    black_pixels_position = list()

    @staticmethod
    def get_bright_and_dark_pixels(grayscale_image_array, pixel_value):  # Returns the bright and the dark pixels
        indices_bright = np.where(grayscale_image_array >= pixel_value)
        index_array_x = indices_bright[1]
        index_array_y = indices_bright[0]
Esempio n. 11
0
def main(video, **kwargs):
    start_time = time.time()
    blur_is_enabled = kwargs.get('blur', False)
    variance_is_enabled = kwargs.get('variance', False)
    circles_is_enabled = kwargs.get('circles', False)
    root = utils.get_project_root()
    frames_folder = os.path.join(str(root), 'data', 'frames')
    frames_creator = video_to_frames.FramesCreator(video,
                                                   frames_folder,
                                                   fps=1,
                                                   crop=True)
    frames_creator.get_frame()
    video_name_no_extension, video_name_extension = os.path.splitext(video)
    frames_raw = os.path.join(str(root), 'data', 'frames',
                              video_name_no_extension, 'raw')
    frames_res = os.path.join(str(root), 'data', 'frames',
                              video_name_no_extension, 'res')

    if blur_is_enabled or variance_is_enabled:
        color_detector = color_detection.ColorDetector(frames_raw, frames_res)
        # HSV values
        yellow_low = [18, 25, 25]
        yellow_high = [30, 255, 255]
        color_detector.detect_yellow(yellow_low, yellow_high)

    if blur_is_enabled:
        frames_blur = os.path.join(str(root), 'data', 'frames',
                                   video_name_no_extension, 'blur')
        blur_detector = blur.BlurDetector(frames_raw, frames_blur)
        blur_detector.calculate_laplacian()
        blur_detector.blur_results()

    # Identify pixels
    if variance_is_enabled:
        variance_index = 0
        for image_name, image_directory in utils.folder_reader(frames_raw):
            variance_index += 1
            image_name_path = os.path.join(image_directory, image_name)
            variance_image = identify_pixels.Variance(image_name_path)
            variance_image.create_grayscale_from_rgb()
            variance_image.get_bright_and_dark_pixels()
            variance_image.calculate_variance()
            csv = identify_pixels.WritingCSV(image_name_path)
            csv.write_plot_data_2_csv(variance_index)

    # Identify circles
    if circles_is_enabled:
        yellow_low = [14, 25, 25]
        yellow_high = [30, 255, 255]
        scatter_images = identify_circles.ScatterImages(
            video_name_no_extension)
        scatter_images.get_res(yellow_low, yellow_high)
        scatter_images.get_scatter_plot()
        edge_detection = identify_circles.EdgeDetection(
            video_name_no_extension)
        edge_detection.get_edges()
        circle_pos = identify_circles.CirclePosition(video_name_no_extension)
        circle_pos.get_valid_radii()
        circle_pos.count_pixels_in_circle()
        circle_pos.plot_circles_on_raw_image()
        identify_circles.CirclePosition.features_selected_circle = list()

    print("Main program took", round(time.time() - start_time, 2),
          "seconds to run")