c++ - 当我声明vector <Point2f>函数时,opencv c++ “missing ' ;' before ' <' ”

标签 c++ opencv

我正在制作一个接受两个'cv::Mat'图像并输出它们之间旋转差异的类。当我声明函数“getGoodFeatures”时,错误出现在“getImageRotation.h”的第13行。该函数拍摄图像并将所有良好特征存储在 vector 中,然后返回该 vector 。我将在下面添加控制台输出和代码。

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

控制台输出:
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 ';'

最佳答案

“ vector ”是变量类型吗?
如果我是对的,为什么没有该变量的名称?
您应该命名该变量

关于c++ - 当我声明vector <Point2f>函数时,opencv c++ “missing ' ;' before ' <' ”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61278428/

相关文章:

c++ - 在我看来,[basic.lookup.argdep]/3 中的示例中有两个候选函数用于调用 g(parm, 1)

c# - 如何在 Emgu 上为视频或相机捕捉进行白色 Blob 跟踪?

c++ - OpenCV - 去除凸性缺陷(Python 到 C++)

c++ - 如何初始化和使用静态结构

c++ - QThread - 使用槽 quit() 退出线程

C++ 编译器优化 - 为什么需要 constexpr?

c++ - 返回局部结构变量的成员变量是否安全?

c++ - ARM 平台的数据转换(来自 x86/x64)

c++ - OpenCV 在 VideoCapture grab() 上挂起

android - Android-找不到* .apk