Question

How do I compile c++ code in terminal. Below i have some code to apply Gaussian...

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<<"\nbefore 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<<"\t";
        }
      cout<<"\n";
    }

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<<"\nafter 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<<"\t";
        }
      cout<<"\n";
    }


imshow("image1:",image1);//displaying image1
waitKey(0);
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#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.

Add a comment
Know the answer?
Add Answer to:
How do I compile c++ code in terminal. Below i have some code to apply Gaussian...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Question 1: Fix the 2D dynamic array initialization in following code #include <iostream> using namespace std;...

    Question 1: Fix the 2D dynamic array initialization in following code #include <iostream> using namespace std; int main(){    int rows = 5; int cols = 5; int x;    int** arr = new int[rows][cols]    cin >> x; arr[x][x] = x; cout << "arr[x][x] = " << arr[x][x];    return 0; } Question 2: Fix the code to initialize the 2D array elements to x #include <iostream> using namespace std; int main(){    int rows; int cols; int x;...

  • C++ how can I fix these errors this is my code main.cpp #include "SpecialArray.h" #include <...

    C++ how can I fix these errors this is my code main.cpp #include "SpecialArray.h" #include <iostream> #include <fstream> #include <string> using namespace std; int measureElementsPerLine(ifstream& inFile) {    // Add your code here.    string line;    getline(inFile, line);    int sp = 0;    for (int i = 0; i < line.size(); i++)    {        if (line[i] == ' ')            sp++;    }    sp++;    return sp; } int measureLines(ifstream& inFile) {    // Add your code here.    string line;    int n = 0;    while (!inFile.eof())    {        getline(inFile,...

  • This is an advanced version of the game tic tac toe, where the player has to...

    This is an advanced version of the game tic tac toe, where the player has to get five in a row to win. The board is a 30 x 20. Add three more functions that will check for a win vertically, diagonally, and backwards diagonally. Add an AI that will play against the player, with random moves. Bound check each move to make sure it is in the array. Use this starter code to complete the assignment in C++. Write...

  • Given a matrix, clockwise-rotate elements in it. Please add code to problem3.cpp and the makefile. I...

    Given a matrix, clockwise-rotate elements in it. Please add code to problem3.cpp and the makefile. I have also given the main_problem3.cpp and problem3.h to test. problem3.cpp::: #include "problem3.h" // A function to rotate a matrix mat[][MAX] void rotatematrix(int m, int n, int mat[][MAX]) { // your code here    } Makefile::: all : problem3.o    g++ -o mainp3 # your code here problem3.o : problem3.h problem3.cpp    # your code here clean:    rm -f *.o mainp3 main_problem3.cpp::: #include <iostream>...

  • Linkedlist implementation in C++ The below code I have written is almost done, I only need...

    Linkedlist implementation in C++ The below code I have written is almost done, I only need help to write the definition for delete_last() functio​n. ​ Language C++ // LinkedList.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include <string> #include <iostream> using namespace std; struct Node { int dataItem;//Our link list stores integers Node *next;//this is a Node pointer that will be areference to next node in the list }; class LinkedList { private: Node *first;...

  • CONVERT CODE TO JAVA // A C++ program to Print all elements in sorted order from...

    CONVERT CODE TO JAVA // A C++ program to Print all elements in sorted order from row and // column wise sorted matrix #include<iostream> #include<climits> using namespace std;    #define INF INT_MAX #define N 4    // A utility function to youngify a Young Tableau. This is different // from standard youngify. It assumes that the value at mat[0][0] is // infinite. void youngify(int mat[][N], int i, int j) {     // Find the values at down and right sides of...

  • I need a program in c++ the same as below code but I want it to...

    I need a program in c++ the same as below code but I want it to prompt the user to enter the number of elements after that I want it to ask the user to enter the array elements #include<algorithm> #include<stdio.h> #include<string.h> #include<iostream> using namespace std; int a[50]={2,5,4,3}; bool x[100]; int N=4;//number of elements    int k=10;//target sum int sum;//current target sum int cmp(const void *a,const void *b) { return *(int *)b-*(int *)a; } void backtrace(int n) { if(sum>k) return...

  • I have to write a loop that moves the content of the dynamic array to the...

    I have to write a loop that moves the content of the dynamic array to the static array but I can't seem to figure it out. Exit Full Screen code.cpp New 1 #include <iostream> 3 using namespace std; 4 5 int main) 6 int *ptr 7 ptr -new int[5]; 8 int arr[5]; 9int x; 10 cin >> x; 11 for( int í = 0; 1 < 5; 1++) // initialization 12 13 ptr[i] x; = 14 for O//your code goes...

  • The C++ code below will compile but has a variety of runtime issues. Identify a runtime...

    The C++ code below will compile but has a variety of runtime issues. Identify a runtime issue with the program and describe how you might fix the problem. #include <iostream> #include <vector> using namespace std; //------------------------------------------------------------------------------ int main() { vector<double> temps; // temperatures double temp = 0; double sum = 0; double high_temp = 0; double low_temp = 0; while (cin >> temp) // read and put into temps temps.push_back(temp); for (int i = 0; i < temps.size(); ++i) {...

  • I just need a help in replacing player 2 and to make it unbeatable here is my code: #include<i...

    I just need a help in replacing player 2 and to make it unbeatable here is my code: #include<iostream> using namespace std; const int ROWS=3; const int COLS=3; void fillBoard(char [][3]); void showBoard(char [][3]); void getChoice(char [][3],bool); bool gameOver(char [][3]); int main() { char board[ROWS][COLS]; bool playerToggle=false; fillBoard(board); showBoard(board); while(!gameOver(board)) { getChoice(board,playerToggle); showBoard(board); playerToggle=!playerToggle; } return 1; } void fillBoard(char board[][3]) { for(int i=0;i<ROWS;i++) for(int j=0;j<COLS;j++) board[i][j]='*'; } void showBoard(char board[][3]) { cout<<" 1 2 3"<<endl; for(int i=0;i<ROWS;i++) { cout<<(i+1)<<"...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT