Counting Brazilians Protesters with Mathematica

Last weekend, 16th march 2016, we had the biggest protests ever registered here in Brasil against a Government.

In TV, for each city, we always see three numbers for protesters count. The organizer’s number, the police number and an institute number, and they always show completely discrepant results. As you can see, for Av. Paulista in São Paulo we have.

  • Organizer’s number: …2.5 millions
  • Polices’s number:… 1.4 millions
  • Datafolha’s number: …0.5 millions

From 33’ to 36’ seconds of this video we can see the image of people in the streets.

The challenge is: Can I count them with Mathematica and help the Brazilian democracy to be a bit more precise?

Here is my humble wrong attempt to do it:

img = Binarize[img];
m = ImageDifference[DeleteSmallComponents[img, 20], img];
(m =  MorphologicalComponents[m])// Colorize

Length@ComponentMeasurements[m,"Count"]
(*4953*)

So I get the worst estimative ever! How can this be improved?

UPDATE

A better approach: Inspired by this post

pts = 200{{0,0},{0,1},{1,1},{1,0}};
width=100;
height=100;
ptsFlat={{0,0},{width,0},{width,height},{0,height}};
LocatorPane[Dynamic[pts],
  Dynamic[
  {err,transform} = FindGeometricTransform[pts,ptsFlat,TransformationClass->"Perspective"];
  grid = Table[transform[{x,y}],{x,0,width,5},{y,0,height,5}];
   Show[img,
     Graphics[{
       {EdgeForm[Red], Transparent, Polygon[pts]},
       {Red, MapIndexed[Text[Style[#2[[1]], 14], #1, {1, 1}] &, pts]},
	   {Red,Line/@grid,Line/@Transpose[grid]}
     }], ImageSize-> 500
    ]
  ]
]

Using: 10 people per square, we get: (400 x 10/60) x 2710 = 180k

Yeah, that is bad. It looks to be around a bazillion Brazilians out there. Mixed with the sporadically weighing in Uruguayans.

I like the idea of it, here are some thoughts:

  1. the resolution of the image is much too low to count individual heads, especially further away
  2. A best approach probably would be:
    a) accurately estimate the density of people at a convenient spot on the picture (preferably a higher resolution picture)
    b) scale the density with the depth (distance) in the picture
    c) differentiate picture between crowd area and other stuff like buildings etc
    e) integrate scaled people density over crowded area

@Daniel, what you’re saying is there’s no estimate of accuracy or diagnostics, eg image resolution warning as per Kay’s comment. If so, how would you know computed result are accurate vs mis-estimates? People want to use image analysis in all sorts of fields, eg cancer prognosis from radiology.

I think you read way too much into my misguided comment. That said, I do not know the answers to the questions you raise but certainly they are important questions. Others may have some ideas worth sharing.

@Daniel, understood, and this particular problem is a user application, not WL specific. However, be aware that there are increasing mis-classification problems with built-in methods, eg date interpretation: http://mathematica.stackexchange.com/questions/79241/improving-semantic-interpretation-of-dates.

@Rodrigo Murta this is perhaps a statistically simple question if you know the area of the street? There is interesting theory of crowd density and flow: Crowd Safety and Risk Analysis (see also some images below). If you know length and width of the street roughly, you can pick approximate low or high risk density depending whether the crowd is moving or not. Then it is just multiplication.

ezgif-1528645777.gif