问题
Could you please help me???Getting an error when executing coding below. I'm a newbie using OpenCV. My teacher is Mr. Google and you guys who expert in this field.
IntelliSense: identifier "cvPyrSegmentation" is undefined
Error error C3861: 'cvPyrSegmentation': identifier not found
#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
回答1:
You didn't include the right header, by the looks of things.
#include <opencv2/imgproc/imgproc_c.hpp>
回答2:
Your compiler can't understand what the command cvPyrSegmentation
means. Your solutions are:
That particular function doesn't actually exist and you are reading the wrong documentation (I can't find that function in the official API).
You might be missing a header file. Go back to what ever example you are following and redo it exactly as they demonstrate. If you're not following an example, find one; this is almost always the best way to solve a problem.
You might be missing a number of flags that you have to pass to the compiler. If you're familiar with using libraries you'll know what I mean. If you're not familiar with using libraries in C, look up how to use a very simply one first. I suggest the GMP.
If you can't find an example, leave a comment, and I'll edit one in once I find one.
回答3:
add #include<cvaux.h>
where the function cvPyrSegmentation lies.
PS: all files to be included for assurance...
#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:
You need to : 1) first include legacy.hpp (usually on opencv2/legacy/legacy.hpp)
2) make sure that legacy.hpp is in the "additional dependencies" of the linker input (I am assuming you are using visual C++)
来源:https://stackoverflow.com/questions/20547340/error-error-c3861-cvpyrsegmentation-identifier-not-found