Slides from the talk “Face Detection and Recognition for Fun and Profit” for XCake

These are the slides to my talk for XCake on using OpenCV for face recognition on iOS. It should be noted that the first half of the talk deals with using OpenCV to also detect faces and so applies to any platform you can use OpenCV on. The simplified code sample on slide 14 should more or less work for you on non-iOS implementations.

Links

Slide 4: https://en.wikipedia.org/wiki/Prosopagnosia

Slide 6: http://opencv.org/

Slide 9: http://coding-robin.de/2013/07/22/train-your-own-opencv-haar-classifier.html

Slide 10: http://docs.opencv.org/modules/contrib/doc/facerec/facerec_tutorial.html

Slide 25: http://www.rekognition.com/
https://www.bioid.com/solutions/solutions-by-application/bioid-for-facedotcom.html
http://api.animetrics.com
http://www.identitykit.it/
http://www.skybiometry.com/

Slide 27: https://github.com/kmonaghan/FaceRecognition

Other

520 – What’s New in Camera Capture from WWDC 2012 talks about CIDetector and AVCaptureMetadataOutput from about the 19 minute mark. You should look at the sample code from that talk (StacheCam) for details on how to implement CIDetector and AVCaptureMedataOutput rather than the SquareCam project referenced in the Apple Documentation.

iOS 6, Auto Layout and MKMapView

I’m currently in the throws of updating an app for iOS 7. As part of the update, I’m throwing out all the XIBs and buying fully into using auto layout programatically.

I’ve been concentrating on getting it all to work on iOS 7 and only started at looking at how it looks on iOS 6 this week. Straight away I hit an issue

Auto Layout still required after executing -layoutSubviews. MKMapView's implementation of -layoutSubviews needs to call super.

The solution turns out to fairly straight forward. You don’t seem to be able to directly apply constraints between a MKMapView and another subview under iOS 6. Instead, you place your map into a container view and set the autoresizingMask to flexible width and height. You can then apply any constraints needed to the container view.

The code below simply creates a MKMapView which takes up the whole screen. From there, you could add buttons to the container view that are constrained to float 30 points from the bottom (which is what I needed to do).

self.mapContainerView = [[UIView alloc] initWithFrame:CGRectZero];
self.mapContainerView.translatesAutoresizingMaskIntoConstraints = NO;

self.mapView = [[MKMapView alloc] initWithFrame:self.mapContainerView.frame];
self.mapView.showsUserLocation = YES;
self.mapView.delegate = self;
self.mapView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self.mapContainerView addSubview:self.mapView];

[self.view addSubview:self.mapContainerView];

