Thrill-seeking social media users have gone to great lengths — and heights — for the perfect selfie.

Daredevils on Instagram, Twitter and YouTube have earned online notoriety for photos and videos taken at the top of mountains, on the edges of cliffs or teetering at the top of a communications tower.

There's a real art to the best of them: a high angles and wide shots of a cityscape behind the subject can induce a sense of vertigo in seconds.

But a few have met a grisly end in the process. And the number of so-called "selfie deaths" is growing.

That's why a group of researchers from Carnegie Mellon University studied over 120 selfie deaths in the hopes of creating a system that might discourage others from putting their lives at risk.

The project started after Hemank Lamba, a computer science PhD student, was disturbed by a report earlier this year of a student's death while taking a selfie.

"Our group is always interested in working on topics and technologies that have a real-world impact on our society or culture, so we jumped in and started digging more into it," he said.

127 selfie deaths since 2014

In the provocatively titled report "Me, Myself and My Killfie," the team reportedly found a total of 127 deaths from 2014 to September 2016 that were linked to someone taking or attempting to take a selfie.

The number of deaths per year has risen from 15 in 2014, to 39 in 2015 to 73 so far recorded in 2016.

The greatest number of deaths happened in India, with a whopping 76 recorded fatalities. Mumbai police in January established a list of "no-selfie zones" after an 18-year-old girl drowned while taking a selfie.

The next most common locations were Pakistan with nine and the U.S., with eight.

A tool analyses multiple elements in a selfie, including the elevation of the subject compared to the steep drop in elevation nearby. (Hemank Lamba, Megha Arora et al.)

Most deaths involved people falling from a great height. The second-most common factor was water: the study cites one case in India where multiple people drowned after one person leaned back to take a selfie, tipping their boat and throwing everyone overboard.

Other factors include taking a selfie close to rail tracks before being hit by a train, while holding a weapon such as a gun, or while close to an animal that later attacked the person taking the photo.

Perhaps unsurprisingly, most were 24 years old or younger. But while women typically take more selfies than men, "men are more prone to taking dangerous selfies, and accounted for roughly 75.5 per cent of all the casualties," according to the report.

Selfie safety app

Using the information gleaned from these reports, the researchers built a tool that could identify whether a selfie posted on social media was taken in a dangerous or potentially fatal location.

They ran the tool through more than 138,000 selfies posted on Twitter, which looked for indicators like a steep drop in elevation from one point to another — signifying someone standing on top of a radio tower, for example — closeness to rail tracks or the presence of potentially harmful items like a handgun.

The experiment was mostly successful; the tool was able to identify these elements with a 73.6 per cent accuracy rate.

The team hopes to use the tool to eventually build an app that can warn people in real-time whether they're about to take a dangerous selfie, or are approaching a dangerous location where selfies should not be taken.

If you're wondering what the point would be of an app that tells you you're about to take a dangerous selfie while already in said dangerous location, don't worry, they've thought about that too.

Instead, the app could have a map marked with "red zones" noted as particularly dangerous terrain, or links to news reports of previous selfie-related injuries that occurred there in the past — before you've reached the very edge of a cliff or train platform, for example.

It could even prevent you from launching your phone's camera app before moving to a safer location.

Making Pokemon Go safer?

With enough data, these tools could be used for other apps as well, to warn smartphone owners prone to walking while texting, or staring at their phones while hunting for pocket monsters in Pokemon Go.

The team hopes this project will spread awareness that people need to remain cognizant of the environment around them while taking selfies — or just using their personal devices in general. That's especially the case in unfamiliar locations like tourist locations and around vehicles like fast-moving trains.

"With the growing trend of dangerous selfies, it becomes important to spread awareness of the inherent hazards associated with people risking their lives simply for the sake of recognition on a virtual forum," the study reads.

After all, you can't take those likes and shares with you when you're gone.