opencv bug? cvExtractSurf fails with Non-positive width or height exception (opencv 2.1.0)

在使用OpenCV 2.1.0版本时,遇到cvExtractSurf函数抛出'Non-positive width or height'异常。详细探讨了该异常产生的原因及可能的解决方案,帮助开发者解决图像处理过程中的问题。
在使用cvExtractSurf提取特征出现

OpenCV Error : Incorrect size of input array ( Non - positive width or height ) in cvCreateMatHeader , file / build / buildd / opencv - 2.1 . 0 / src / cxcore / cxarray . cpp , line 113
terminate called after throwing an instance of 'cv::Exception'
  what ():   / build / buildd / opencv - 2.1 . 0 / src / cxcore / cxarray . cpp : 113 : error : (- 201 ) Non - positive width or height in function cvCreateMatHeader


上网搜了很多,是opencv的BUG吗?



Looks like someone has already created a bug report and found some fixes for this: 

源出处:http://opencv-users.1802565.n2.nabble.com/cvExtractSurf-fails-with-Non-positive-width-or-height-exception-opencv-2-1-0-td4963615.html


引用源内容:

Hello, 

I use opencv 2.1.0-1 on archlinux (i386). I'm not sure if I don'
correctly use the API, if it is an archlinux package problem of if it 
is a opencv bug. Thank you for your help 

This is the output of my program: 

./a.out 
Filesize: 13x29 
OpenCV Error: Incorrect size of input array (Non-positive width or 
height) in cvCreateMatHeader, file 
/build/src/OpenCV-2.1.0/src/cxcore/cxarray.cpp, line 113 
terminate called after throwing an instance of 'cv::Exception' 
  what():  /build/src/OpenCV-2.1.0/src/cxcore/cxarray.cpp:113: error: 
(-201) Non-positive width or height in function cvCreateMatHeader 

Aborted 

And here is the source code: 

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

int main(int argc, char** argv) 
{ 
    IplImage* image = cvLoadImage( "image.png", CV_LOAD_IMAGE_GRAYSCALE ); 
    if(  !image ) 
    { 
        fprintf( stderr, "Can not load image.png "); 
        exit(-1); 
    } 

    CvMemStorage* storage = cvCreateMemStorage(0); 
    CvSeq *imageKeypoints = 0, *imageDescriptors = 0; 
    CvSURFParams params = cvSURFParams(500, 1); 
    CvSize s = cvGetSize(image); 
    printf("Filesize: %dx%d\n", s.width, s.height); 
    cvExtractSURF( image, 0, &imageKeypoints, &imageDescriptors, 
storage, params ); 
    printf("Object Descriptors: %d\n", imageDescriptors->total); 

    return 0; 
} 



I am having the same problem with both OpenCV 2.0.0 and 2.1.0 in Visual Studio 2008.  Debug/release libraries were built from source.  I compiled the sample code found in opencv/sample/c/find_obj.cpp and it works great with the images provided, but when I supply my own images I get mixed results.  When I input a white image (i.e. no features can be extracted) it produces this error.  When I input an image composed of noise it works great.  I ran the VS debugger and the call stack shows: 
cxcore200.dll!cv::error(const cv::Exception & exc={...})  Line 194 + 

cxcore200.dll!cv::flann::Index::knnSearch(const cv::Mat & queries={...}, cv::Mat & indices={...}, cv::Mat & dists={...}, int knn=2, const cv::flann::SearchParams & searchParams={...})  Line 135 + 
 
Project.exe!flannFindPairs(const CvSeq * __formal=0x00401b1a, const CvSeq * objectDescriptors=0x00cf57d0, const CvSeq * __formal=0x00401b1a, const CvSeq * imageDescriptors=0x00cfb2e8, std::vector<int,std::allocator<int> > & ptpairs=[...]()) 

Project.exe!locatePlanarObject(const CvSeq * objectKeypoints=, const CvSeq * objectDescriptors=, const CvSeq * imageKeypoints=, const CvSeq * imageDescriptors=, const CvPoint * src_corners=, CvPoint * dst_corners=)  Line 170 

So I'm guessing it's something in cv::flann::Index::knnSearch(...) 

As an alternative OpenSURF seems to work (it works well with a webcam image source).  http://www.chrisevansdev.com/computer-vision-opensurf.html

