Ejemplo n.º 1
0
def main():
    vid = (Path(__file__).parent / 'test.mp4').absolute()
    stream = FileVideoStream(str(vid), queue_size=100).start()
    time.sleep(1)

    while stream.more():
        img_data = stream.read()
        if img_data is None:
            break
        img = Image(img_data)
        transformed = Transformer(img)
        image = transformed.cannify()
        cropped_img = region(image)
        lines = cv2.HoughLinesP(cropped_img.raw,
                                2,
                                np.pi / 180,
                                100,
                                np.array([]),
                                minLineLength=40,
                                maxLineGap=5)
        avg_lines = utils.average_slope_intercept(img, lines)
        lines_image = img.display_lines(avg_lines)
        combined = img.combine(lines_image)
        cv2.imshow('', combined.raw)
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break

    cv2.destroyAllWindows()
    stream.stop()
Ejemplo n.º 2
0
 def process_url_web(self, url, data=None):
     # get header web
     header_content = self.get_url_content(url, view=False)
     if not header_content:
         if self._thread_queue:
             self._thread_queue.get()
         self._pr.pr_err('failed to download %s header web.' % url)
         return
     # get url title.
     title = self.get_title(header_content, self._title)
     if not title:
         title = self.convert_url_to_title(url)
     self._pr.pr_dbg('title: %s' % title)
     # create path of title to store data.
     subpath = os.path.join(self._path, title)
     self._pr.pr_dbg('subpath: %s' % subpath)
     # get count of pages
     pages = self.get_pages(header_content)
     self._pr.pr_dbg('get pages: %s' % pages)
     if not pages:
         limg = self.get_image_url(header_content)
     else:
         limg = self.get_image_url_of_pages(pages, header_content)
     # filter images
     limg = set(limg)
     # self._pr.pr_dbg('image url list: %s' % limg)
     # download images
     if limg:
         # download all of images.
         self.download_images(limg, subpath)
         # write web info
         self.store_web_info(subpath, title, url)
         # reclaim image, remove small image
         if self._remove_small_image:
             Image.reclaim_path_images(subpath, xfunc=Image.remove_small_image)
         else:
             Image.reclaim_path_images(subpath)
         # show output info.
         if self._view:
             if self.output_image_exists(subpath):
                 self._pr.pr_info('output: %s' % (subpath))
             else:
                 self._pr.pr_info('output no images: %s' % (subpath))
         # save url of images if it is full debug.
         if self.__dbg >= 2:
             self.store_url_of_images(subpath, limg)
     # release queue
     if self._thread_queue:
         self._thread_queue.get()
     if data:
         self._pr.pr_info('%d/%d: process %s done!' % (data[0], data[1], url))
     return subpath
Ejemplo n.º 3
0
 def output_image_exists(self, path):
     for rt, ds, fs in os.walk(path):
         if fs:
             for f in fs:
                 f = os.path.join(rt, f)
                 if Image.image_file2(f):
                     return True
     return False
Ejemplo n.º 4
0
 def unzip_wiz(self):
     for f in self._fs:
         path = os.path.join(
             os.path.dirname(f).replace(self._src, self._dst),
             File.get_fname(f))
         path = os.path.splitext(path)[0]
         Path.make_path(path)
         self.unzip_file(f, path)
         # remove small image.
         Image.remove_small_image(path)
         # move image.
         if os.path.exists('%s/index_files' % path):
             for ff in os.listdir('%s/index_files' % path):
                 if Image.image_file('%s/index_files/%s' % (path, ff)):
                     shutil.copyfile('%s/index_files/%s' % (path, ff),
                                     '%s/%s' % (path, ff))
             # remove invalid files and dirs.
             shutil.rmtree('%s/index_files' % path)
         if os.path.exists('%s/index.html' % path):
             os.remove('%s/index.html' % path)
