CONFIGURE NETBEANS C++ WITH OPENCV
ref: http://www.technical-recipes.com/2015/configure-netbeans-to-use-opencv-in-linux-environments/
1. Create C++ Application Project
File->New Project->C/C++ ->C/C++ Application->Next->’Give it the Project name and the location’ AND CHOOSE C++11->Finish
2. Configure the compiler:
Right Click The project->Properties->Build->C++ Compiler->’Include Directories’: /usr/local/include/opencv ->Apply
3. Add the opencv libraries:
Right Click The project->Properties->Build->Linker->’Additional Library Directories’: /usr/local/lib ->Apply
Right Click The project->Properties->Build->Linker->’Libraries’: Add -> Click Add Library THEN GO TO /usr/local/lib ->CLICK (SIMULTANEOUSLY) libopencv_core.so, libopencv_highgui.so, libopencv_imgproc.so, libopencv_imgcodecs.so
OK
NOTE: TO SHOW VIDEO CAPTURE, ADD libopencv_videoio.so
4. Test
in main.cpp:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /* * File: main.cpp * Author: teddy * * Created on April 13, 2016, 10:04 AM */ #include <opencv2/opencv.hpp> #include <iostream> using namespace cv; using namespace std; /* * */ int main(int argc, char** argv) { cout<<"OPENCV VERSION: "<<CV_VERSION<<endl; return 0; } |
BUILD & RUN:
OPENCV VERSION: 3.1.0
RUN FINISHED;
exit value 0;
real time: 0ms; user: 0ms; system: 0ms
SHOW IMAGE main.cpp:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
#include <opencv2/highgui/highgui.hpp> #include <iostream> using namespace cv; using namespace std; int main(int argc, char** argv) { Mat img=imread("/home/teddy/opencv/samples/data/messi5.jpg",CV_LOAD_IMAGE_UNCHANGED); if(img.empty()){ cout<<"Error: Image can't be opened. Check the path and the image is exist"; return -1; } string winname="Show Image"; namedWindow(winname,CV_WINDOW_AUTOSIZE); imshow(winname,img); waitKey(0); destroyWindow(winname); return 0; } |
VIDEO CAPTURE main.cpp (add linker libopencv_videoio.so) :
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
/* * File: main.cpp * Author: teddy * * Created on April 13, 2016, 10:04 AM */ #include <opencv2/core/core.hpp> #include <opencv2/videoio/videoio.hpp> #include <opencv2/highgui/highgui.hpp> #include <opencv2/imgproc/imgproc.hpp> #include <iostream> using namespace cv; using namespace std; /* * */ int main(int argc, char** argv) { VideoCapture stream(0); if(!stream.isOpened()){ cout<<"Cannot open camera"; } bool isClosed=false; Mat cameraFrame; while(isClosed!=true){ stream.read(cameraFrame); imshow("Camera Stream",cameraFrame); if(waitKey(30)>=0){ isClosed=true; } } //cout<<"OPENCV VERSION: "<<CV_VERSION<<endl; return 0; } |