LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 09-19-2015, 04:23 PM   #1
baronobeefdip
Senior Member
 
Registered: Jul 2009
Distribution: Debian Squeeze
Posts: 1,267

Rep: Reputation: 32
How do I setup opencv2 on my ubuntu distribution


I have a project to do but I need opencv libraries in order to do it. I did the apt-get install commands and tried to compile the c++ file that was given to me but I got a bunch of errors. I think the libraraies are not there, or they are placed in a location that the compiler doesn't seem to be looking in. where is the compiler looking for these library files and how do I set to where the compiler will include these files when it compiles a program.
 
Old 09-19-2015, 06:27 PM   #2
norobro
Member
 
Registered: Feb 2006
Distribution: Debian Sid
Posts: 792

Rep: Reputation: 331Reputation: 331Reputation: 331Reputation: 331
Quote:
Originally Posted by baronobeefdip View Post
I did the apt-get install commands
Did you install the development package?
Code:
$ apt-get install opencv-dev
EDIT: As noted by baronofbeefdip below that should be libopencv-dev

Quote:
Originally Posted by baronobeefdip View Post
. . . I got a bunch of errors.
Please list the errors.

Here's an example command line to compile a c++/opencv program on my system:
Code:
g++ -std=c++11 main.cpp -lstdc++ $(pkg-config --libs --cflags opencv)

Last edited by norobro; 09-19-2015 at 06:41 PM.
 
Old 09-19-2015, 06:28 PM   #3
baronobeefdip
Senior Member
 
Registered: Jul 2009
Distribution: Debian Squeeze
Posts: 1,267

Original Poster
Rep: Reputation: 32
Quote:
Originally Posted by norobro View Post
Did you install the development package?
Code:
$ apt-get install opencv-dev
Please list the errors.

Here's an example command line to compile a c++/opencv program on my system:
Code:
g++ -std=c++11 main.cpp -lstdc++ $(pkg-config --libs --cflags opencv)
The errors are pretty much saying that they can't find the header files.

Just tried your apt-get command and I got an error, is there a ppa or something that I can use to fix this one.
Code:
E: Unable to locate package opencv-dev
 
Old 09-19-2015, 06:34 PM   #4
baronobeefdip
Senior Member
 
Registered: Jul 2009
Distribution: Debian Squeeze
Posts: 1,267

Original Poster
Rep: Reputation: 32
Quote:
Originally Posted by norobro View Post
Did you install the development package?
Code:
$ apt-get install opencv-dev
Please list the errors.

Here's an example command line to compile a c++/opencv program on my system:
Code:
g++ -std=c++11 main.cpp -lstdc++ $(pkg-config --libs --cflags opencv)
I just ran this command and installed all of the development files, I'll post what happens when I try to compile the program
Code:
apt-get install libopencv-dev
 
Old 09-19-2015, 06:36 PM   #5
norobro
Member
 
Registered: Feb 2006
Distribution: Debian Sid
Posts: 792

Rep: Reputation: 331Reputation: 331Reputation: 331Reputation: 331
EDIT: whoops, had this open in a tab and missed your post.

Are you still on Squeeze? What do you use as repositories?

Here is opencv-dev in Wheezy: link

Last edited by norobro; 09-19-2015 at 06:38 PM.
 
Old 09-19-2015, 06:38 PM   #6
baronobeefdip
Senior Member
 
Registered: Jul 2009
Distribution: Debian Squeeze
Posts: 1,267

Original Poster
Rep: Reputation: 32
Quote:
Originally Posted by norobro View Post
Are you still on Squeeze? What do you use as repositories?

Here is opencv-dev in Wheezy: link
I just tried to compile the program, here is what came back
Code:
/tmp/ccvvzxBm.o: In function `main':
lab1.cpp:(.text+0x5c): undefined reference to `cv::imread(std::string const&, int)'
lab1.cpp:(.text+0x1a9): undefined reference to `cv::namedWindow(std::string const&, int)'
lab1.cpp:(.text+0x1da): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'
lab1.cpp:(.text+0x21a): undefined reference to `cv::imshow(std::string const&, cv::_InputArray const&)'
lab1.cpp:(.text+0x242): undefined reference to `cv::waitKey(int)'
lab1.cpp:(.text+0x275): undefined reference to `cv::destroyWindow(std::string const&)'
/tmp/ccvvzxBm.o: In function `cv::Mat::~Mat()':
lab1.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x39): undefined reference to `cv::fastFree(void*)'
/tmp/ccvvzxBm.o: In function `cv::Mat::operator=(cv::Mat const&)':
lab1.cpp:(.text._ZN2cv3MataSERKS0_[_ZN2cv3MataSERKS0_]+0x111): undefined reference to `cv::Mat::copySize(cv::Mat const&)'
/tmp/ccvvzxBm.o: In function `cv::Mat::release()':
lab1.cpp:(.text._ZN2cv3Mat7releaseEv[_ZN2cv3Mat7releaseEv]+0x47): undefined reference to `cv::Mat::deallocate()'
collect2: error: ld returned 1 exit status
I am using Backbox Linux, the most recent reccomended version.
 
Old 09-19-2015, 06:43 PM   #7
norobro
Member
 
Registered: Feb 2006
Distribution: Debian Sid
Posts: 792

Rep: Reputation: 331Reputation: 331Reputation: 331Reputation: 331
And how did you compile it? Are you using an IDE?
 
Old 09-19-2015, 06:47 PM   #8
baronobeefdip
Senior Member
 
Registered: Jul 2009
Distribution: Debian Squeeze
Posts: 1,267

Original Poster
Rep: Reputation: 32
Quote:
Originally Posted by norobro View Post
And how did you compile it? Are you using an IDE?
I used the g++ command, I figured because it was a C++ file.
 
