opencv中cvPyrSegmentation出现问题了

ogiso_pest 2010-10-18 09:30:31
运行学习opencv中的代码,但是出现了错误
提示窗口
Opencv GUI Error Handler
Bad argument (OpenCV function failed)
in function cvPyrSegmentation ,c:\User\vp\opencv\src\cvPyrSegmentation.cpp 1870
谢谢了啊
~
麻烦大家了



//
//Example 5-1. Doing something with each element in the sequence of connected components returned
// by cvPyrSegmentation(
//
/* *************** License:**************************
Oct. 3, 2008
Right to use this code in any way you want without warrenty, support or any guarentee of it working.

BOOK: It would be nice if you cited it:
Learning OpenCV: Computer Vision with the OpenCV Library
by Gary Bradski and Adrian Kaehler
Published by O'Reilly Media, October 3, 2008

AVAILABLE AT:
http://www.amazon.com/Learning-OpenCV-Computer-Vision-Library/dp/0596516134
Or: http://oreilly.com/catalog/9780596516130/
ISBN-10: 0596516134 or: ISBN-13: 978-0596516130

OTHER OPENCV SITES:
* The source code is on sourceforge at:
http://sourceforge.net/projects/opencvlibrary/
* The OpenCV wiki page (As of Oct 1, 2008 this is down for changing over servers, but should come back):
http://opencvlibrary.sourceforge.net/
* An active user group is at:
http://tech.groups.yahoo.com/group/OpenCV/
* The minutes of weekly OpenCV development meetings are at:
http://pr.willowgarage.com/wiki/OpenCV
************************************************** */

#include <stdio.h>
#include <cv.h>
#include <highgui.h>
#include <stdio.h>

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( "201001071230101.jpg", 1 );
// Load the image from the given file name.
IplImage* src = cvLoadImage( "201001071230101.jpg" );
if(!src) { printf("Couldn't seem to Open %s, sorry\n",argv[1]); return -1;}
IplImage* dst = cvCreateImage( cvGetSize(src), src->depth, src->nChannels);
f( src, dst);

// Show the image in the named window
cvShowImage( argv[1], dst );

// Idle until the user hits the "Esc" key.
while( 1 ) { if( cvWaitKey( 100 ) == 27 ) break; }

// Clean up and don鈥檛 be piggies
cvDestroyWindow( "201001071230101.jpg" );
cvReleaseImage( &src );
cvReleaseImage( &dst );

}
...全文
424 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
dingyitian 2012-12-05
  • 打赏
  • 举报
回复
这个问题我也碰到过,这是因为cvPyrSegmentation这个函数对输入输出图像时有要求的,具体可以参考学习opencv这本书
yyshawn 2011-03-06
  • 打赏
  • 举报
回复
我按二楼的来,还是那个问题啊!!!
求指导
fengbingchun 2010-10-19
  • 打赏
  • 举报
回复
改成这样就可以了,我已调试通过:
#include <stdio.h>
#include <cv.h>
#include <highgui.h>
#include <stdio.h>

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( "201001071230101.jpg", 1 );
// Load the image from the given file name.
IplImage* src = cvLoadImage( "201001071230101.jpg" );
if(!src) { printf("Couldn't seem to Open %s, sorry\n",argv[1]); return -1;}
IplImage* dst = cvCreateImage( cvGetSize(src), src->depth, src->nChannels);
f( src, dst);

// Show the image in the named window
cvShowImage( "201001071230101.jpg", dst );

// Idle until the user hits the "Esc" key.
while( 1 ) { if( cvWaitKey( 100 ) == 27 ) break; }

// Clean up and don鈥檛 be piggies
cvDestroyWindow( "201001071230101.jpg" );
cvReleaseImage( &src );
cvReleaseImage( &dst );

return 0;

}

4,512

社区成员

发帖
与我相关
我的任务
社区描述
图形图像/机器视觉
社区管理员
  • 机器视觉
  • 迪菲赫尔曼
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