Skip to content

Instantly share code, notes, and snippets.

@cflove
Created May 19, 2013 15:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cflove/5608050 to your computer and use it in GitHub Desktop.
Save cflove/5608050 to your computer and use it in GitHub Desktop.
Here is Railo code for Face Detection with Jviolajones Java library. Update CreateObject() function in line 1, copy jar files into your CF server or load it with JavaLoader if you are using Adobe ColdFusion. http://cflove.org/2013/05/face-detection-with-coldfusion-and-jviolajones.cfm
<cfset Detector = CreateObject('java', 'jviolajones.Detector',"#ExpandPath('jviolajones.jar')#,#ExpandPath('jdom.jar')#" ).init( ExpandPath('haarcascade_frontalface_alt.xml'))>
<cfset image = ImageRead(ExpandPath('images/2.jpg'))>
<cfset results = Detector.getFaces( ImageGetBufferedImage(image) ,
JavaCast('float',2) ,
JavaCast('float',1.25) ,
JavaCast('float',.05) ,
JavaCast('int',3) ,
JavaCast('boolean',true) ) >
<cfset ImageSetDrawingColor(image,"red")>
<cfset ImageSetAntialiasing(image,"on")>
<cfset attr = StructNew()>
<cfset attr.width = 2>
<cfset ImageSetDrawingStroke(image,attr)>
<cfset facelist = QueryNew('face,x,y,width,height,bottom')>
<cfloop from="1" to="#ArrayLen(results)#" index="f">
<cfset QueryAddRow(facelist)>
<cfset QuerySetCell(facelist,'face',f )>
<cfset QuerySetCell(facelist,'x',results[f].x )>
<cfset QuerySetCell(facelist,'y',results[f].y )>
<cfset QuerySetCell(facelist,'width',results[f].width )>
<cfset QuerySetCell(facelist,'height',results[f].height )>
</cfloop>
<cfloop query="facelist">
<cfquery name="check" dbtype="query">
select face from facelist where face <> #face# and
x < #x# and (x+width) > #x# and
y < #y# and (y+height) > #y# and
(x+width) > #x+width#
</cfquery>
<cfif not check.recordCount>
<cfset ImageDrawRect(image,x,y,width,height,0)>
</cfif>
</cfloop>
<cfset ImageWrite(image, ExpandPath('images/test.JPG') )>
<img src="images/test.JPG" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment