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

Posted

技术标签:

【中文标题】错误:“getRotationMatrix2D”未在此范围内声明【英文标题】:error: 'getRotationMatrix2D' was not declared in this scope 【发布时间】:2016-04-01 09:45:05 【问题描述】:

我是 NDK 和 OpenCv 的新手。正在尝试编译一些本机 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_

【问题讨论】:

还有很多其他内容不在范围内...请显示您的标题包含语句或尝试using namespace cv 请检查我的更新... 问题已解决.. 我自己的 JNI 文件夹结构和 OpenCv 分发存在一些问题。谢谢。 【参考方案1】:

在你的 HairAnalysisUtils.cpp 添加一行

#include "opencv2/imgproc.hpp"

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

【讨论】:

以上是关于错误:“getRotationMatrix2D”未在此范围内声明的主要内容,如果未能解决你的问题,请参考以下文章

图片处理-opencv-3.图像缩放、旋转、翻转、平移

仿射变换

旋转和平移

opencv 图片旋转

旋转和平移 代码2

裁剪给定角度的图像