Ejemplo n.º 5
0
def main():
    img_path = (Path(__file__).parent / 'lanes.jpg').absolute()
    img = Image.from_file(str(img_path))
    transformed = Transformer(img)
    image = transformed.cannify()
    cropped_img = region(image)
    lines = cv2.HoughLinesP(cropped_img.raw, 2, np.pi / 180,
                            100, np.array([]), minLineLength=40, maxLineGap=5)
    avg_lines = utils.average_slope_intercept(img, lines)
    lines_image = img.display_lines(avg_lines)
    combined = img.combine(lines_image)
    combined.show(stream=False)
Ejemplo n.º 6
0
def loadImages(oriDir = ".", imDir = ".", exts = (".jpg", ".tif", ".JPG", ".TIF", ".JPEG", ".TIFF") , channel = "unknown") :
     
    #Reads all images and returns a list of images
    try :
        ls=listdir(imDir)
    except FileNotFoundError :
        raise FileNotFoundError
    image_list = []
    for f in ls :
        file=join(imDir, f)
        xmlfile=join(oriDir, "Orientation-"+f+".xml")
        if isfile(file) and f.endswith(exts) and exists(xmlfile):
            
            data=plt.imread(file)
            R, S = readOri(xmlfile)
            img = Image(f, channel,data, R, S)
            image_list.append(img)
    return image_list
Ejemplo n.º 7
0
def main():
  script_dir = os.path.dirname(os.path.realpath(__file__))

  image = Image(script_dir, 'config.json')
  image.create()
Ejemplo n.º 8
0
def add_routes(config):
    """
    Called once per thread start, in order to call
    :func:`solute.epfl.core.epflcomponentbase.ComponentBase.add_pyramid_routes` for every component provided by epfl
    through this package.
    """

    Box.add_pyramid_routes(config)
    LoginBox.add_pyramid_routes(config)
    ModalBox.add_pyramid_routes(config)
    TabsLayout.add_pyramid_routes(config)
    NavLayout.add_pyramid_routes(config)
    ColLayout.add_pyramid_routes(config)
    CardinalLayout.add_pyramid_routes(config)
    Link.add_pyramid_routes(config)

    RecursiveTree.add_pyramid_routes(config)
    ListLayout.add_pyramid_routes(config)
    PrettyListLayout.add_pyramid_routes(config)
    PaginatedListLayout.add_pyramid_routes(config)
    LinkListLayout.add_pyramid_routes(config)
    GroupedLinkListLayout.add_pyramid_routes(config)
    HoverLinkListLayout.add_pyramid_routes(config)
    ContextListLayout.add_pyramid_routes(config)
    TableLayout.add_pyramid_routes(config)
    SelectableList.add_pyramid_routes(config)

    TypeAhead.add_pyramid_routes(config)

    Form.add_pyramid_routes(config)
    Button.add_pyramid_routes(config)
    TextInput.add_pyramid_routes(config)
    TextEditor.add_pyramid_routes(config)
    CodeEditor.add_pyramid_routes(config)
    NumberInput.add_pyramid_routes(config)
    Textarea.add_pyramid_routes(config)
    Radio.add_pyramid_routes(config)
    ButtonRadio.add_pyramid_routes(config)
    Toggle.add_pyramid_routes(config)
    SimpleToggle.add_pyramid_routes(config)
    Checkbox.add_pyramid_routes(config)
    Select.add_pyramid_routes(config)
    Upload.add_pyramid_routes(config)
    Download.add_pyramid_routes(config)
    ColorPicker.add_pyramid_routes(config)
    ColorThief.add_pyramid_routes(config)
    DatetimeInput.add_pyramid_routes(config)
    AutoCompleteInput.add_pyramid_routes(config)
    PasswordInput.add_pyramid_routes(config)

    Badge.add_pyramid_routes(config)
    Diagram.add_pyramid_routes(config)
    Progress.add_pyramid_routes(config)
    StackedProgress.add_pyramid_routes(config)
    Image.add_pyramid_routes(config)
    Text.add_pyramid_routes(config)
    Placeholder.add_pyramid_routes(config)
    PlainHtml.add_pyramid_routes(config)
    Breadcrumb.add_pyramid_routes(config)
    Carousel.add_pyramid_routes(config)
    Popover.add_pyramid_routes(config)

    TextList.add_pyramid_routes(config)
    Dropdown.add_pyramid_routes(config)

    EmbeddedVideo.add_pyramid_routes(config)
