Skip to content
Snippets Groups Projects
Select Git revision
  • v0.3.0
  • master default protected
  • th/two-steps-ux
  • th/free-draw
  • th/js-exp
  • th/speedup
  • th/resizing
  • th/algotweaks
  • algo
  • th/ui-propal-merge
  • ad/ui-propal
  • th/i18n
  • th/simplify
  • th/svg
  • th/brush
  • th/konva
  • th/pos_system
  • jc/extract-promise
  • th/styling
  • jc/npm-package
  • th/zoom
  • v0.9.97
  • v0.9.96
  • v0.9.95
  • v0.9.94
  • v0.9.93
  • v0.9.92
  • v0.9.91
  • v0.9.9
  • v0.9.8
  • v0.9.7
  • v0.9.6
  • v0.9.5
  • v0.9.4
  • v0.9.3
  • v0.9.2
  • v0.9.1
  • v0.9.0
  • v0.8.2
  • v0.8.1
  • v0.8.0
41 results

cool

  • Open with
  • Download source code
  • Your workspaces

      A workspace is a virtual sandbox environment for your code in GitLab.

      No agents available to create workspaces. Please consult Workspaces documentation for troubleshooting.

  • Thomas Hennebert's avatar
    Thomas Hennebert authored
    8dac55d0
    History

    COOL

    CERTIC Object Outline Library?

    A web component utility to easily extract the foreground elements of an image.

    Prerequisites

    You need python3 if you intend to run the dev server.

    Usage

    # run a development server to test the library 
    make dev 

    To use in your project, copy the cool directory into your project and load the cool.js module in your HTML.

    Add the cool-ed web component to your page and load an image via the data-image-url attribute:

    <cool-ed id="editor" extract-callback="printContours" data-image-url="https://my_site/my_image.jpeg"></cool-ed>

    The attribute can also be set dynamically to load a new image.

    Note: make sure to define an id for the cool-ed component, this is needed to properly load openCV on startup.

    Listen to the contours-extracted event to retrieve the contours which are returned as a 3 dimensional array with the layout:

    contour
    |__ contour points
      |__ point x and y coordinates
    <script>
        document.addEventListener("DOMContentLoaded", (e) => {
            const editor = document.querySelector("#editor");
            editor.addEventListener("contours-extracted", (event) => {
                const contours = event.detail;
                for (c of contours) {
                    console.log("Contour:");
                    for (point of c) {
                        console.log("x: ", point[0], " y: ", point[1]);
                    }
                }
            });
        });
    </script>
    
    <script src="cool/cooled.js" type="module"></script>

    Optional component attributes

    Preferences:

    • data-default-brush-size
    • data-background-dot-color
    • data-foreground-dot-color
    • log-opencv-build-info

    Extracting elements of the image

    • Select a brush mode in the toolbar, the size of the dot can be adjusted via the brush size slider.
    • click on Extract and a wait a few seconds to get the contours of the extracted foreground.

    Customizing the CSS

    The editor elements are exposed via the part selector, so you can style them :

    cool-ed::part(extract_button) {
        color: #00aa00;
    }

    You can look up the part names via the browser inspector, here is a list of the available elements:

    • toolbar
      • init_workspace_button
      • undo_button
      • extract_button
      • brush_size_label
      • brush_size_slider
      • brush_type_fieldset
        • foreground_brush_radio
        • foreground_brush_label
        • background_brush_radio
        • background_brush_label
        • eraser_brush_radio
        • eraser_brush_label
      • user_layer_toggle_legend
      • user_layer_toggle
    • panel

    Notes

    If the image width or height are greater than 1000px, the image will be resized for performance reasons. The scaling automatically divides the size by 2 until it is conform (which means corner case situations can lead to unexpected resizing, for example an image of 1002x1002 will be resized to 501x501). It is advised to pass images where the size is below 600px for better performance. Ideally you should pass an image already cropped around the region of interest and at the appropriate size.