How do I compile c++ code in terminal. Below i have some code to apply Gaussian
ID: 663073 • Letter: H
Question
How do I compile c++ code in terminal. Below i have some code to apply Gaussian Filter on an image using OpenCV. I have tried compling using the code
g++ Project2.cpp -o Project2 `pkg-config --cflags --libs opencv` && ./Project2
and it gives me a whole list of errors saying directory not found.
---------------------------------------------------------------------------------------------------------
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <opencv2/core/core.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main()
{
Mat image = imread("//u//oowens//First.jpg");
int rows=image.rows;
int cols=image.cols;
if (image.empty())
{
cout << "Cannot load image!" << endl;
return -1;
}
cout<<"the output for matrix of pixels";
//code to access pixel values of an image
cout<<" before blur";
for (int i = 0; i <rows; i++)
{
Vec3b *ptr = image.ptr<Vec3b>(i);
for (int j = 0; j < cols; j++)
{
Vec3b pixel = ptr[j];
//cout<<pixel<<" ";
}
cout<<" ";
}
imshow("Image", image);//displaying image
waitKey(0);
Mat image1=image.clone();//cloning image
GaussianBlur( image, image1, Size( 7, 7), 0, 0 );//applying Gaussian filter
cout<<" after blur";
//code to access pixel values of an image
for (int i = 0; i < rows; i++)
{
Vec3b *ptr = image1.ptr<Vec3b>(i);
for (int j = 0; j < cols; j++)
{
Vec3b pixel = ptr[j];
//cout<<pixel<<" ";
}
cout<<" ";
}
imshow("image1:",image1);//displaying image1
waitKey(0);
}
Explanation / Answer
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <opencv2/core/core.hpp>
these files and you this code cpp file must be in same directory.
Mat image = imread("//u//oowens//First.jpg");
also check if the file directory u r providing right,
if possible put this image file in also in same directory.
use eclipse if possible there these directory problems are very less.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.