And here is an example drawing a rect in front of your face and ellipsis over your eyes and mouth using the front camera stream.
-- FaceDetection
-- Use this function to perform your initial setup
function setup()
displayMode(FULLSCREEN)
m = mesh()
m:addRect(WIDTH/2,HEIGHT/2,WIDTH,HEIGHT)
m.texture = CAMERA
cameraSource(CAMERA_FRONT)
img = image(WIDTH, HEIGHT)
face = {}
detectTimer = ElapsedTime + 0.2
end
-- This function gets called once every frame
function draw()
m:draw()
if ElapsedTime > detectTimer then -- update every 0.2 seconds
detectTimer = ElapsedTime + 0.2
updateFeatures()
end
if face and face.x then
fill(255,255,255,100)
rectMode(CORNER)
rect(face.x, face.y, face.width, face.height)
if face.leftEye then
fill(255,0,0,100)
ellipse(face.leftEye.x, face.leftEye.y, 50)
end
if face.rightEye then
fill(255,0,0,100)
ellipse(face.rightEye.x, face.rightEye.y, 50)
end
if face.mouth then
fill(0,255,0,100)
ellipse(face.mouth.x, face.mouth.y, 50)
end
end
end
function updateFeatures()
setContext(img)
m:draw()
setContext()
face = detectFaceFeatures(img)
end
The other features in my library are used like this:
-- will show a popup with facebook sharing options for the image
shareToFacebook(image)
-- will save the image to the photo album. showing a dialog to allow access the first time
saveToPhotoAlbum(image)
That looks great @tnlogy - So your C code in your Gist is integrated in the next release of Codea as a face detection Lua lib? Cool. I guess you’re only a few steps away then from some sort of more sophisticated Augmented Reality functionality… Hmmmm… Interesting.
The process will be to export your Lua code to a Xcode project from within Codea. Then you can add this addon to the Xcode project to use this functionality. Of course it would be nice if TTL would add some of the addons to the Codea app in future releases. As it is now, you have to simulate the functionality in Codea, since it is only available in the runtime.
Thanks for the info. So I guess this means you can only really test this from within Xcodes simulator, although in practice you’d really need to compile it and test on the iPad (to use the camera). You’re right though, integrating it directly into Codea would make more sense for this very reason. I notice @Reefwing has a new tutorial on developing additional Lua libs and integrating them into the runtime which opens up a whole range of possibilities such as this.
HI @tnlogy, Thanks for creating the addon. I am not experienced enough to understand fully how to get this working and need your help (or anyone else) please?
I have your Codea example exported loaded up in Xcode and I have added the other two files from the Gisthub - ImageTools.mm and ImageTools.h - trying different locations to figure out where these should be - Addons folder?
Nevertheless, for all my efforts so far I cannot get anything to run in the simulator.
All I really need to do is to get an example working - Once I see this happen then I aim to add ‘save to camera roll’ functionality to an app I am creating.
Any guidance is vastly appreciated - thankyou!