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

Error error C3861: 'cvPyrSegmentation': identifier not found

本文关键字:错误 标识符 找不到 cvPyrSegmentation C3861      更新时间:2023-10-16

你能帮我吗???执行以下代码时出错。我是一个使用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 taskbarn""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 - %sn", 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 <opencv2/imgproc/imgproc_c.hpp>

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

  1. 这个特定的函数实际上并不存在,而且您读错了文档(我在官方API中找不到这个函数)。

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

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

如果你找不到一个例子,请留下评论,我一找到就会编辑一个。

在函数cvPyrSessionation所在的位置添加#include<cvaux.h>

附言:所有文件都包括在内,以保证。。。

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

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

2) 确保legacy.hpp在链接器输入的"附加依赖项"中(我假设您使用的是visual C++)