diff --git a/examples/CoffeeScript Examples/blend-images.coffee b/examples/CoffeeScript Examples/blend-images.coffee new file mode 100644 index 0000000..3e7ec7e --- /dev/null +++ b/examples/CoffeeScript Examples/blend-images.coffee @@ -0,0 +1,31 @@ +cv = require 'opencv' + +# we create a function helper to display the images. +displayImage = (windowName, img) -> + namedWindow = new cv.NamedWindow(windowName) + namedWindow.show(img) + namedWindow.blockingWaitKey(0, 5000) + +# Load both sources to be blended +cv.readImage("./images/windows-logo.png", (err, src1) -> + + # Display Source 1 + displayImage('Source 1', src1) + + # Load source #2 + cv.readImage("./images/linux-logo.png", (err, src2) -> + + # Display Source 2 + displayImage('Source 2', src2) + + # We use the addWeighted opencv wrapper to blend the images. + # we need to use a different image object, since src1 and src2 + # will be manipulated. + result = new cv.Matrix(src1.width(), src2.height()) + result.addWeighted(src1, 0.7, src2, 0.9) + result.save("./tmp/blended.png") + + # Display Blended result 2 + displayImage('Blended', result) + ) +) diff --git a/examples/CoffeeScript Examples/camera.coffee b/examples/CoffeeScript Examples/camera.coffee new file mode 100644 index 0000000..ec5a4e3 --- /dev/null +++ b/examples/CoffeeScript Examples/camera.coffee @@ -0,0 +1,41 @@ +cv = require 'opencv' + +# First we create a new VideoCapture object to get +# video from the camera (0 for default camera) +camera = new cv.VideoCapture(1) + +# we create a window to display the Video frames +namedWindow = new cv.NamedWindow('Video',1) + +# We set an interval to retrieve frames from the +# video source and we get the intervalId so we can +# stop the program from the video feed window. +intervalId = setInterval(()-> + + # camera.read allows us to retriebe the current + # frame to be displayed in the video window. + camera.read((err, im) -> + # We can check for errors and even break the + # program execution if an error is detected here. + console.lof "The err ==>#{ err }" if err + + # There is no need to display the image width or Height + # but I leave this here in case anyone needs to check them. + #console.log("Width: #{im.width()}") + #console.log("height: #{im.height()}") + + # We use the previously created namedWindow to display the + # video feed frame, we need to check the image is already + # available and has a width and height greated than 0, + # otherwise namedWindow.show() will fail if any of those is 0. + namedWindow.show(im) if im.width() > 0 and im.height() > 0 + + # Finally we get the key pressed on the window to terminate + # execution of the program. + res = namedWindow.blockingWaitKey(0, 20) + console.log("KEYPRESSED => #{ res } ") + + # In this case I terminate the program if any key is pressed. + if res >= 0 then clearInterval(intervalId) + ) +, 500) diff --git a/examples/CoffeeScript Examples/image-load-display.coffee b/examples/CoffeeScript Examples/image-load-display.coffee new file mode 100644 index 0000000..81b3838 --- /dev/null +++ b/examples/CoffeeScript Examples/image-load-display.coffee @@ -0,0 +1,22 @@ +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 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.") +) diff --git a/examples/CoffeeScript Examples/image-load-modify-display.coffee b/examples/CoffeeScript Examples/image-load-modify-display.coffee new file mode 100644 index 0000000..80e08a2 --- /dev/null +++ b/examples/CoffeeScript Examples/image-load-modify-display.coffee @@ -0,0 +1,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.") +) diff --git a/examples/CoffeeScript Examples/images/linux-logo.png b/examples/CoffeeScript Examples/images/linux-logo.png new file mode 100644 index 0000000..31ae97c Binary files /dev/null and b/examples/CoffeeScript Examples/images/linux-logo.png differ diff --git a/examples/CoffeeScript Examples/images/mona.png b/examples/CoffeeScript Examples/images/mona.png new file mode 100755 index 0000000..a1f7d16 Binary files /dev/null and b/examples/CoffeeScript Examples/images/mona.png differ diff --git a/examples/CoffeeScript Examples/images/windows-logo.png b/examples/CoffeeScript Examples/images/windows-logo.png new file mode 100644 index 0000000..6001491 Binary files /dev/null and b/examples/CoffeeScript Examples/images/windows-logo.png differ diff --git a/src/HighGUI.cc b/src/HighGUI.cc index 942acc6..217917a 100644 --- a/src/HighGUI.cc +++ b/src/HighGUI.cc @@ -73,9 +73,14 @@ NamedWindow::BlockingWaitKey(const v8::Arguments& args){ HandleScope scope; //SETUP_FUNCTION(NamedWindow) int time = 0; + if (args.Length() > 0){ time = args[1]->IntegerValue(); + }else{ + time = args[0]->IntegerValue(); } + int res = cv::waitKey(time); + return scope.Close(Number::New(res)); }