/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
after that, update homebrew;
brew update
You can now install opencv.
brew install homebrew/science/opencv
Homebrew will start to install opencv. This process may take a little longer.
When opencv installed, you will see this summary;
You can see opencv location in this summary.
Test Program
This program just shows a image. Write in terminal window;
vim testcode.cpp
you will see vim editor.
We will write our code here. Press i to enter insert mode and write this program.
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main( int argc, char** argv )
{
Mat image;
image = imread(“/home/Users/64pin/Pictures/testpic.jpg”, CV_LOAD_IMAGE_COLOR); // Read the file
if(! image.data ) // Check for invalid input
{
cout << "Could not open or find the image" << std::endl ;
return -1;
}
namedWindow( "Display window", WINDOW_AUTOSIZE );// Create a window for display.
imshow( "Display window", image ); // Show our image inside it.
waitKey(0); // Wait for a keystroke in the window
return 0;
}
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main( int argc, char** argv )
{
Mat image;
image = imread(“/home/Users/64pin/Pictures/testpic.jpg”, CV_LOAD_IMAGE_COLOR); // Read the file
if(! image.data ) // Check for invalid input
{
cout << "Could not open or find the image" << std::endl ;
return -1;
}
namedWindow( "Display window", WINDOW_AUTOSIZE );// Create a window for display.
imshow( "Display window", image ); // Show our image inside it.
waitKey(0); // Wait for a keystroke in the window
return 0;
}
Press ESC to exit insert mode. Then, write this command and press enter;
:wq
Now, we should compile this cpp file.
g++ -o cvtestprog opencvtest.cpp -I/usr/local/Cellar/opencv/2.4.12_2/include -L/usr/local/Cellar/opencv/2.4.12_2/lib -lopencv_highgui.2.4.12 -lopencv_core.2.4.12
cvtestprog is executable file. Run program.
./cvtestprog
Result:
0 yorum :
Post a Comment