博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
jQuery人脸检测
阅读量:2512 次
发布时间:2019-05-11

本文共 16315 字,大约阅读时间需要 54 分钟。

jQuery Face Detection

I've always been intrigued by recognition software because I cannot imagine the logic that goes into all of the algorithms. Whether it's voice, face, or other types of detection, people look and sound so different, pictures are shot differently, and from different angles, I cannot fathom how it's all done. Since I already covered booby , I thought it would be worth some time to explore face detection. Facebook uses it, so maybe it has application in your websites.

我一直对识别软件很感兴趣,因为我无法想象所有算法中包含的逻辑。 无论是语音,面部还是其他类型的检测,人们的外观和声音都如此不同,照片的拍摄方式也不同,而且从不同的角度看,我无法理解它是如何完成的。 因为我已经讲过 布比 ,我认为值得花一些时间来探索人脸检测。 Facebook使用它,因此它可能已在您的网站中使用。

One face detection library I found is and Liu Liu. This is a standard jQuery plugin that receives an image and returns an array of coordinates of faces found within the image. Let's have a look at how to use it!

我发现的一个面部检测库是和Liu Liu的 。 这是一个标准的jQuery插件,用于接收图像并返回在图像中找到的人脸坐标数组。 让我们看看如何使用它!

jQuery.faceDetection (jQuery.faceDetection)

Four JS files are required for this jQuery plugin:

此jQuery插件需要四个JS文件:

 

The faceDetection plugin wraps functionality within the first two JavaScript files, and returns an array of objects which represent the coordinates of the faces within the photo (if any are found). An example would be:

faceDetection插件将功能包装在前两个JavaScript文件中,并返回一个对象数组,这些对象代表照片中人脸的坐标(如果找到)。 一个例子是:

var coords = jQuery("#myImage").faceDetection();/* Returns:	{		x: 525		y: 435,		width: 144,		height: 144,		positionX: 532.6353328125226,		positionY: 443.240976080536,		offsetX: 532.6353328125226,		offsetY: 443.240976080536,		confidence: 12.93120119,		neighbour: undefined,	}*/

You may also add event callbacks to every call:

您还可以向每个调用添加事件回调:

