错误:'getRotationMatrix2D'未在此范围内声明

时间:2016-04-01 09:45:05

标签: android c++ opencv android-ndk

我是NDK和OpenCv Stuff的新手。尝试编译一些本机C ++代码。

编译时我遇到了一些错误error: 'getRotationMatrix2D' was not declared in this scope

请帮助我解决这个问题,因为我不知道原生的东西。

感谢。

内联是.cpp文件功能代码

void RotateImage(const Mat input, Mat &rotated, float angle)
{
    // create the rotation transformation matrix
    Point2f img_center(input.cols/2.0F, input.rows/2.0F);
    Mat rot_mat = getRotationMatrix2D(img_center, angle, 1.0);

    // transform the image
    warpAffine(input, rotated, rot_mat, input.size()); 
}

除了上面提到的错误之外,我也遇到了很多其他错误。

在编译时内联错误日志。

/home/vivek/workspace/Test/jni/HairAnalysisUtils.cpp: In function 'void RotateImage(cv::Mat, cv::Mat&, float)':
/home/vivek/workspace/Test/jni/HairAnalysisUtils.cpp:10:59: error: 'getRotationMatrix2D' was not declared in this scope
  Mat rot_mat = getRotationMatrix2D(img_center, angle, 1.0f);
                                                           ^
/home/vivek/workspace/Test/jni/HairAnalysisUtils.cpp:13:50: error: 'warpAffine' was not declared in this scope
  warpAffine(input, rotated, rot_mat, input.size()); 
                                                  ^
/home/vivek/workspace/Test/jni/HairAnalysisUtils.cpp: In function 'void imfill(cv::Mat, cv::Mat&)':
/home/vivek/workspace/Test/jni/HairAnalysisUtils.cpp:23:77: error: 'findContours' was not declared in this scope
     findContours(dist_8u, contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE);
                                                                             ^
/home/vivek/workspace/Test/jni/HairAnalysisUtils.cpp:28:54: error: 'drawContours' was not declared in this scope
   drawContours(imgDilate, contours, i, 255, CV_FILLED);
                                                      ^
/home/vivek/workspace/Test/jni/HairAnalysisUtils.cpp: In function 'int GetFoldersInDirectory(const string&, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >&)':
/home/vivek/workspace/Test/jni/HairAnalysisUtils.cpp:58:2: error: 'DIR' was not declared in this scope
  DIR *dirp;
  ^
/home/vivek/workspace/Test/jni/HairAnalysisUtils.cpp:58:7: error: 'dirp' was not declared in this scope
  DIR *dirp;
       ^
