{"id":2981,"date":"2017-04-25T15:46:05","date_gmt":"2017-04-25T20:46:05","guid":{"rendered":"https:\/\/blogs.mathworks.com\/videos\/?p=2981"},"modified":"2017-04-27T16:34:02","modified_gmt":"2017-04-27T21:34:02","slug":"writing-a-script-to-automate-the-cropping-of-many-photos","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/videos\/2017\/04\/25\/writing-a-script-to-automate-the-cropping-of-many-photos\/","title":{"rendered":"Writing A Script to Automate the Cropping of Many Photos Using Face Detection"},"content":{"rendered":"<p>My colleague Tim makes a video presentation of new hires joining MathWorks for each quarterly company meeting. He likes to use uniformly cropped photos of staff members, similar to this one of when I joined 20 years ago today (I was more pixelated in those days).<\/p>\n<p><a href=\"https:\/\/blogs.mathworks.com\/videos\/files\/stuartm_tn_AD.jpg\"><img decoding=\"async\" loading=\"lazy\" width=\"200\" height=\"200\" src=\"https:\/\/blogs.mathworks.com\/videos\/files\/stuartm_tn_AD.jpg\" alt=\"\" class=\"alignnone size-full wp-image-2982\" \/><\/a><\/p>\n<p>But this can be time consuming to do manually, especially when we hire more than 100 staff members a quarter. So he asked if I could automate it for him. Here is my first attempt to build a script to do that. <\/p>\n<p>Features covered in this <a href=\"https:\/\/blogs.mathworks.com\/videos\/2015\/10\/29\/matlab-code-along-videos\/\">code-along<\/a> style video include:<\/p>\n<ul>\n<li><tt>vision.CascadeObjectDetector System object<\/tt>, from Computer Vision System Toolbox for the face detection<\/li>\n<li><tt>imread<\/tt>, <tt>imwrite<\/tt><\/li>\n<li>tables, and <tt>dir<\/tt> for extracting multiple files for processing in a loop<\/li>\n<\/ul>\n<p><div class=\"row\"><div class=\"col-xs-12 containing-block\"><div class=\"bc-outer-container add_margin_20\"><videoplayer><div class=\"video-js-container\"><video data-video-id=\"5410983877001\" data-video-category=\"blog\" data-autostart=\"false\" data-account=\"62009828001\" data-omniture-account=\"mathwgbl\" data-player=\"rJ9XCz2Sx\" data-embed=\"default\" id=\"mathworks-brightcove-player\" class=\"video-js\" controls><\/video><script src=\"\/\/players.brightcove.net\/62009828001\/rJ9XCz2Sx_default\/index.min.js\"><\/script><script>if (typeof(playerLoaded) === 'undefined') {var playerLoaded = false;}(function isVideojsDefined() {if (typeof(videojs) !== 'undefined') {videojs(\"mathworks-brightcove-player\").on('loadedmetadata', function() {playerLoaded = true;});} else {setTimeout(isVideojsDefined, 10);}})();<\/script><\/div><\/videoplayer><\/div><\/div><\/div><\/p>\n<p>Play the video in full screen mode for a better viewing experience.\u00a0<\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"thumbnail thumbnail_asset asset_overlay video\"><a href=\"https:\/\/blogs.mathworks.com\/videos\/2017\/04\/25\/writing-a-script-to-automate-the-cropping-of-many-photos\/?dir=autoplay\"><img decoding=\"async\" src=\"https:\/\/cf-images.us-east-1.prod.boltdns.net\/v1\/static\/62009828001\/50a2ef0c-9f17-4dff-8a95-624e42e35e2c\/a49543db-7ca7-468d-abe4-49f0cb489c01\/160x90\/match\/image.jpg\" onError=\"this.style.display ='none';\"\/><\/p>\n<div class=\"overlay_container\">\n      <span class=\"icon-video icon_color_null\"><time class=\"video_length\">52:57<\/time><\/span>\n      <\/div>\n<p>      <\/a><\/div>\n<p>My colleague Tim makes a video presentation of new hires joining MathWorks for each quarterly company meeting. He likes to use uniformly cropped photos of staff members, similar to this one of when I&#8230; <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/videos\/2017\/04\/25\/writing-a-script-to-automate-the-cropping-of-many-photos\/\">read more >><\/a><\/p>\n","protected":false},"author":133,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[27,4],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/videos\/wp-json\/wp\/v2\/posts\/2981"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/videos\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/videos\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/videos\/wp-json\/wp\/v2\/users\/133"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/videos\/wp-json\/wp\/v2\/comments?post=2981"}],"version-history":[{"count":10,"href":"https:\/\/blogs.mathworks.com\/videos\/wp-json\/wp\/v2\/posts\/2981\/revisions"}],"predecessor-version":[{"id":2996,"href":"https:\/\/blogs.mathworks.com\/videos\/wp-json\/wp\/v2\/posts\/2981\/revisions\/2996"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/videos\/wp-json\/wp\/v2\/media?parent=2981"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/videos\/wp-json\/wp\/v2\/categories?post=2981"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/videos\/wp-json\/wp\/v2\/tags?post=2981"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}