File: image-load-modify-display.coffee

package info (click to toggle)
node-opencv 6.0.0%2Bgit20180416.cfc96ba0-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 24,632 kB
  • sloc: xml: 476,707; cpp: 5,950; makefile: 114; sh: 59; ansic: 20
file content (28 lines) | stat: -rw-r--r-- 1,140 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
cv = require('opencv')


cv.readImage("./images/windows-logo.png", (err, im) ->

  # The nodejs-opencv has some shortcodes for image manipulation.
  # We modify the image using the handy function im.convertGrayscale()
  # This will overwrite the current image with a grayscaled version.
  im.convertGrayscale()

  # Create new NamedWindow object to hold the image
  # NamedWindow takes two arguments String WindowName and String windowSize
  namedWindow = new cv.NamedWindow('Display Window', '400x400')

  # We then tell the image to show the image we loaded.
  namedWindow.show(im)

  console.log("Image should be displayed inside a window.")
  # Finally we tell the NamedWindow to wait for any key being pressed to close
  # itself (by passing a 0 as the first param, or wait a defined amount of time
  # by passing the time as a second argument (in milliseconds)
  #
  # If we do not tell the window to wait it will just load and show the image
  # and close so fast that it will appear nothing happened.
  namedWindow.blockingWaitKey(0, 5000)

  console.log("And the window should close automatically or by pressing any key on it.")
)