Merge pull request #74 from hybridgroup/opencv-examples

Added Opencv examples.
This commit is contained in:
Ron Evans 2014-01-14 14:15:10 -08:00
commit d59d151767
4 changed files with 26283 additions and 0 deletions

View File

@ -0,0 +1,44 @@
Cylon = require('../..')
Cylon.robot
connection:
name: 'opencv', adaptor: 'opencv'
devices: [
{ name: 'window', driver: 'window' }
{
name: 'camera',
driver: 'camera',
camera: 1,
haarcascade: "#{ __dirname }/examples/opencv/haarcascade_frontalface_alt.xml"
} # Default camera is 0
]
work: (my) ->
my.camera.once('cameraReady', ->
console.log('The camera is ready!')
# We listen for frame ready event, when triggered
# we display the frame/image passed as an argument
# and we tell the window to wait 40 milliseconds
my.camera.on('frameReady', (err, im) ->
console.log("FRAMEREADY!")
my.window.show(im, 40)
#my.camera.readFrame()
)
# Here we have two options to start reading frames from
# the camera feed.
# 1. As fast as possible triggering the next frame read
# in the listener for frameReady, if you need video
# as smooth as possible uncomment #my.camera.readFrame()
# in the listener above and the one below this comment.
#
# my.camera.readFrame()
#
# 2. Use an interval of time to try and get aset amount
# of frames per second (FPS), in the next example
# we are trying to get 1 frame every 50 milliseconds
# (20 FPS).
#
every 50, my.camera.readFrame
)
.start()

View File

@ -0,0 +1,20 @@
Cylon = require('../..')
Cylon.robot
connection:
name: 'opencv', adaptor: 'opencv'
devices: [
{ name: 'window', driver: 'window' }
{ name: 'camera', driver: 'camera', camera: 1 }
]
work: (my) ->
my.camera.on('cameraReady', ->
console.log('THE CAMERA IS READY!')
my.camera.on('frameReady', (err, im) ->
my.window.show(im, 5000)
)
my.camera.readFrame()
)
.start()

View File

@ -0,0 +1,58 @@
Cylon = require('../..')
Cylon.robot
connection:
name: 'opencv', adaptor: 'opencv'
devices: [
{ name: 'window', driver: 'window' }
{
name: 'camera',
driver: 'camera',
camera: 1,
haarcascade: "#{ __dirname }/haarcascade_frontalface_alt.xml"
} # Default camera is 0
]
work: (my) ->
# We setup our face detection once the camera is ready to
# siplays images, we used once to make sure the event listeners
# are only registered once.
my.camera.once('cameraReady', ->
console.log('The camera is ready!')
# We add a listener for the facesDetected event
# here we will get (err, image/frame, faces) params.
# The faces param is an array conaining any face detected
# in the frame (im).
my.camera.on('facesDetected', (err, im, faces) ->
# We loop trhough the faces and manipulate the image
# to display a square in the coordinates for the detected
# faces.
for face in faces
im.rectangle([face.x, face.y], [face.x + face.width, face.y + face.height], [0,255,0], 2)
# Once the image has been updated with rectangles around
# detected faces we display it in our window.
my.window.show(im, 40)
# After displaying the updated image we trigger another
# frame read to ensure the fastest processing possible.
# We could also use an interval to try and get a set
# amount of processed frames per second, see below.
my.camera.readFrame()
)
# We listen for frameReady event, when triggered
# we start the face detection passsing the frame
# that we jsut got.
my.camera.on('frameReady', (err, im) ->
my.camera.detectFaces(im)
)
# Here we could also try to get a set amount of processed FPS
# by setting an interval and reading frames every set amount
# of time. We could just uncomment the next line and commenting
# out the my.camera.readFrame() in the facesDetected listener
# as well as the one two lines below.
#every 150, my.camera.readFrame
my.camera.readFrame()
)
.start()

File diff suppressed because it is too large Load Diff