Cannot compile houghline.cpp after installing openCV 2.4.9 [closed]

asked 2014-10-14 04:37:51 -0600

When i compile openCV2.4.9 sample code using following command

g++ houghlines.cpp -o application `pkg-config --cflags --libs opencv`

I get following errors, any suggestions pointers to solve it ?

houghlines.cpp:6:17: error: ‘cv’ is not a namespace-name
 using namespace cv;
                 ^
houghlines.cpp:6:19: error: expected namespace-name before ‘;’ token
 using namespace cv;
                   ^
houghlines.cpp: In function ‘int main(int, char**)’:
houghlines.cpp:20:5: error: ‘Mat’ was not declared in this scope
     Mat src = imread(filename, 0);
     ^
houghlines.cpp:20:9: error: expected ‘;’ before ‘src’
     Mat src = imread(filename, 0);
         ^
houghlines.cpp:21:8: error: ‘src’ was not declared in this scope
     if(src.empty())
        ^
houghlines.cpp:28:9: error: expected ‘;’ before ‘dst’
     Mat dst, cdst;
         ^
houghlines.cpp:29:11: error: ‘src’ was not declared in this scope
     Canny(src, dst, 50, 200, 3);
           ^
houghlines.cpp:29:16: error: ‘dst’ was not declared in this scope
     Canny(src, dst, 50, 200, 3);
                ^
houghlines.cpp:29:31: error: ‘Canny’ was not declared in this scope
     Canny(src, dst, 50, 200, 3);
                               ^
houghlines.cpp:30:19: error: ‘cdst’ was not declared in this scope
     cvtColor(dst, cdst, COLOR_GRAY2BGR);
                   ^
houghlines.cpp:30:25: error: ‘COLOR_GRAY2BGR’ was not declared in this scope
     cvtColor(dst, cdst, COLOR_GRAY2BGR);
                         ^
houghlines.cpp:30:39: error: ‘cvtColor’ was not declared in this scope
     cvtColor(dst, cdst, COLOR_GRAY2BGR);
                                       ^
houghlines.cpp:49:5: error: ‘vector’ was not declared in this scope
     vector<Vec4i> lines;
     ^
houghlines.cpp:49:12: error: ‘Vec4i’ was not declared in this scope
     vector<Vec4i> lines;
            ^
houghlines.cpp:49:19: error: ‘lines’ was not declared in this scope
     vector<Vec4i> lines;
                   ^
houghlines.cpp:50:32: error: ‘CV_PI’ was not declared in this scope
     HoughLinesP(dst, lines, 1, CV_PI/180, 50, 50, 10 );
                                ^
houghlines.cpp:50:54: error: ‘HoughLinesP’ was not declared in this scope
     HoughLinesP(dst, lines, 1, CV_PI/180, 50, 50, 10 );
                                                      ^
houghlines.cpp:53:15: error: expected ‘;’ before ‘l’
         Vec4i l = lines[i];
               ^
houghlines.cpp:54:27: error: ‘l’ was not declared in this scope
         line( cdst, Point(l[0], l[1]), Point(l[2], l[3]), Scalar(0,0,255), 3, CV_AA);
                           ^
houghlines.cpp:54:37: error: ‘Point’ was not declared in this scope
         line( cdst, Point(l[0], l[1]), Point(l[2], l[3]), Scalar(0,0,255), 3, CV_AA);
                                     ^
houghlines.cpp:54:73: error: ‘Scalar’ was not declared in this scope
         line( cdst, Point(l[0], l[1]), Point(l[2], l[3]), Scalar(0,0,255), 3, CV_AA);
                                                                         ^
houghlines.cpp:54:79: error: ‘CV_AA’ was not declared in this scope
         line( cdst, Point(l[0], l[1]), Point(l[2], l[3]), Scalar(0,0,255), 3, CV_AA);
                                                                               ^
houghlines.cpp:54:84: error: ‘line’ was not declared in this scope
         line( cdst, Point(l[0], l[1]), Point(l[2], l[3]), Scalar(0,0,255), 3, CV_AA);
                                                                                    ^
houghlines.cpp:57:25: error: ‘imshow’ was not declared in this scope
     imshow("source", src);
                         ^
houghlines.cpp:60:13: error: ‘waitKey’ was not declared in this scope
     waitKey();
             ^
edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by StevenPuttemans
close date 2014-10-16 03:10:07.915668

Comments

I am afraid there is something wrong with your configuration. Just built 2.4.9 and this houghlines sample and it builds perfectly fine. I am using the following g++ command g++ houghlines.cpp houghlines.o pkg-config opencv --libs

StevenPuttemans gravatar imageStevenPuttemans ( 2014-10-14 04:47:46 -0600 )edit

thank you for reply StevenPuttemans, i am using it in virtualbox installed ubuntu ? do you think that can be a problem ?, what steps you followed to build and install OpenCV 2.4.9 ?

AnkurTank gravatar imageAnkurTank ( 2014-10-14 05:39:49 -0600 )edit

Just the following simple steps

git clone <a href="http://github.com/Itseez/opencv.git">http://github.com/Itseez/opencv.git</a> opencv/
cd opencv/
git checkout 2.4
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=DEBUG -D CMAKE_INSTALL_PREFIX=/usr/local ..
sudo make -j 10
sudo make install

Than afterwards using the pkg-config generator does all the tricks for me.

StevenPuttemans gravatar imageStevenPuttemans ( 2014-10-14 06:52:26 -0600 )edit

I had followed the steps you have mentioned except pkg-config generator, if possible any hint on that ?

AnkurTank gravatar imageAnkurTank ( 2014-10-14 06:58:43 -0600 )edit

its just adding that config line in your optional linker settings. That is what I do in codeblocks.

StevenPuttemans gravatar imageStevenPuttemans ( 2014-10-14 07:09:46 -0600 )edit
1

Hi StevenPuttemanas, i followed the steps you mentioned and finally i could solve the issue. Before that i had used the opencv2_4_9.sh to install but it didn't work. Thank you for help

AnkurTank gravatar imageAnkurTank ( 2014-10-15 13:57:30 -0600 )edit