Old 09-19-2015, 06:57 PM   #9
norobro
Member
 
Registered: Feb 2006
Distribution: Debian Sid
Posts: 792

Rep: Reputation: 331Reputation: 331Reputation: 331Reputation: 331
What do you get with the following command?
Code:
pkg-config --libs opencv
 
Old 09-19-2015, 07:01 PM   #10
baronobeefdip
Senior Member
 
Registered: Jul 2009
Distribution: Debian Squeeze
Posts: 1,267

Original Poster
Rep: Reputation: 32
Code:
/usr/lib/x86_64-linux-gnu/libopencv_calib3d.so /usr/lib/x86_64-linux-gnu/libopencv_contrib.so /usr/lib/x86_64-linux-gnu/libopencv_core.so /usr/lib/x86_64-linux-gnu/libopencv_features2d.so /usr/lib/x86_64-linux-gnu/libopencv_flann.so /usr/lib/x86_64-linux-gnu/libopencv_gpu.so /usr/lib/x86_64-linux-gnu/libopencv_highgui.so /usr/lib/x86_64-linux-gnu/libopencv_imgproc.so /usr/lib/x86_64-linux-gnu/libopencv_legacy.so /usr/lib/x86_64-linux-gnu/libopencv_ml.so /usr/lib/x86_64-linux-gnu/libopencv_objdetect.so /usr/lib/x86_64-linux-gnu/libopencv_ocl.so /usr/lib/x86_64-linux-gnu/libopencv_photo.so /usr/lib/x86_64-linux-gnu/libopencv_stitching.so /usr/lib/x86_64-linux-gnu/libopencv_superres.so /usr/lib/x86_64-linux-gnu/libopencv_ts.so /usr/lib/x86_64-linux-gnu/libopencv_video.so /usr/lib/x86_64-linux-gnu/libopencv_videostab.so -lopencv_calib3d -lopencv_contrib -lopencv_core -lopencv_features2d -lopencv_flann -lopencv_gpu -lopencv_highgui -lopencv_imgproc -lopencv_legacy -lopencv_ml -lopencv_objdetect -lopencv_ocl -lopencv_photo -lopencv_stitching -lopencv_superres -lopencv_ts -lopencv_video -lopencv_videostab
 
Old 09-19-2015, 07:15 PM   #11
norobro
Member
 
Registered: Feb 2006
Distribution: Debian Sid
Posts: 792

Rep: Reputation: 331Reputation: 331Reputation: 331Reputation: 331
That's the same list my system has. Is your c++ file too large to post?
 
Old 09-19-2015, 07:25 PM   #12
baronobeefdip
Senior Member
 
Registered: Jul 2009
Distribution: Debian Squeeze
Posts: 1,267

Original Poster
Rep: Reputation: 32
not at all
Code:
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>
 
using namespace cv;
using namespace std;

int main( )
{
      Mat img;

      img = imread("tamucc.jpg", CV_LOAD_IMAGE_UNCHANGED); //read the image data in the file "tamucc.jpg" and store it in 'img'


    if (img.empty()) //check whether the image is loaded or not
     {
          cout << "Error : Image cannot be loaded..!!" << endl;
         
          return -1;
     } 

double rows = img.rows; // image size
double cols = img.cols;


cout<< "The image has "<<rows<<" rows and "<<cols << " columns"<<endl;

     namedWindow("MyWindow",CV_WINDOW_NORMAL);
    imshow("MyWindow", img); //display the image which is stored in the 'img' in the "MyWindow" window

    waitKey(0); //wait infinite time for a keypress

    destroyWindow("MyWindow"); //destroy the window with the name, "MyWindow"


     return 0;
}
 
Old 09-19-2015, 07:47 PM   #13
norobro
Member
 
Registered: Feb 2006
Distribution: Debian Sid
Posts: 792

Rep: Reputation: 331Reputation: 331Reputation: 331Reputation: 331
Works on my box, of course with a different jpeg file:
Code:
$ gcc -std=c++11 main.cpp  -lstdc++  $(pkg-config --libs --cflags opencv)
$ ./a.out 
The image has 389 rows and 600 columns
So something is wrong with your install. Maybe try reinstalling opencv?

Is the tamucc what i think it is? I'm in central Tejas.
 
Old 09-19-2015, 07:56 PM   #14
baronobeefdip
Senior Member
 
Registered: Jul 2009
Distribution: Debian Squeeze
Posts: 1,267

Original Poster
Rep: Reputation: 32
How do I reinstall it, because it's a fresh Linux distribution installation and a fresh install of opencv. I didn't do anything with anything on the system other than install the opencv development files.
 
Old 09-19-2015, 08:11 PM   #15
norobro
Member
 
Registered: Feb 2006
Distribution: Debian Sid
Posts: 792

Rep: Reputation: 331Reputation: 331Reputation: 331Reputation: 331
The only way I know is to remove the package first and the install it again. Probably not necessary though.

What does the following output? As root:
Code:
ldconfig -p | grep opencv
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
What distribution for home setup with gui desktop justinn Linux - Newbie 8 05-17-2013 01:24 PM
LXer: Linux Deepin: Ubuntu-Based Linux Distribution With A Beautiful GNOME Shell Setup LXer Syndicated Linux News 0 03-09-2012 08:30 PM
which linux distribution is best for server setup aliabbass Linux - General 16 01-05-2011 07:37 AM
Best distribution for server setup Mearth Linux - Newbie 4 02-25-2007 08:41 PM
what linux distribution should I use to setup an Apache web server stteng Linux - Distributions 10 04-03-2005 08:04 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 06:38 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration