【问题标题】:Error error C3861: 'cvPyrSegmentation': identifier not found错误错误 C3861:“cvPyrSegmentation”:找不到标识符
【发布时间】:2013-12-31 02:10:42
【问题描述】:

你能帮帮我吗???在下面执行编码时出错。我是使用 OpenCV 的新手。我的老师是谷歌先生和你们这方面的专家。

IntelliSense:标识符“cvPyrSegmentation”未定义

错误错误C3861:'cvPyrSegmentation':找不到标识符

#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <stdlib.h>
#include <stdio.h>


 static void help(void)
{
  printf("\nThis program present the function of pyramid segmentation which is   
        cvcvPyrSegmentation()\n""we can controlled the value of threshold by creating 
        the taskbar\n""Usage :\n");            
}

IplImage*  image[2] = { 0, 0 }, *image0 = 0, *image1 = 0;
CvSize size;

int  w0, h0,i;
int  threshold1, threshold2;
int  l,level = 4;
int sthreshold1, sthreshold2;
int  l_comp;
int block_size = 1000;
float  parameter;
double threshold;
double rezult, min_rezult;
int filter = CV_GAUSSIAN_5x5;
CvConnectedComp *cur_comp, min_comp;
CvSeq *comp;
CvMemStorage *storage;

CvPoint pt1, pt2;



static void START_SEGMENT(int a)
{
  (void) a;
  cvPyrSegmentation (image0, image1, storage, &comp, level, threshold1+1,  
  threshold2+1);

  cvShowImage("Segmentation", image1);
}

int main( int argc, char** argv )
{
  char* filename;

  help();

  filename = argc == 2 ? argv[1] : (char*)"C:/Users/acer/Documents/Visual Studio   
  2012/Projects/me2.jpg";

  if( (image[0] = cvLoadImage( filename, 1)) == 0 )
{
  help();
  printf("Cannot load fileimage - %s\n", filename);
  return -1;
}


  cvNamedWindow("Source", 0);
  cvShowImage("Source", image[0]);

  cvNamedWindow("Segmentation", 0);

  storage = cvCreateMemStorage ( block_size );

  image[0]->width &= -(1<<level);
  image[0]->height &= -(1<<level);

  image0 = cvCloneImage( image[0] );
  image1 = cvCloneImage( image[0] );
  // segmentation of the color image
  l = 1;
  threshold1 =255;
  threshold2 =30;

  START_SEGMENT(1);

  sthreshold1 = cvCreateTrackbar("Threshold1", "Segmentation", &threshold1, 255,   
  START_SEGMENT);
  sthreshold2 = cvCreateTrackbar("Threshold2", "Segmentation",  &threshold2, 255, 
  START_SEGMENT);

  cvShowImage("Segmentation", image1);
  cvWaitKey(0);

  cvDestroyWindow("Segmentation");
  cvDestroyWindow("Source");

  cvReleaseMemStorage(&storage );

  cvReleaseImage(&image[0]);
  cvReleaseImage(&image0);
  cvReleaseImage(&image1);

  return 0;
}

 #ifdef _EiC
 main(1,"pyramid_segmentation.c");
 #endif

【问题讨论】:

  • 您在编译或运行代码时是否出现此错误?
  • 您是否将正确的链接标志传递给编译器?
  • 当我尝试“构建解决方案”时出现此错误...如果出现错误我肯定无法运行它...你知道我的编码有什么问题吗??
  • 你错过了必要的头文件。尝试添加#include
  • 确定??因为当我添加 #include 时,还有另一个错误..No such file or directory.. ?_?

标签: c++ undefined-function


【解决方案1】:

从表面上看,您没有包含正确的标题。

#include <opencv2/imgproc/imgproc_c.hpp>

【讨论】:

  • 除非该函数被定义为宏,否则不应引发致命异常。
  • @randomusername:嗯?没有人说过“致命的例外”。 OP 出现编译器错误,因为他尝试使用的函数尚未在该范围内声明。
  • @ApipNate:我已经帮你了,不用乞求了。我已经为你设置了正确的路径——现在你必须自己执行下一步,使用文档,甚至只是自己阅读头文件,以找出去哪里。
  • 谢谢...请看这个问题(stackoverflow.com/questions/20548462/…)。我无法回答我自己的问题,所以我从一个新问题开始。
  • @ApipNate:将其作为一个新问题发布是正确的做法™。
【解决方案2】:

您的编译器无法理解命令cvPyrSegmentation 的含义。您的解决方案是:

  1. 该特定函数实际上并不存在,并且您正在阅读错误的文档(我在官方 API 中找不到该函数)。

  2. 您可能缺少一个头文件。回到你所遵循的任何例子,并完全按照他们演示的方式重做。如果您没有遵循示例,请找到一个示例;这几乎总是解决问题的最佳方法。

  3. 您可能缺少一些必须传递给编译器的标志。如果您熟悉使用库,您就会明白我的意思。如果您不熟悉在 C 中使用库,请先查看如何使用一个非常简单的库。我建议 GMP。

如果找不到示例,请发表评论,我会在找到后编辑其中一个。

【讨论】:

  • 就在the reference
  • @LightnessRacesinOrbit 然后我纠正了。除非 OP 使用的 OpenCV 版本与该文档不匹配。
【解决方案3】:

在函数 cvPyrSegmentation 所在的位置添加#include&lt;cvaux.h&gt;

PS:所有文件都被包括在内以保证......

#include<cv.h>
#include <cvaux.h>
#include <opencv\cxcore.hpp>
#include <opencv.hpp>
#include <nonfree.hpp>
#include <core/core.hpp>
#include <imgproc/imgproc.hpp>
#include <imgproc/imgproc_c.h>
#include <highgui.h>

【讨论】:

    【解决方案4】:

    您需要: 1) 首先包含 legacy.hpp (通常在 opencv2/legacy/legacy.hpp)

    2) 确保 legacy.hpp 位于链接器输入的“附加依赖项”中(我假设您使用的是 Visual C++)

    【讨论】:

      猜你喜欢
      • 2013-03-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多