FriendlyFire
Posts: 2
Joined: Thu Oct 11, 2018 10:28 pm

[Raspbian 9 (stretch)] Is opencv installed by default ? If so how do you use it!

Thu Oct 11, 2018 10:39 pm

As the title states, I'm on Stretch (on a Pi zero W btw). I need to do some fairly simple image processing, and was happy to find out it has a default install of opencv2.4.9, as that should be enough.

I just can't seem to get any code to find it. I'm working in C++, and get the error "Package opencv was not found in the pkg-config search path". Which is fair enough because although pkg-config was already installed, when I checked I found it's search path was blank. Trying to find where opencv was installed turned out to be totally fruitless.

I then decided to test in python, because it seems like the Pi comes setup for python specifically, and >>import cv2 fails as well!

Using >>sudo apt-get remove libopencv* I get the option to remove the opencv packages. So it sure seems like they are on here, but I can't figure out how to find/use them. And the only things I can find online, or this forum, talk about installing opencv from scratch. Haven't seen any that explained how to find the native install.

Am I missing something obvious? Is there a secret trick to using the installed opencv package? Should I just remove it and reinstall it "properly"?

Thanks for any help!

User avatar
topguy
Posts: 5618
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: [Raspbian 9 (stretch)] Is opencv installed by default ? If so how do you use it!

Fri Oct 12, 2018 11:25 am

At minimum you need to do a "sudo apt install libopencv-dev". Check your pkg-config after that.

But you can get a newer OpenCV if you build it yourself, and there should be a bunch of guides on the net for that.

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 23078
Joined: Sat Jul 30, 2011 7:41 pm

Re: [Raspbian 9 (stretch)] Is opencv installed by default ? If so how do you use it!

Fri Oct 12, 2018 12:34 pm

Try this link, it might help.

https://blog.piwheels.org/new-opencv-builds/
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
"My grief counseller just died, luckily, he was so good, I didn't care."

sora03
Posts: 192
Joined: Mon Dec 29, 2014 4:11 pm
Contact: Website

Re: [Raspbian 9 (stretch)] Is opencv installed by default ? If so how do you use it!

Fri Oct 12, 2018 1:11 pm

if you are using python then install opencv with pip:

Code: Select all

$ pip install opencv-python
FLOSS enthusiast, Debian user (linux-libre)

FriendlyFire
Posts: 2
Joined: Thu Oct 11, 2018 10:28 pm

Re: [Raspbian 9 (stretch)] Is opencv installed by default ? If so how do you use it!

Fri Oct 12, 2018 11:10 pm

topguy wrote:
Fri Oct 12, 2018 11:25 am
At minimum you need to do a "sudo apt install libopencv-dev". Check your pkg-config after that.

But you can get a newer OpenCV if you build it yourself, and there should be a bunch of guides on the net for that.
Appreciate the help from everyone, but this fixed the issue, thanks topguy! Never thought about it being built, but not installed.

User avatar
topguy
Posts: 5618
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: [Raspbian 9 (stretch)] Is opencv installed by default ? If so how do you use it!

Sat Oct 13, 2018 3:44 pm

Never thought about it being built, but not installed.
I'ts not really about that..

Most libraries have a standard package that includes the compiled library ( .so files ). All other software already compiled will just load this library file dynamically if they need it.
The "-dev" or developer package includes typically the additional header files ( .h/.hpp ) needed to compile new programs that also will load the ".so" files when runned.

So if you want to use a library in your programming you need to have both the "libsomething" and "libsomthing-dev" packages installed. But you usually need only to run "apt install libsomething-dev" because the other package will be a dependency and will also be installed automatically.

Return to “Troubleshooting”