Ejemplo n.º 9
0
def add_routes(config):
    """
    Called once per thread start, in order to call
    :func:`solute.epfl.core.epflcomponentbase.ComponentBase.add_pyramid_routes` for every component provided by epfl
    through this package.
    """

    Box.add_pyramid_routes(config)
    LoginBox.add_pyramid_routes(config)
    ModalBox.add_pyramid_routes(config)
    TabsLayout.add_pyramid_routes(config)
    NavLayout.add_pyramid_routes(config)
    ColLayout.add_pyramid_routes(config)
    CardinalLayout.add_pyramid_routes(config)
    Link.add_pyramid_routes(config)

    RecursiveTree.add_pyramid_routes(config)
    ListLayout.add_pyramid_routes(config)
    PrettyListLayout.add_pyramid_routes(config)
    PaginatedListLayout.add_pyramid_routes(config)
    LinkListLayout.add_pyramid_routes(config)
    GroupedLinkListLayout.add_pyramid_routes(config)
    HoverLinkListLayout.add_pyramid_routes(config)
    ContextListLayout.add_pyramid_routes(config)
    TableLayout.add_pyramid_routes(config)
    SelectableList.add_pyramid_routes(config)

    TypeAhead.add_pyramid_routes(config)

    Form.add_pyramid_routes(config)
    Button.add_pyramid_routes(config)
    TextInput.add_pyramid_routes(config)
    TextEditor.add_pyramid_routes(config)
    CodeEditor.add_pyramid_routes(config)
    NumberInput.add_pyramid_routes(config)
    Textarea.add_pyramid_routes(config)
    Radio.add_pyramid_routes(config)
    ButtonRadio.add_pyramid_routes(config)
    Toggle.add_pyramid_routes(config)
    SimpleToggle.add_pyramid_routes(config)
    Checkbox.add_pyramid_routes(config)
    Select.add_pyramid_routes(config)
    Upload.add_pyramid_routes(config)
    Download.add_pyramid_routes(config)
    ColorPicker.add_pyramid_routes(config)
    ColorThief.add_pyramid_routes(config)
    DatetimeInput.add_pyramid_routes(config)
    AutoCompleteInput.add_pyramid_routes(config)
    PasswordInput.add_pyramid_routes(config)

    Badge.add_pyramid_routes(config)
    Diagram.add_pyramid_routes(config)
    Progress.add_pyramid_routes(config)
    StackedProgress.add_pyramid_routes(config)
    Image.add_pyramid_routes(config)
    Text.add_pyramid_routes(config)
    Placeholder.add_pyramid_routes(config)
    PlainHtml.add_pyramid_routes(config)
    Breadcrumb.add_pyramid_routes(config)
    Carousel.add_pyramid_routes(config)
    Popover.add_pyramid_routes(config)

    TextList.add_pyramid_routes(config)
    Dropdown.add_pyramid_routes(config)

    EmbeddedVideo.add_pyramid_routes(config)
Ejemplo n.º 10
0
def main():
    img_path = (Path(__file__).parent / 'way.jpg').absolute()
    img = Image.from_file(str(img_path))
    transformer = Transformer(img)
    blurred = transformer.cannify()
    cv2.imwrite('blurred.jpg', blurred._img_data)
Ejemplo n.º 11
0
def region(image: Image) -> Image:
    width, height = image.dims
    triangle = np.array([(200, height), (1100, height), (550, 250)])
    mask = np.zeros_like(image.raw)
    cv2.fillPoly(mask, [triangle], 255)
    return Image(cv2.bitwise_and(image.raw, mask))