Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Macports, compiling using G++ in Terminal

I installed OpenCV for mac with MacPorts by following this video: https://www.youtube.com/watch?v=mJWVz3ncRoo When I ran this script as shown in that video (compiled with the G++ compiler), it runs nicely and I've put in this here into the Terminal: g++ main.cpp -o main -I/opt/local/include -L/opt/local/lib -lopencv_highgui.2.4.9 -lopencv_core.2.4.9 C++ code:

"#include" <opencv2 core="" core.hpp=""> "#include" <opencv2 highgui="" highgui.hpp=""> int main() { cv::Mat image = cv::imread("/Users/Mike/Desktop/download.jpeg"); cv::namedWindow("OpenCV First Project"); cv::imshow("Image", image); cv::waitKey(5000); return 1; }

The code above works just fine, but the sample code from this site "http://opencvlover.blogspot.ch/2011/07/accesing-camera-using-opencv.html" showed up some errors in the Terminal. I've put this into the Terminal: g++ camera.cpp -o camera -I/opt/local/include -L/opt/local/lib -lopencv_highgui.2.4.9 -lopencv_cv.2.4.9 -lopencv_iostream.2.4.9 d and the Terminal outputted this: camera.cpp:2:10: fatal error: 'cv.h' file not found "#include" <cv.h> ^ 1 error generated.

"#include" < iostream > "#include" < cv.h > "#include" < highgui.h >

using namespace std; char key; int main() { cvNamedWindow("Camera_Output", 1); //Create window CvCapture* capture = cvCaptureFromCAM(CV_CAP_ANY); //Capture using any camera connected to your system while(1){ //Create infinte loop for live streaming

    IplImage* frame = cvQueryFrame(capture); //Create image frames from capture
    cvShowImage("Camera_Output", frame);   //Show image frames on created window
    key = cvWaitKey(10);     //Capture Keyboard stroke
    if (char(key) == 27){
        break;      //If you hit ESC key loop will break.
    }
}
cvReleaseCapture(&capture); //Release capture.
cvDestroyWindow("Camera_Output"); //Destroy Window
return 0;

}

Why am I getting this error, although I linked it correctly? Can you recommend me any tutorial, that uses a G++ compiler on a OS X with the Terminal? THANKS. Marsstar

Macports, compiling using G++ in Terminal

I installed OpenCV for mac with MacPorts by following this video: https://www.youtube.com/watch?v=mJWVz3ncRoo https://www.youtube.com/watch?v=mJWVz3ncRoo

When I ran this script as shown in that video (compiled with the G++ compiler), it runs nicely and I've put in this here into the Terminal: Terminal: g++ main.cpp -o main -I/opt/local/include -L/opt/local/lib -lopencv_highgui.2.4.9 -lopencv_core.2.4.9 C++ code:-lopencv_core.2.4.9

"#include" <opencv2 core="" core.hpp=""> "#include" <opencv2 highgui="" highgui.hpp=""> int main() { cv::Mat image = cv::imread("/Users/Mike/Desktop/download.jpeg"); cv::namedWindow("OpenCV First Project"); cv::imshow("Image", image); cv::waitKey(5000); return 1; }image description

The code above works just fine, but the sample code from this site "http://opencvlover.blogspot.ch/2011/07/accesing-camera-using-opencv.html" showed up some errors in the Terminal. I've put this into the Terminal: g++ camera.cpp -o camera -I/opt/local/include -L/opt/local/lib -lopencv_highgui.2.4.9 -lopencv_cv.2.4.9 -lopencv_iostream.2.4.9 d -lopencv_iostream.2.4.9

and the Terminal outputted this: camera.cpp:2:10: fatal error: 'cv.h' file not found "#include" <cv.h> ^ 1 error generated.this:

"#include" < iostream > "#include" < cv.h > "#include" < highgui.h >

using namespace std; char key; int main() { cvNamedWindow("Camera_Output", 1); //Create window CvCapture* capture = cvCaptureFromCAM(CV_CAP_ANY); //Capture using any camera connected to your system while(1){ //Create infinte loop for live streaming

    IplImage* frame = cvQueryFrame(capture); //Create image frames from capture
    cvShowImage("Camera_Output", frame);   //Show image frames on created window
    key = cvWaitKey(10);     //Capture Keyboard stroke
    if (char(key) == 27){
        break;      //If you hit ESC key loop will break.
    }
}
cvReleaseCapture(&capture); //Release capture.
cvDestroyWindow("Camera_Output"); //Destroy Window
return 0;

}image description

Why am I getting this error, although I linked it correctly? Can you recommend me any tutorial, that uses a G++ compiler on a OS X with the Terminal? THANKS. Marsstar