1

I'm making a class that takes two 'cv::Mat' images and outputs the rotational difference between them. The error comes in at line 13 of 'getImageRotation.h' when I declare the function 'getGoodFeatures'. The function takes an image and stores all the good features in a vector and returns that vector. I will add the console output and code below.

main.cpp:

#include <opencv2/opencv.hpp>
#include <iostream>
#include <stdlib.h>
#include "getImageRotation.h"

using namespace std;
using namespace cv;

Mat image1 = imread("left.png");//read the two images I want to compare
Mat image2 = imread("right.png");

float rotFactor; //the float returned by the class

int main()//main
{
    getImageRotation rotDetect; //make a object
    rotFactor = rotDetect.detect(image1,image2);//get the rotFactor from the two images

    cout << rotFactor << endl; //print out the rot factor
    return 0;
}

getImageRotation.h

#pragma once
#include <opencv2/opencv.hpp>

using namespace cv;

class getImageRotation
{
    private:

        int imageSize = 400;//resize the image for faster processing
        Mat resizeImage(Mat image, int width, int height);//return image with specified dimension perameters
        vector<Point2f> getGoodFeatures(Mat input);//returns a vector of good keypoints //ERROR

    public:

        getImageRotation();
        ~getImageRotation();

        float detect(Mat image1, Mat image2);//main method of the class, returns angle difference between the two images

};

getImageRotation.cpp

#include "getImageRotation.h"
#include <iostream>

using namespace std;

getImageRotation::getImageRotation()
{
    cout << "started" << endl;
}

getImageRotation::~getImageRotation()
{

}

float getImageRotation::detect(Mat image1in, Mat image2in)
{
    //check if images are empty, if so return 0
    if ((image1in.empty())|| (image2in.empty()))
    {
        return 0;
    }
    //clone images
    Mat image1 = image1in.clone();
    Mat image2 = image2in.clone();
    //first resize bolth images
    image1 = resizeImage(image1,imageSize,imageSize);
    image2 = resizeImage(image2,imageSize,imageSize);
    //convert images to grayscale
    cvtColor(image1, image1, CV_BGR2GRAY);
    cvtColor(image2, image2, CV_BGR2GRAY);
    //get good feature points for both images
    vector<Point2f> keypoints1 = getGoodFeatures(image1);
    vector<Point2f> keypoints2 = getGoodFeatures(image2);
    //get orb feature points for both images 
    //make new feature data of orb features that match the good features in image 1
    //make new feature data of orb features that match the good features in image 2
    //return mean rotational difference between images
    return 0.0;
}

Mat getImageRotation::resizeImage(Mat input, int width, int height)
{
    if (input.empty())//if image is emty then return the input
    {
        return input;
    }

    Mat newImage;
    resize(input,newImage, Size(width,height));//resize input to img
    return newImage;
}

vector<Point2f> getImageRotation::getGoodFeatures(Mat input)//ERROR
{
    vector<Point2f> features;
    goodFeaturesToTrack(input,features,20,0.01,10);
    return features;
}

Console Output:

getImageRotation.h(12,9): error C2143: syntax error: missing ';' before '<'
getImageRotation.h(12,17): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
getImageRotation.h(12,45): error C2238: unexpected token(s) preceding ';'
getImageRotation.cpp(35,31): error C3861: 'getGoodFeatures': identifier not found
getImageRotation.cpp(36,31): error C3861: 'getGoodFeatures': identifier not found
getImageRotation.cpp(56,35): error C2039: 'getGoodFeatures': is not a member of 'getImageRotation'
getImageRotation.h(6): message : see declaration of 'getImageRotation'
getImageRotation.h(12,9): error C2143: syntax error: missing ';' before '<'
getImageRotation.h(12,17): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
getImageRotation.h(12,45): error C2238: unexpected token(s) preceding ';'
463035818_is_not_an_ai
  • 109,796
  • 11
  • 89
  • 185
  • 2
    Add all the necessary `#include`s first and try again. – DeiDei Apr 17 '20 at 18:41
  • 1
    You need to `#include ` in any file that needs to know what a `vector` is. See https://en.cppreference.com/w/cpp/container/vector Under the title it will tell you which header is required. – JohnFilleau Apr 17 '20 at 18:41
  • 1
    Or do you want to use `cv::Vector`? – JohnFilleau Apr 17 '20 at 18:42
  • 7
    `vector` is supposed to be `std::vector` ? Then use the fully qualified name and get rid of the bad habit of `using namespace std;` – 463035818_is_not_an_ai Apr 17 '20 at 18:42
  • 1
    read here on why adding `using namespace std;` also in your header (and the include) **is not** the solution : [Why is “using namespace std;” considered bad practice?](https://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice) – 463035818_is_not_an_ai Apr 17 '20 at 18:44
  • `using namespace ...` don't *ever* do that in a header file. It's (debatable) bad practice in implementation files, but in *headers* it's a pretty clear *no, don't ever do that*. – Jesper Juhl Apr 17 '20 at 18:48
  • Thank you I figured out the problem. It was from the bad coding practice of the use of "using namespace". I feel like a idiot. – Ghirardelli Apr 17 '20 at 19:23

1 Answers1

-1

is "vector" a variable type? if i'm right why there is no name of that variable? you should name that variable

김진오
  • 49
  • 4
  • this is not an anwer. You will have enough rep to comment soon, but if you write answers that are not answers you might get downvoted and have to wait longer – 463035818_is_not_an_ai Apr 18 '20 at 21:35