简体   繁体   中英

opencv c++ “missing ';' before '<' ” when i declare a vector<Point2f> function

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 ';'

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM