File: image-basic-shapes.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 (29 lines) | stat: -rw-r--r-- 1,238 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
29
cv = require('opencv')


cv.readImage("./images/mona.png", (err, im) ->
  # 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 add a couple of basic shapes to the image, just to show how
  # to create basic shapes.
  # im.rectangle([startX, StartY], [width, height], color(array of RGB)
  im.rectangle([50, 50], [200, 200], [0, 255, 0], 2)
  # im.ellipse(centerX, centerY, width, height, color(array of RGB)
  im.ellipse(150, 150, 50, 50, [255, 255, 0], 2)

  # 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.")
)