《learning opencv》例5-1
#include <stdio.h>
#include <cv.h>
#include <highgui.h>
#include <stdio.h>
#include <opencv2/legacy/legacy.hpp>
//#pragma comment(lib, "opencv_legacy244.lib")
//void cvPyrSegmentation( IplImage* src, IplImage* dst, CvMemStorage* storage, CvSeq** comp, int a,int b,int c );
void f(
IplImage* src,
IplImage* dst
) {
CvMemStorage* storage = cvCreateMemStorage(0);
CvSeq* comp = NULL;
cvPyrSegmentation( src, dst, storage, &comp, 4, 200, 50 );
int n_comp = comp->total;
for( int i=0; i<n_comp; i++ ) {
CvConnectedComp* cc = (CvConnectedComp*)
cvGetSeqElem( comp, i );
// do_something_with( cc );
}
cvReleaseMemStorage( &storage );
}
int main(int argc, char** argv)
{
// Create a named window with a the name of the file.
cvNamedWindow( "pic.jpg", 1 );
// Load the image from the given file name.
IplImage* src = cvLoadImage( "pic.jpg" );
if(!src) { printf("Couldn't seem to Open %s, sorry\n","pic.jpg"); return -1;}
IplImage* dst = cvCreateImage( cvGetSize(src), src->depth, src->nChannels);
f( src, dst);
// Show the image in the named window
cvShowImage( "pic.jpg", dst );
// Idle until the user hits the "Esc" key.
while( 1 ) { if( cvWaitKey( 100 ) == 27 ) break; }
// Clean up and don’t be piggies
cvDestroyWindow( "pic.jpg" );
cvReleaseImage( &src );
cvReleaseImage( &dst );
}
ps:使用的例子是“pic.jpg”,原来的代码中是argv【1】,具体使用是直接替换即可
今天试了例5-1,其中cvPyrSegmentation( src, dst, storage, &comp, 4,
200, 50 );这个函数总是出问题,后来百度才知道是高版本的opencv无法兼容低
版本的函数问题,然后加两个头文件便可以解决问题,
#include <opencv2/legacy/legacy.hpp>
//#pragma comment(lib, "opencv_legacy244.lib")
其中我第二个无法解析找到,所以注释后也可以编译通过了,5-1使得图像变得模
糊化,像油笔效果
补充:
- typedef struct CvConnectedComp
- {
- double area; //区域的面积
- CvScalar value; //区域颜色的平均值
- CvRect rect; //是一个区域的外接矩形
- CvSeq * contour; //指向另一个序列的指针
- };