var coords = jQuery("#myImage").faceDetection({	complete: function(image, coords) {		// Do something	},	error: function() {		console.warn("Could not process image");	}});

It's up to you what you'd like to do when the faces have been found. You could add a square around the person's face:

发现面Kong后,您要做什么取决于您。 您可以在此人的脸部周围添加一个正方形:

jQuery("img").each(function() {	var img = this;	// Get faces cooridnates	var coordinates = jQuery(img).faceDetection();	// Make boxes if faces are found	if(coordinates.length) {		coordinates.forEach(function(coord) {			jQuery("   
", { css: { position: "absolute", left: coord.positionX + 5 + "px", top: coord.positionY + 5 + "px", width: coord.width + "px", height: coord.height + "px", border: "3px solid white" } }).appendTo(img.parentNode); }); }});
There's not much more to it than that!
I tried to vary the photos I used faceDetection on and as I expected, the results are the not perfect. They are, however, quite good; no software will be perfect for all cases. The software also does not do facial comparison, so you would need to provide suggestions as to the face's identity via another method. For what this plugin is meant to do, however, it does pretty well. I encourage you to give this a try!
By September 3, 2014
CSS animations are a lot of fun; the beauty of them is that through many simple properties, you can create anything from an elegant fade in to a WTF-Pixar-would-be-proud effect. One CSS effect somewhere in between is the CSS flip effect, whereby there's...
By February 18, 2013
I was inspired when I first saw . The hover sheen effect is simple but awesome. When I started my blog redesign, I really wanted to use a sheen effect with my logo. Using two HTML elements and...
By April 16, 2009
One of the famous MooTools plugins is plugin. AutoCompleter takes a term input by the user and searches for matches -- an obviously help to the user. Here's how to make the most of Harald's great plugin. The XHTML All we...
By March 4, 2009
Everyone loves Twitter. Everyone loves MooTools. That's why everyone should love TwitterGitter, a MooTools plugin that retrieves a user's recent tweets and allows the user to format them however the user would like. TwitterGitter allows the user to choose the number of...
Discussion
Alex iPad almost burned when browsing the demo page.
Yeah, that will happen with client-side technology like this. In practice, this is better done on the server side, but it’s still fascinating to see on the client side.
Rasmus Fløe The perfect companion article would be about webworkers :D
Yep latest FF got an slow/unresponsive script error while loading the demo. Interesting though!
Most facial recognition software is done with neural networks….the varied results are because of a limited data set used in training….in theory they can be nearly as good as people at recognizing faces (same technology for voice recognition, OCR (Object Character Recognition), etc.)..it’s essentially pattern matching. I haven’t seen any good neural networks for javascript though, so this is pretty interesting to me.
It would be great if the software could also recognize if people wear glasses, ear rings, wrinkles, et cetera. So that you would be able to apply filters on the image library and make selections.
Nice work but Slow Script Error on FF
David This is done somewhat quite easy using matlab. Too bad that my signal processing teacher was a bitch and I did not learn anything…
andre yeah and god accidentally forgot to give you brain
foluso any thing on global browser detection am having battles with site displaying on other browsers as it did on my browser
Tarlenan This website had made a similar tutorial using the same jQuery pluign by Jay Salvat, but they have presented many examples on using the plugin. May be it is useful for your visitors.
thank you for sharing, this is realy one of the complex jQuery plugins, but how the f**k they do it ?? have any one a document of the algorithm ? Thank you.
serkan Can you add sound output in your face detection program.. it say your name..
Hi i would like to recognize only one face from the group photo as well from the single image photo too. So what should i do in the code. It would be great help if anyone say the solution. Thanks in advance.
Rufus It works great but when there is no face to detect in a picture it does not trigger the error function, but only the “complete” function. It does trigger the error function when the pic is below a certain size however. I tried checking for undefined (and tried null too) in the array like so: but no dice. Any suggestions? I am developing a chrome app so only testing there.
Nice Tutorial David.. :) you are really rocking.. please share more tutorials on jQuery..
Hi David, The demo no longer works (in Chrome) because you can no longer embed javascript from raw.github.com . Sairam
Vikram Hi David Walsh, I am getting the error ‘ this image is invalid’. Can you hint how to solve this problem.
Vikram (when I tried it locally and on localhost)
Justin O'Neill Hi David, This doesn’t seem to be working in Chrome at all and in FireFox is spits an error back at me. It did manage to pop out a white border box, however it wasn’t on the face.
Man Man.. hotlinking from github has been disabled. Now your demo doesnt work. Can you update your demo? Cheers!
perfo hello, all. How could I do this but without displaying the video on the screen ? I want to detect if someone is in front of the camera and roughly where they are but I don’t need to video to be displayed. Any hints ? Thanks
Kapil Gupta Hi David, Do you have idea that how can we use this one to detect the face shape (like Oval, square, narrow etc…) Please let me know if you know any API’s for it also… Thanks
The example only highlights one soccer player, the photo with Brad/Angelina, and one photo in the black and white.
You could also forego any development and just leverage a pre-existing API service that provides this sort of functionality. For instance the follow face detection API can be hit from javascript client side or server side. Face Location
Name: Email: Website: Wrap your code in
 tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed! Continue this conversation via emailGet only replies to your comment, the best of the rest, as well as a daily recap of all comments on this post. No more than a few emails daily, which you can reply to/unsubscribe from directly from your inbox. Use Code Editor
jQuery("img").each(function() {	var img = this;	// Get faces cooridnates	var coordinates = jQuery(img).faceDetection();	// Make boxes if faces are found	if(coordinates.length) {		coordinates.forEach(function(coord) {			jQuery("   
", { css: { position: "absolute", left: coord.positionX + 5 + "px", top: coord.positionY + 5 + "px", width: coord.width + "px", height: coord.height + "px", border: "3px solid white" } }).appendTo(img.parentNode); }); }});
There's not much more to it than that!
I tried to vary the photos I used faceDetection on and as I expected, the results are the not perfect. They are, however, quite good; no software will be perfect for all cases. The software also does not do facial comparison, so you would need to provide suggestions as to the face's identity via another method. For what this plugin is meant to do, however, it does pretty well. I encourage you to give this a try!
By September 3, 2014
CSS animations are a lot of fun; the beauty of them is that through many simple properties, you can create anything from an elegant fade in to a WTF-Pixar-would-be-proud effect. One CSS effect somewhere in between is the CSS flip effect, whereby there's...
By February 18, 2013
I was inspired when I first saw . The hover sheen effect is simple but awesome. When I started my blog redesign, I really wanted to use a sheen effect with my logo. Using two HTML elements and...
By April 16, 2009
One of the famous MooTools plugins is plugin. AutoCompleter takes a term input by the user and searches for matches -- an obviously help to the user. Here's how to make the most of Harald's great plugin. The XHTML All we...
By March 4, 2009
Everyone loves Twitter. Everyone loves MooTools. That's why everyone should love TwitterGitter, a MooTools plugin that retrieves a user's recent tweets and allows the user to format them however the user would like. TwitterGitter allows the user to choose the number of...
Discussion
Alex iPad almost burned when browsing the demo page.
Yeah, that will happen with client-side technology like this. In practice, this is better done on the server side, but it’s still fascinating to see on the client side.
Rasmus Fløe The perfect companion article would be about webworkers :D
Yep latest FF got an slow/unresponsive script error while loading the demo. Interesting though!
Most facial recognition software is done with neural networks….the varied results are because of a limited data set used in training….in theory they can be nearly as good as people at recognizing faces (same technology for voice recognition, OCR (Object Character Recognition), etc.)..it’s essentially pattern matching. I haven’t seen any good neural networks for javascript though, so this is pretty interesting to me.
It would be great if the software could also recognize if people wear glasses, ear rings, wrinkles, et cetera. So that you would be able to apply filters on the image library and make selections.
Nice work but Slow Script Error on FF
David This is done somewhat quite easy using matlab. Too bad that my signal processing teacher was a bitch and I did not learn anything…
andre yeah and god accidentally forgot to give you brain
foluso any thing on global browser detection am having battles with site displaying on other browsers as it did on my browser
Tarlenan This website had made a similar tutorial using the same jQuery pluign by Jay Salvat, but they have presented many examples on using the plugin. May be it is useful for your visitors.
thank you for sharing, this is realy one of the complex jQuery plugins, but how the f**k they do it ?? have any one a document of the algorithm ? Thank you.
serkan Can you add sound output in your face detection program.. it say your name..
Hi i would like to recognize only one face from the group photo as well from the single image photo too. So what should i do in the code. It would be great help if anyone say the solution. Thanks in advance.
Rufus It works great but when there is no face to detect in a picture it does not trigger the error function, but only the “complete” function. It does trigger the error function when the pic is below a certain size however. I tried checking for undefined (and tried null too) in the array like so: but no dice. Any suggestions? I am developing a chrome app so only testing there.
Nice Tutorial David.. :) you are really rocking.. please share more tutorials on jQuery..
Hi David, The demo no longer works (in Chrome) because you can no longer embed javascript from raw.github.com . Sairam
Vikram Hi David Walsh, I am getting the error ‘ this image is invalid’. Can you hint how to solve this problem.
Vikram (when I tried it locally and on localhost)
Justin O'Neill Hi David, This doesn’t seem to be working in Chrome at all and in FireFox is spits an error back at me. It did manage to pop out a white border box, however it wasn’t on the face.
Man Man.. hotlinking from github has been disabled. Now your demo doesnt work. Can you update your demo? Cheers!
perfo hello, all. How could I do this but without displaying the video on the screen ? I want to detect if someone is in front of the camera and roughly where they are but I don’t need to video to be displayed. Any hints ? Thanks
Kapil Gupta Hi David, Do you have idea that how can we use this one to detect the face shape (like Oval, square, narrow etc…) Please let me know if you know any API’s for it also… Thanks
The example only highlights one soccer player, the photo with Brad/Angelina, and one photo in the black and white.
You could also forego any development and just leverage a pre-existing API service that provides this sort of functionality. For instance the follow face detection API can be hit from javascript client side or server side. Face Location
Name: Email: Website: Wrap your code in
 tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed! Continue this conversation via email Get only replies to your comment, the best of the rest, as well as a daily recap of all comments on this post. No more than a few emails daily, which you can reply to/unsubscribe from directly from your inbox. Use Code Editor

翻译自:

转载地址:http://xgswd.baihongyu.com/

你可能感兴趣的文章
AngularJs学习笔记-慕课网AngularJS实战
查看>>
数据库三大范式
查看>>
工作总结之二:bug级别、优先级别、bug状态
查看>>
访问修饰符、封装、继承
查看>>
更换pip源到国内镜像,提升pip下载速度.
查看>>
POJ 2265 Bee Maja (找规律)
查看>>
Kendo MVVM 数据绑定(七) Invisible/Visible
查看>>
[zz]kvm环境使用libvirt创建虚拟机
查看>>
bzoj1059 [ZJOI2007]矩阵游戏
查看>>
插入返回ibatis 的selectKey 实现插入数据后获得id
查看>>
vim 程序编辑器
查看>>
LIS(单调队列优化 C++ 版)(施工ing)
查看>>
刚接触Vuex
查看>>
四种加载React数据的技术对比(Meteor 转)
查看>>
Airthmetic_Approching
查看>>
操作文本文件
查看>>
公司项目的几个问题
查看>>
解决win7下打开Excel2007,报“向程序发送命令时出现问题”的错误
查看>>
Velocity快速入门教程
查看>>
关于集合常见的问题
查看>>