-Paul Filitchkin 



--- In  [hidden email] , Tristram Gr?bener <tristramg@...> wrote:

>  
> Hello ,  
>  
> I use opencv 2.1 . 0 - 1 on archlinux ( i386 ). I 'm not sure if I don'
> correctly use the API , if it is an archlinux package problem of if it 
> is a opencv bug . Thank you for your help 
>  
> This is the output of my program :  
>  
> ./ a . out  
> Filesize : 13x29  
> OpenCV Error : Incorrect size of input array ( Non - positive width or  
> height ) in cvCreateMatHeader , file 
> /build/ src / OpenCV - 2.1 . 0 / src / cxcore / cxarray . cpp , line 113  
> terminate called after throwing an instance of 'cv::Exception'  
>   what ():   / build / src / OpenCV - 2.1 . 0 / src / cxcore / cxarray . cpp : 113 : error :  
> (- 201 ) Non - positive width or height in function cvCreateMatHeader 
>  
> Aborted  
>  
> And here is the source code :  
>  
> #include <cv.h>  
> #include <highgui.h>  
> #include <stdio.h>  
>  
> int main ( int argc , char ** argv )  
> {  
>     IplImage * image = cvLoadImage ( "image.png" , CV_LOAD_IMAGE_GRAYSCALE );  
>     if (   ! image )  
>     {  
>         fprintf ( stderr , "Can not load image.png " );  
>         exit (- 1 );  
>     }  
>  
>     CvMemStorage * storage = cvCreateMemStorage ( 0 );  
>     CvSeq * imageKeypoints = 0 , * imageDescriptors = 0 ;  
>     CvSURFParams params = cvSURFParams ( 500 , 1 );  
>     CvSize s = cvGetSize ( image );  
>     printf ( "Filesize: %dx%d\n" , s . width , s . height );  
>     cvExtractSURF ( image , 0 , & imageKeypoints , & imageDescriptors ,  
> storage , params );  
>     printf ( "Object Descriptors: %d\n" , imageDescriptors -> total );  
>  
>     return 0 ;  
> }  
>
...   [ show rest of quote ]


In reply to  this post   by Tristram Gr ? bener


Looks like someone has already created a bug report and found some fixes for this :  
https://code.ros.org/trac/opencv/ticket/68
- Paul Filitchkin  


--- In   [hidden email] , Tristram Gr ? bener < tristramg@ ...> wrote :
>   > Hello ,   >   > I use opencv 2.1 . 0 - 1 on archlinux ( i386 ). I 'm not sure if I don' > correctly use the API , if it is an archlinux package problem of if it  > is a opencv bug . Thank you for your help  >   > This is the output of my program :   >   > ./ a . out   > Filesize : 13x29   > OpenCV Error : Incorrect size of input array ( Non - positive width or   > height ) in cvCreateMatHeader , file  > /build/ src / OpenCV - 2.1 . 0 / src / cxcore / cxarray . cpp , line 113   > terminate called after throwing an instance of 'cv::Exception'   >   what ():   / build / src / OpenCV - 2.1 . 0 / src / cxcore / cxarray . cpp : 113 : error :   > (- 201 ) Non - positive width or height in function cvCreateMatHeader  >   > Aborted   >   > And here is the source code :   >   > #include <cv.h>   > #include <highgui.h>   > #include <stdio.h>   >   > int main ( int argc , char ** argv )   > {   >     IplImage * image = cvLoadImage ( "image.png" , CV_LOAD_IMAGE_GRAYSCALE );   >     if (   ! image )   >     {   >         fprintf ( stderr , "Can not load image.png " );   >         exit (- 1 );   >     }   >   >     CvMemStorage * storage = cvCreateMemStorage ( 0 );   >     CvSeq * imageKeypoints = 0 , * imageDescriptors = 0 ;   >     CvSURFParams params = cvSURFParams ( 500 , 1 );   >     CvSize s = cvGetSize ( image );   >     printf ( "Filesize: %dx%d\n" , s . width , s . height );   >     cvExtractSURF ( image , 0 , & imageKeypoints , & imageDescriptors ,   > storage , params );   >     printf ( "Object Descriptors: %d\n" , imageDescriptors -> total );   >   >     return 0 ;   > }   >
...   [ show rest of quote ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值