Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div>
  <span>Click on a button for start<br/>processing in real time</span>
</div>
<button onclick="main()">Start Capturing</button>
              
            
!

CSS

              
                button {
  width: 100%;
  height: 60px;
  background: rgb(123, 200, 156);
  border: none;
  font-size: 18px;
  margin-top: 8px;
}
div {
  height: calc(100% - 68px);
  overflow: hidden;
  background: rgb(220, 220, 220);
  text-align: center;
  position: relative;
}
html, body {
  height: 100%;
  box-sizing: border-box;
}
body {
  margin: 0;
  padding: 8px;
}
canvas {
  display: block;
  margin: 0 auto;
  position: relative;
}
span {
  color: rgb(140, 140, 140);
  position: absolute;
  top: calc(50% - 18px);
  left: 0;
  width: 100%;
  font-family: "Open Sans";
}
              
            
!

JS

              
                // https://gammacv.com
const width = 500;
const heigth = 400;
// initialize WebRTC stream and session for runing operations on GPU
const stream = new gm.CaptureVideo(width, heigth);
const sess = new gm.Session();
const canvasProcessed = gm.canvasCreate(width, heigth);

// session uses a context for optimize calculations and prevent recalculations
// context actually a number which help algorythm to run operation efficiently  
let context = 0;
// allocate memeory for storing a frame and calculations output
const input = new gm.Tensor('uint8', [heigth, width, 4]);
// construct operation grap which is actially a Canny Edge Detector
let pipeline = input

pipeline = gm.grayscale(pipeline);
pipeline = gm.gaussianBlur(pipeline, 3, 3);
pipeline = gm.sobelOperator(pipeline);
pipeline = gm.cannyEdges(pipeline, 0.25, 0.75);

// initialize graph
sess.init(pipeline);

// allocate output
const output = gm.tensorFrom(pipeline);

// create loop
const tick = () => {
  requestAnimationFrame(tick);
  // Read current in to the tensor
  stream.getImageBuffer(input);

  // finaly run operation on GPU and then write result in to output tensor
  sess.runOp(pipeline, context, output);

  // draw result into canvas
  gm.canvasFromTensor(canvasProcessed, output);

  // if we would like to be graph recalculated we need 
  // to change the context for next frame
  context += 1;
}

function main() {
  // start capturing a camera and run loop
  stream.start();
  tick();

  document.body.children[0].appendChild(canvasProcessed);
}

              
            
!
999px

Console