Skip to content

Commit 42d57aa

Browse files
author
Florin
committed
Added runMessageLoop() and closeOnEsc() functions
1 parent 664d22f commit 42d57aa

File tree

2 files changed

+26
-10
lines changed

2 files changed

+26
-10
lines changed

scripts/calcHist.coffee

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,8 @@ for h in [0..hbins - 1]
5151
cv.namedWindow "H-S Histogram", 1
5252
cv.imshow "H-S Histogram", histImg
5353

54-
doATick = ->
55-
cv.doTick();
56-
process.nextTick doATick
5754

58-
doATick()
59-
60-
setTimeout ->
61-
process.exit -1
62-
, 5000
55+
cv.closeOnEsc()
6356

57+
#Important on Windows, if you have windows which display stuff.
58+
cv.runMessageLoop()

scripts/opencv.coffee

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#This should be done in the C++ addon ?
2-
opencvjs = require '../build/Release/addon.node'
2+
opencvjs = require '../build/Debug/addon.node'
33

44
_ = require 'underscore'
55
cv = opencvjs.OpenCV
@@ -8,4 +8,25 @@ Mat = opencvjs.Mat
88
_.extend module.exports, opencvjs
99
delete module.exports.OpenCV
1010

11-
_.extend module.exports, opencvjs.OpenCV
11+
_.extend module.exports, opencvjs.OpenCV
12+
13+
#Run the message loop on windows. This is required, otherwise the window painting will not work in Windows.
14+
module.exports.runMessageLoop = ->
15+
#I doubt this is the most efficient way to do it, but it seems to do the job for the moment
16+
doTick = ->
17+
cv.doTick(); #calls GetMessage(), TranslateMessage() and DispatchMessage()
18+
process.nextTick doTick
19+
20+
if require('os').type().toLowerCase().indexOf("windows") is 0
21+
doTick()
22+
23+
24+
#This is used
25+
module.exports.closeOnEsc = ->
26+
require('keypress') process.stdin
27+
process.stdin.on 'keypress', (char, key) ->
28+
if key.name == 'escape'
29+
console.log 'Stopping.'
30+
process.exit 0
31+
process.stdin.setRawMode true
32+
process.stdin.resume()

0 commit comments

Comments
 (0)