How to get segment-geospatial working on Microsoft Planetary Computer
Just a quick one today to document the solution to a problem I ran into earlier today.
I was using Microsoft Planetary Computer to access some Landsat satellite data, and I wanted to run it through the Segment Anything model from Meta, to segment out agricultural fields from the image. I tried to do this using the segment-geospatial Python package.
Unfortunately I got an error that libgl1.so
could not be found. Luckily this is documented on the segment-geospatial installation page and you just need to run:
apt update; apt install -y libgl1
But, there’s a problem: Microsoft Planetary Computer does not allow apt
access from their container images. I tried every way I could think of to install this, and did a lot of googling, but couldn’t find anything.
Eventually I found the answer in this issue which somehow didn’t appear in my earlier Google searches. It seems that the libgl1
library is a dependency of OpenCV, which segment-geospatial uses interally, and you can get around this dependency by installing the opencv-python-headless package. And it was just that simple – running
pip install opencv-python-headless
completely solved the problem and let me get going running segment-geospatial.
I hope this post helps someone else with the same problem as me – and hopefully turns up better in relevant Google searches.
If you found this post useful, please consider buying me a coffee.
This post originally appeared on Robin's Blog.
Categorised as: How To, Programming, Python, Remote Sensing
Hi! I’ve been playing around with Microsoft Planetary Computer today. I’d like to segment areas burned by wildfires. I came across your post. Would you mind sharing your notebook? I’d be curious to see how you implemented the segment-geospatial package.
Thanks for considering!
Hi – unfortunately I don’t think my notebook would be very useful to you, and I can’t really share it anyway as it was part of some work for a client. It was heavily based on the examples fro the segment-geospatial documentation. In my case I wasn’t actually using data from Planetary Computer – I had a TIFF file that I’d uploaded to use instead – but I imagine to use PC data you’d need to save out to some sort of file first (from what I remember, I don’t think segment-geospatial supported reading directly from xarray or similar).