Andre Coetzer
Andre Coetzer

Reputation: 169

Finding the Sky/Ground separation in OpenCV

I am trying to detect the horizon in an image, and return a mask of the sky (or inverted as the ground). While there seems to be many uses for it, I am battling to find a good solution. What's worse is that it seems like such a simple problem, and most humans have NO issue in detecting the horizon.

The following makes it harder:

What I have tried for now is to use a colour filter limiting it to low saturations, then find contours and detect and fill the largest contour. After this, I flood fill the area above the contour. This does work, but I still can't imagine this problem to be so difficult.

I am writing the code in Delphi XE8, using a OpenCV wrapper, but answers or ideas in any other language are welcome!

Upvotes: 14

Views: 8312

Answers (3)

AlkindiX
AlkindiX

Reputation: 40

My answer is completely different. You can link OpenCV with magnetic compass to separate the sky from the ground.

You can do this in OpenCV with iOS. Link your OpenCV project with the compass which is in IPhone. Then separate the sky from the ground like what compass App did that .

See https://i.sstatic.net/P00oG.jpg

Upvotes: 1

Andrey  Smorodov
Andrey Smorodov

Reputation: 10850

You can try convolutional deep neural networks, like http://mi.eng.cam.ac.uk/projects/segnet/ for example, or train your own similar network.

Upvotes: 0

renonsz
renonsz

Reputation: 591

In my understanding you are looking for a horizontal line - if exists at all - to separate the exclusively sky part from the rest.

I would compute image statistics row by row, so a horizontal histogram or similar to that.

It could be based even on a global threshold or a custom 'skyness' function. Decide somehow (intensity, hue) if pixels are sky or not and count them within scanlines.

Then half the image horizontally, sum row values for both parts and decide which direction your 'horizont line' should be moved. Half that part too and continue until you get to the proper row. With such a binary search you should be able to extract which line separates sky from foreground. If it is the first line: no sky, if last: all sky.

This problem has surely has other approaches so I am looking forward to seeing more suggestions.

Upvotes: 3

Related Questions