/home/vivek/workspace/Test/jni/HairAnalysisUtils.cpp:61:38: error: 'opendir' was not declared in this scope
  if ((dirp = opendir(dir_path.c_str())) == NULL) {
                                      ^
/home/vivek/workspace/Test/jni/HairAnalysisUtils.cpp:66:16: error: 'rewinddir' was not declared in this scope
  rewinddir(dirp);
                ^
/home/vivek/workspace/Test/jni/HairAnalysisUtils.cpp:67:26: error: 'readdir' was not declared in this scope
  while (dp = readdir(dirp))
                          ^
/home/vivek/workspace/Test/jni/HairAnalysisUtils.cpp:69:24: error: invalid use of incomplete type 'struct GetFoldersInDirectory(const string&, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >&)::dirent'
   sFileName = string(dp->d_name, dp->d_name + strlen(dp->d_name));
                        ^
/home/vivek/workspace/Test/jni/HairAnalysisUtils.cpp:59:9: error: forward declaration of 'struct GetFoldersInDirectory(const string&, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >&)::dirent'
  struct dirent *dp;
         ^
/home/vivek/workspace/Test/jni/HairAnalysisUtils.cpp:69:36: error: invalid use of incomplete type 'struct GetFoldersInDirectory(const string&, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >&)::dirent'
   sFileName = string(dp->d_name, dp->d_name + strlen(dp->d_name));
                                    ^
/home/vivek/workspace/Test/jni/HairAnalysisUtils.cpp:59:9: error: forward declaration of 'struct GetFoldersInDirectory(const string&, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >&)::dirent'
  struct dirent *dp;
         ^
/home/vivek/workspace/Test/jni/HairAnalysisUtils.cpp:69:56: error: invalid use of incomplete type 'struct GetFoldersInDirectory(const string&, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >&)::dirent'
   sFileName = string(dp->d_name, dp->d_name + strlen(dp->d_name));
                                                        ^
/home/vivek/workspace/Test/jni/HairAnalysisUtils.cpp:59:9: error: forward declaration of 'struct GetFoldersInDirectory(const string&, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >&)::dirent'
  struct dirent *dp;
         ^
/home/vivek/workspace/Test/jni/HairAnalysisUtils.cpp:73:6: error: 'DT_DIR' was not declared in this scope
   if(DT_DIR == dp->d_type)
      ^
/home/vivek/workspace/Test/jni/HairAnalysisUtils.cpp:73:18: error: invalid use of incomplete type 'struct GetFoldersInDirectory(const string&, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >&)::dirent'
   if(DT_DIR == dp->d_type)
                  ^
/home/vivek/workspace/Test/jni/HairAnalysisUtils.cpp:59:9: error: forward declaration of 'struct GetFoldersInDirectory(const string&, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >&)::dirent'
  struct dirent *dp;
         ^
/home/vivek/workspace/Test/jni/HairAnalysisUtils.cpp:81:22: error: 'closedir' was not declared in this scope
  (void) closedir(dirp);
                      ^
/home/vivek/workspace/Test/jni/HairAnalysisUtils.cpp: In function 'bool GetFilesInDirectory(const string&, const string&, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >&)':
/home/vivek/workspace/Test/jni/HairAnalysisUtils.cpp:115:2: error: 'DIR' was not declared in this scope
  DIR *dirp;
  ^
/home/vivek/workspace/Test/jni/HairAnalysisUtils.cpp:115:7: error: 'dirp' was not declared in this scope
  DIR *dirp;
       ^
/home/vivek/workspace/Test/jni/HairAnalysisUtils.cpp:117:38: error: 'opendir' was not declared in this scope
  if ((dirp = opendir(dir_path.c_str())) == NULL) {
                                      ^
/home/vivek/workspace/Test/jni/HairAnalysisUtils.cpp:121:16: error: 'rewinddir' was not declared in this scope
  rewinddir(dirp);
                ^
/home/vivek/workspace/Test/jni/HairAnalysisUtils.cpp:122:25: error: 'readdir' was not declared in this scope
  while(dp = readdir(dirp))
                         ^
/home/vivek/workspace/Test/jni/HairAnalysisUtils.cpp:125:30: error: invalid use of incomplete type 'struct GetFilesInDirectory(const string&, const string&, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >&)::dirent'
         sFileName = string(dp->d_name, dp->d_name + strlen(dp->d_name));
                              ^
/home/vivek/workspace/Test/jni/HairAnalysisUtils.cpp:116:9: error: forward declaration of 'struct GetFilesInDirectory(const string&, const string&, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >&)::dirent'
  struct dirent *dp;
         ^
/home/vivek/workspace/Test/jni/HairAnalysisUtils.cpp:125:42: error: invalid use of incomplete type 'struct GetFilesInDirectory(const string&, const string&, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >&)::dirent'
         sFileName = string(dp->d_name, dp->d_name + strlen(dp->d_name));
                                          ^
/home/vivek/workspace/Test/jni/HairAnalysisUtils.cpp:116:9: error: forward declaration of 'struct GetFilesInDirectory(const string&, const string&, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >&)::dirent'
  struct dirent *dp;
         ^
/home/vivek/workspace/Test/jni/HairAnalysisUtils.cpp:125:62: error: invalid use of incomplete type 'struct GetFilesInDirectory(const string&, const string&, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >&)::dirent'
         sFileName = string(dp->d_name, dp->d_name + strlen(dp->d_name));
                                                              ^
/home/vivek/workspace/Test/jni/HairAnalysisUtils.cpp:116:9: error: forward declaration of 'struct GetFilesInDirectory(const string&, const string&, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >&)::dirent'
  struct dirent *dp;
         ^
/home/vivek/workspace/Test/jni/HairAnalysisUtils.cpp:127:12: error: 'DT_DIR' was not declared in this scope
         if(DT_DIR == dp->d_type)
            ^
/home/vivek/workspace/Test/jni/HairAnalysisUtils.cpp:127:24: error: invalid use of incomplete type 'struct GetFilesInDirectory(const string&, const string&, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >&)::dirent'
         if(DT_DIR == dp->d_type)
                        ^
/home/vivek/workspace/Test/jni/HairAnalysisUtils.cpp:116:9: error: forward declaration of 'struct GetFilesInDirectory(const string&, const string&, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >&)::dirent'
  struct dirent *dp;
         ^
/home/vivek/workspace/Test/jni/HairAnalysisUtils.cpp: In function 'void getRangeFilteredImage(const cv::Mat&, cv::Mat&, int)':
/home/vivek/workspace/Test/jni/HairAnalysisUtils.cpp:331:14: error: 'getStructuringElement' is not a member of 'cv'
  Mat strel = cv::getStructuringElement(MORPH_RECT, Size(kernelSize, kernelSize));
              ^
/home/vivek/workspace/Test/jni/HairAnalysisUtils.cpp:331:40: error: 'MORPH_RECT' was not declared in this scope
  Mat strel = cv::getStructuringElement(MORPH_RECT, Size(kernelSize, kernelSize));
                                        ^
/home/vivek/workspace/Test/jni/HairAnalysisUtils.cpp:332:43: error: 'dilate' was not declared in this scope
  dilate(gray, dilateImg, strel, Point(0,0));
                                           ^
/home/vivek/workspace/Test/jni/HairAnalysisUtils.cpp:333:41: error: 'erode' was not declared in this scope
  erode(gray, erodeImg, strel, Point(0,0));
                                         ^
/home/vivek/workspace/Test/jni/HairAnalysisUtils.cpp: In function 'void CallBackFunc(int, int, int, int, void*)':
/home/vivek/workspace/Test/jni/HairAnalysisUtils.cpp:514:15: error: 'EVENT_LBUTTONDOWN' was not declared in this scope
  if( event == EVENT_LBUTTONDOWN )
               ^
make: *** [/home/vivek/workspace/Test/obj/local/armeabi-v7a/objs/ndksetup/HairAnalysisUtils.o] Error 1

更新

#ifndef _HAIRANALYSISUTILS_H_
#define _HAIRANALYSISUTILS_H_

#include <include/CoreCommons.h>
#include <opencv/cv.h>
#if (defined WIN32 || defined WIN64)
    #include <time.h>
    #include <windows.h>
    #include <winsock.h>
#else 
    #include <sys/time.h>
    #include <time.h>
    #include <unistd.h>
    #define Sleep(x) usleep((x)*1000);
#endif

using namespace cv;

static int sub_to_ind(int *coords, int *cumprod, int num_dims);
static void ind_to_sub(int p, int num_dims, const int size[], int *cumprod, int *coords);
void    getLocalEntropyImage(const Mat &gray, Rect &roi, Mat &entropy);
void    getRangeFilteredImage(const Mat &gray, Mat& filterImg, int kernelSize);
void    RotateImage(const Mat input, Mat &rotated, float angle);
void    imfill(const Mat imgThresh, Mat& imgDilate);
string  GetFilenameFromPath(string filepath, bool stripExtension);
string  GetFolderPathFromFilePath(string filepath);
bool    GetFilesInDirectory(const string& dir_path, const string& ext_to_match, vector <string> &files);
int     GetFoldersInDirectory(const string& dir_path, vector <string> &folders);
Rect    getInscribedRect(const Mat &fiber);
void    ImageAdjust(const Mat1b& src, Mat1b& dst);
//void  EstimateSharpness(const Mat& image,int sharpness);      //added to remove bright edge region
void    CallBackFunc(int event, int x, int y, int flags, void * userdata);

#endif // _HAIRANALYSISUTILS_H_

1 个答案:

答案 0 :(得分:0)

在HairAnalysisUtils.cpp中添加一行

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text">

如果它已经存在,那么只需搜索包含“getRotationMatrix2D”文本的* .hpp文件。 声明在HairAnalysisUtils.cpp模块中引入了名为“getRotationMatrix2D”的实体。如果您不向链接器提供声明的实体的 Definition ,那么您可能会遇到链接器错误。