[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"|[_mapContainerView]|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(_mapContainerView)]];

[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[_mapContainerView]" options:0 metrics:nil views:NSDictionaryOfVariableBindings(_mapContainerView)]];

As an aside: Reveal has been invaluable in debugging my auto layout issues.

Slides From The Broadsheet Talk For Refresh Dublin

These are the slides from my talk in the Science Gallery for Refresh Dublin. All the links mentioned in the slides are below.

Top of the Posts

The top 5 posts (in reverse order):

What Got People Going?

The top 5 most commented posts (in reverse order):

The Apps

iPhone code: https://github.com/kmonaghan/KMWordPress
Android code: https://github.com/kmonaghan/Broadsheet.ie-Android

2013/7/30 Clarification on App Download numbers

The numbers shown are for the last 12 months (like the rest of the stats) not the total downloads. The iPhone app has around 27K total downloads which is why the user numbers are higher than the total downloads shown.

Your Broadsheet.ie Android app has arrived

Screenshot_2013-06-09-12-23-01

Finally, more than two and a half years after my iOS version was released I’ve built an Android app for Broadsheet.ie and it’s available now on the Google Play store.

The app doesn’t quite have feature parity with the iOS version but is close enough that it warrants release (especially considering the clamouring for it from the readers). I will be actively developing it over the summer in step with some updates to the iOS app.

The Android fragmentation issue means I’ve not been able to test it on all platforms, but I’ve made an effort to ensure it works on the top 10 devices that access the website. Hopefully the app won’t look too bad outside of these.

Think you can do better?

As with the iOS version of the app, the code is available on GitHub under the MIT license. I do this not in the hope that someone will come along and fix bugs or improve it but in case someone else finds it useful and wants to use it.

I would, of course, be delighted if someone actually did create a pull request…

And now over to you

The Android using section of our readers have been very vocal about wanting an app. When presented with evidence of lower engagement on the site from Android the lack of an app has been blamed (an opinion which I don’t subscribe too – it seems more like Android users don’t really use their devices compared to iOS).

The only way developers are going to take Android seriously is if people actually use their phones and download apps. So grab the app today and make this developer a happy man!

Eclipse, ADT, Maven, m2e, Android Connector setup

I’m looking at some Android development at the moment in work after being immersed in iOS development for the last few years. Switching tools always has a bit of a learning curve and this post documents what’ve setup so far. I’ve had a few false starts so this might come in useful to someone else.

Since pretty much everything I do these days app wise involved consuming some sort of REST API, I went looking for a library to handle that end of things. I came across Robospice which at first glance fits the bill for what I want. It uses Maven for project and dependency management.

As I’ve not really used Java I’ve never used Maven in anger and had some difficult in setting it up properly. While there are instructions out there, they all assume some working knowledge of how Eclipse, Maven or the ADT works so not ideal for a complete beginner. There was a lot of googling and reading Stack Overflow before it finally all worked.

Here’s the steps I followed to get it running on my iMac:

  • Download the Android SDK as the ADT bundle and install
  • Set the environment variable ANDROID_HOME to point to the sdk directory
  • Run ‘android update sdk –no-ui –all –force’ (android is under tools in the sdk folder. Also, this can take a while as it downloads everything)
  • Open ADT and install the Marketplace Client via ‘Install new software…’ under ‘Help’
  • Install Eclipse Plug-in Development Environment via ‘Install new software…’ under ‘Help’
  • Install M2E Plugin via ‘Install new software…’ under ‘Help’ using the URL http://download.eclipse.org/technology/m2e/releases
  • Install Maven 3 if you have an older version (or none) on your system (instructions on how to do so here)
  • Install Egit from the Eclipse Marketplace
  • Install Android Configurator from the Eclipse Marketplace (search for ‘android m2e’)

After all the restarts, you should be now at a stage where you can import Maven projects.

There’s a couple of more steps before you’re able to create a Maven project:

  • Start creating a new Maven Project
  • In ‘Select an Archetype’, click on ‘Add Archetype…’
  • Set ‘Archetype Group Id’ to ‘de.akquinet.android.archetypes’
  • Set ‘Archetype Artifact Id’ to ‘android-quickstart’
  • Set ‘Archetype Version’ to ‘1.0.8’

You can then continue on creating your project. Once it’s created you may see the error Project ‘skillpages-android’ is missing required source folder: ‘src/test/java’ “. This is a known issue and here’s two solutions to this:

  1. Create the directory and refresh the project
  2. Update the Android Configurator from the URL http://rgladwell.github.com/m2e-android/updates/master/

I will note that after I updated the plugin, it broke creating new projects for me.  But I’m not sure if that was something I did or an issue with it. I ended up removing and reinstalling it.

Hopefully this will help someone else bootstrap themselves into Android development and not just left fruitlessly searching.

Broadsheet.ie iPhone App 2.0

For the last few months I’ve been picking away at a new Broadsheet app for the iPhone.  It’s finally been released to world so it’s time to talk about it and some of the changes.

Raison D’être

The original version of the app was released in January 2011 and bar some minor bug fixes released in March 2011, it has gotten little attention since then.  While the app has been well received, there’s various bugs with commenting, sharing, post rendering and loading new posts.

The app also looks very tired and old compared to its peers so a bit of a more modern look wouldn’t go astray never mind the fact that none of the image assets were updated for retina displays.

What’s New

IMG_1714

IMG_1715

IMG_1719Straight off, for those on an iPhone 5, the app is no longer letterboxed.

There’s a new layout which disposes of the need for a tab bar by moving the information and tip tabs into the nav bar and eliminating of the gallery and video tabs.  The purpose gallery tab has disappeared as Broadsheet now posts galleries as images inline rather than using a javascript gallery.

The post archive is now searchable via a search bar which is hidden at the top of the post list.  While the search is powered by the not-great standard WordPress search, it does open up more content to the user.

Down on the bottom right there’s a fullscreen button.  This hides the status and navigation bars giving you an extra 64 pixels of space to gaze lovingly on the content.  When in fullscreen mode, there’s a little back arrow at the bottom left to help you navigate between screens.

Tapping an image in a post now brings you to that image in a gallery of all images associated with the post.  You can now easily zoom the image and swipe between the other images associated with the post.

IMG_1718IMG_1717

There’s no need to return to the post list screen to navigate between posts.  Dragging the screen down will load the next post while dragging up will load the previous.  This turns into an infinite scroll for posts as long as there are more posts to view.  The post list screen will also be updated with the extra posts.

The comment view is now threaded as well as rendering people’s avatars (which are generated from Gravatar) properly. Now all we have to do is get people to sign up for their own avatar.  Comments can also be replied to directly as well as creating new posts.

Touch me

A big change from the original app is the use of gestures through out for navigation.  Swiping left and right brings you between the post list, a post and the post comments.  This allows for quick and easy navigation.

Swiping left on a comment allows you to reply directly to it, providing a secondary access method to the reply button.

IMG_1710 IMG_1711
On a post screen, the available controls are revealed with a long touch, putting the buttons just above your finger tip. These allow you to view comments, make a comment and share the post.

A Bit of Help

IMG_1713

Gestures and hidden navigation is all well and good but it can be hard for users to discover.  This is easily solved with a couple of help screens which appear the first time you hit the post screen or go full screen.  These very quickly show you what you can do using some great gesture icons from Mobile Tuxedo.

Down The Line

There has been a consistent call for an iPad version of the app.  I have started on making the app universal (i.e. works on both iPhone and iPad from the same download) but for the initial release I decided that getting the iPhone version right was more important.  Hopefully I’ll complete the iPad changes over the next few months and release that as an update.

Other Platforms

An Android and Windows Mobile version of the app are in development and should be released soon.

You can download the app from the Apple App Store and if you have the previous app already installed you should be able to update.

Property Valuation Estimator

The property tax is a bit of a mess. First it was to be self-assessment but now Revenue is going to send you an estimate of their own which you can then dispute.

Ronan Lyons has come up with a nice way of estimating the value of your house based on work he’s been doing on property prices.

house-valuation

A table and some tapping of numbers is all well and good, but we know you’re lazy so we’ve whipped up a simple form to do all the calculating for you!



Obviously there’s caveats, so back to Ronan to explain them:

Clearly, this is by no means meant to capture every last factor affecting property values. (One simple extension is number of bathrooms – roughly speaking, every additional bathroom is associated with a 10% higher price.) This model captures just under two-thirds of variation in house prices in Ireland, which – given the small number of factors included – is pretty good. But there’s still a third out there to explain. (Including effects for areas within counties would explain a significant chunk of the remaining variation, as it happens.) On average this will be right, and it will for the vast majority of cases be close but of course there are always properties that have unobserved factors that dwarf what matters for most homes. The method underpinning the figures above explicitly excludes outliers, so as to better improve the estimates for the vast majority of homes.
The table above is based on 60,000 listings on Daft.ie over the year 2012, and allows for the fact that prices varied throughout the year. “Aha”, a sceptic might say, “these are only asking prices and sure we all know they are ”. As it happens, some pretty detailed research comparing asking and transaction prices shows they move together remarkably tightly, once controls for location and size are included (as they are here). Properties that sell typically sell for about 10% less than their asking price, so for that reason the starting point of €108,000 is actually 90% of the figure returned by the model. The key thing about the model is what it tells us about relativities (prices between counties), not necessarily levels.
Lastly, lest there be any confusion, I offer this table as a public service but can’t offer it as any more than what it is – one academic economist’s analysis of the market.

[A version of this post also appeared on Broadsheet.ie]

A Broadsheet New Year

It’s that time of year where you look back and see how things went.  So without further ado, here’s how Broadsheet.ie did in the last year.

The Big Numbers

Year-on-year there has been:

  • 110% increase in visits to just under 12.5 million
  • 95% increase in unique visitors to a smidgin over 3 million
  • 127% increase in pageviews to 29.1 million

Where Are Your People From?

The lion’s share of visits (72%) were from Ireland as you’d expect.  After that it drops off very quickly with the UK (10%), USA (5%), Australia (1%) and Germany (1%) rounding out the top 5.

Within Ireland, Dublin accounts for 57% of traffic and Cork 3% so we can be excused for a slight bias towards the capital.

Mucky Minds All Round

It will come as no surprise that the top three posts of the year were all mucky and not safe for work (even possibly life).

How They’re Finding Us

Apart from the usual crowd that put in some form of ‘Broadsheet’ as the search term, the top five search terms just re-enforces the idea that the readers have dirty minds with Rosanna Davison appearing twice.

  • rosanna davison
  • niamh horan
  • rosanna davison playboy
  • katie taylor
  • mario balotelli

Mario appears there because whenever he does something mad on the pitch or the news, people find the ‘Mario Balotelli: What A Legend‘ post.

The Window You Look At The Internet Through

Chrome dominates with 33% of users (up 7%), with the increase taking a chunk out of Firefox (21%) and Internet Explorer (17%).

Microsoft is slowly losing the OS battle with it slipping 4% to 61% of traffic while OS X (20%) and Linux (1.1%) both changed by under .5% each

About 16% of traffic comes from mobile devices and iOS is the big winner there accounting for 11%.

Have an Appy New Year

The much neglected iPhone App had 9,249 downloads last year.  For something that was thrown together over a couple of days Christmas two years ago, it does okay for itself.

An update is in the works at the moment which has some interesting things in it.

That’s all for now – there’ll be the usual Broadsheet birthday post later in July with more stat porn.

Previously:

Broadsheet – Entering the Terrible Twos
A year in the Broadsheet

Stasi-esque

There have been several tragic deaths in the last few months that have been attributed to “cyberbullying”, the most recent involving Shane McEntee.

Since then TDs have been complaining that people have been venting their anger over the recent budget cuts via social media and fear a larger campaign next year due the inevitable abortion debate.

Now rather than figuring out why people are angry or using the existing channels on the various services to report abuse, the calls for regulation has begun.

Daragh O’Brien has written an excellent post (spurred on by a tweet about a report on Six One news) on why this is typical knee-jerk nonsense from people who want to seen doing something but haven’t actually thought it through.

He breaks down why such calls for regulation is a bad idea into three broad reasons. To start with is a philosophical question:

Bad Idea Reason #1 – What is Identity?

Requiring people to post comments, write blogs, or tweet under their own identity creates a clear and public link between the public persona and the private individual. The supporters of any such proposal will argue that this is a deterrent to people making harsh or abusive comments. However, in a fair society that respects fundamental rights, it is important to think through who else might be impacted by a “real names” policy.

In Ireland, people who would be affected by a “real names” policy in social comment would include:

  • Public servants who cannot comment publicly on government policy but may be affected by it
  • Survivors of abuse
  • People with mental health concerns or problems
  • Whistleblowers
  • Celebrities.

A real names policy would require that every time Bono tweets or blogs about Ireland, Irishness, or Irish Government policies he would have to do it under the name Paul David Hewson.

Add to that the massive technical headache that real names cause software developers leads us on to the next problem:

Bad Idea Reason #2 – How will it work exactly?

If verifiable identities are required for comment, then how exactly would a small personal blog that is used to exercise my mental muscles outside of my work persona (domestic use) be expected to handle the overhead of verifying the identity of commenters in a verifiable way.

Would I be expected to get people to register with the blog and provide evidence of ID? Would I be able to get a grant to help implement secure processes to obtain and process copies of passports and drivers’ licenses? Or will the State just require that I shut up… shop? Would the State indemnify me if this blog was compromised and data held on it about the identity of others was stolen?

It’s always easy to make a wild statement about something being built (like a real names database), but when someone with a bit of technical know how comes along it falls like a house of cards.  Concerns about the data being stolen are often ignored until it actually happens, as it did with South Korea’s “real name” database.

Finally, we have issue of laws hanging around beyond their sell by date

Bad Idea Reason #3 – The logical principle must be technology neutral

Blogging, tweeting, social media… these are all technologies for self-expression and social interaction that barely existed five years ago and where unheard in the mainstream of a decade ago. Therefore any regulation that requires identification of commenters must be framed in such a way as to anticipate new technologies or new applications of existing technology or risk near instant obsolescence. Therefore the regulation would need to be technology neutral. Which means that, in order to avoid it being discriminatory and to ensure it has the fullest possible effect, it would need to be applicable to other forms of technology.

Laws continue to exist until they are actively repealed (as evidenced by the recent highlighting of Section 58 of the Offences Against the Person Act 1861).  Our TDs are not technical gurus (as they are displaying in spades here) and would not be expected to have enough vision to see what’s coming next year never mind 5 or 10 years down the line.  If there was to be regulation it would need to be worded very carefully or it becomes a barrier to newer, innocent developments.

That’s all well and good, but the wails of “THINK OF THE CHILDREN” could possibly drown it all out. Daragh gives a chilling example from a talk by security researcher Mikko H. Hypponen that we can draw direct parallels with:

In the 1980s in the communist Eastern Germany, if you owned a typewriter, you had to register it with the government. You had to register a sample sheet of text out of the typewriter. And this was done so the government could track where text was coming from. If they found a paper which had the wrong kind of thought, they could track down who created that thought. And we in the West couldn’t understand how anybody could do this, how much this would restrict freedom of speech. We would never do that in our own countries.

If a direct line can be drawn from something the Stasi would do to a law that is being discussed, you’re doing something badly wrong.

The Stasi are long gone and it might be dismissed as fear mongering and not comparing like to like.  International best practice would be to compare potential laws with those existing in other countries.  South Korea’s law (brought in for similar reasons) has been struck down by their constitutional court as it was prior censorship and “violated citizens’ privacy, was technically difficult to enforce and was ineffective at stopping online criticism”.  On the other hand, China has just introduced their version to crack down on dissent online about corruption in the government.  In Germany, the right to have an anonymous account in enshrined in law (German Telemedia Act) and a German data commissioner is taking Facebook to task over its real name policy which forbids pseudonyms.

So what to do about bullying online?  Well, Daragh points out lawmakers don’t have to do much as there’s already laws such as the Non-Fatal Offences against the Person Act 1997 (for instance section 10 covers harassment) that can be used.  The laws may need a small bit of tweaking to bring them fully up-to-date but that is preferable to a raft of new, badly thought out legislation.

Broadsheet has its own problems with anonymous posters but we would fight to the death for your right to be able to post anonymously (but break the law you’ll be hung out to dry).

But really, this is all beautifully summed up in a tweet:

 

Calling The Tweet Police

2012: the year the political and media classes turned on internet users (via @tjmcintyre)

Oireachtas committee to examine social media role

No need for legislation to curb harassment from social media trolls

RTE probe after ‘deplorable’ tweet attack on senator

Legislation is not the answer to abuse on social media