专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > 图形/图像

opencv中cvPyrSegmentation出现有关问题了

发布时间:2011-06-27 20:40:19 文章来源:www.iduyao.cn 采编人员:星星草
opencv中cvPyrSegmentation出现问题了
运行学习opencv中的代码,但是出现了错误
提示窗口
Opencv GUI Error Handler
Bad argument (OpenCV function failed)
in function cvPyrSegmentation ,c:\User\vp\opencv\src\cvPyrSegmentation.cpp 1870
谢谢了啊
~
麻烦大家了



C/C++ code
//
//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 );

}



------解决方案--------------------
改成这样就可以了,我已调试通过:
#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);
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: