Я делаю класс, который берет два изображения 'cv :: Mat' и выводит разницу вращения между ними. Ошибка появляется в строке 13 getImageRotation.h, когда я объявляю функцию getGoodFeatures. Функция берет изображение, сохраняет все полезные функции в векторе и возвращает этот вектор. Я добавлю вывод консоли и код ниже.
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 ';'