OpenCV中文网站

 找回密码
 立即注册
搜索
热搜: 安装 配置
查看: 5169|回复: 3

Image step is wrong

[复制链接]
发表于 2008-9-25 13:31:40 | 显示全部楼层 |阅读模式
我在Linux系统下运行facedetect出现如下错误:

错误信息:
OpenCV Error: Image step is wrong() in function cvInitMatHeader,cxarray.cpp(199)
Terminating the application...
called from cvUnregisterType cxpersistence.cpp(4933)
Terminating the application...
……
called from cvUnregisterType cxpersistence.cpp(4933)
Terminating the application...

不知道为什么,我用arm-linux-g++ facedetect.c -o facedetect `pkg-config --cflags --libs opencv`编译通过了,没有问题,然后下到arm9的板子上运行,就报出上面的错误,感激帮助!
回复

使用道具 举报

发表于 2008-9-26 23:31:52 | 显示全部楼层

Image step is wrong

信息贴的好像不完整……一步步跟吧~定位到哪个地方出错……从“OpenCV Error”来看应该是较严重错误,尝试一下在代码中搜索“Image step is wrong”看是否可以定位到错误……
回复 支持 反对

使用道具 举报

 楼主| 发表于 2008-9-27 20:39:34 | 显示全部楼层

Image step is wrong

感谢你的恢复,我现在可以好想知道了,是里面关于打开窗口什么的函数造成的,我把这些函数删掉,把程序改到最简单,然后可以编译通过,运行的时候出现了 Segmentation fault 的问题,我觉得应该是字节对齐的问题,可我不知道该怎么改,谢谢可以再给我讲一讲,万分感激,程序代码如下:
#include "cv.h"
#include "highgui.h"

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <math.h>
#include <float.h>
#include <limits.h>
#include <time.h>
#include <ctype.h>

#ifdef _EiC
#define WIN32
#endif

static CvMemStorage* storage = 0;
static CvHaarClassifierCascade* cascade = 0;

void detect_and_draw( IplImage* image );

const char* cascade_name =
    &quot;haarcascade_frontalface_alt.xml&quot;;
/*    &quot;haarcascade_profileface.xml&quot;;*/

int main( int argc, char** argv )
{
    IplImage *frame, *frame_copy = 0;
    int optlen = strlen(&quot;--cascade=&quot;);
    const char* input_name;


        cascade_name = &quot;./data/haarcascades/haarcascade_frontalface_alt2.xml&quot;;
        input_name = &quot;001.bmp&quot;;

    cascade = (CvHaarClassifierCascade*)cvLoad( cascade_name, 0, 0, 0 );

        IplImage* image = cvLoadImage( input_name, 1 );

        if( image )
        {
            storage = cvCreateMemStorage(0);
            printf(&quot;width=%d,height%d\\n&quot;,image->width,image->height);
            detect_and_draw( image );
            cvReleaseImage( &image );
        }

    return 0;
}

void detect_and_draw( IplImage* img )
{
    static CvScalar colors[] =
    {
        {{0,0,255}},
        {{0,128,255}},
        {{0,255,255}},
        {{0,255,0}},
        {{255,128,0}},
        {{255,255,0}},
        {{255,0,0}},
        {{255,0,255}}
    };

    double scale = 1.3;
    IplImage* gray = cvCreateImage( cvSize(img->width,img->height), 8, 1 );
    //IplImage* small_img = cvCreateImage( cvSize( cvRound (img->width/scale),
    //                     cvRound (img->height/scale)),
    //                 8, 1 );
    int i;

    cvCvtColor( img, gray, CV_BGR2GRAY );
    //cvResize( gray, small_img, CV_INTER_LINEAR );
    //cvEqualizeHist( small_img, small_img );
   cvClearMemStorage( storage );

    if( cascade )
    {
        double t = (double)cvGetTickCount();
       CvSeq* faces = cvHaarDetectObjects( gray, cascade, storage,
                                           1.1, 2, 0/*CV_HAAR_DO_CANNY_PRUNING*/,
                                           cvSize(30, 30) );
        t = (double)cvGetTickCount() - t;
        printf( &quot;detection time = %gms\\n&quot;, t/((double)cvGetTickFrequency()*1000.) );
        for( i = 0; i < (faces ? faces->total : 0); i++ )
        {
            CvRect* r = (CvRect*)cvGetSeqElem( faces, i );
            CvPoint center;
            int radius;
            center.x = cvRound((r->x + r->width*0.5)*scale);
            center.y = cvRound((r->y + r->height*0.5)*scale);
            radius = cvRound((r->width + r->height)*0.25*scale);
            //cvCircle( img, center, radius, colors[i%8], 3, 8, 0 );
        }
    }

  //  cvShowImage( &quot;result&quot;, img );
    cvReleaseImage( &gray );
    //cvReleaseImage( &small_img );
}
我是通过./configure --host=arm-linux --without-gtk --without-carbon --without-v4l --without-quicktime --without-1394libs --without-ffmpeg --without-python --without-swig
然后make,make install
arm-linux-gcc facedetect.c -o facetect `pkg-config --cflags --libs opencv`
编译没有问题,还是下到arm9的板子上出的上面的 Segmentation fault 错误!
回复 支持 反对

使用道具 举报

发表于 2008-10-24 10:56:07 | 显示全部楼层

Image step is wrong

感谢你的恢复,我现在可以好想知道了,是里面关于打开窗口什么的函数造成的,我把这些函数删掉,把程序改到最简单,然后可以编译通过,运行的时候出现了 Segmentation fault 的问题,我觉得应该是字节对齐的问题,可我不知道该怎么改,谢谢可以再给我讲一讲,万分感激,程序代码如下:
#include &quot;cv.h&quot;
#include &quot;highgui.h&quot;

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <math.h>
#include <float.h>
#include <limits.h>
#include <time.h>
#include <ctype.h>

#ifdef _EiC
#define WIN32
#endif

static CvMemStorage* storage = 0;
static CvHaarClassifierCascade* cascade = 0;

void detect_and_draw( IplImage* image );

const char* cascade_name =
    &quot;haarcascade_frontalface_alt.xml&quot;;
/*    &quot;haarcascade_profileface.xml&quot;;*/

int main( int argc, char** argv )
{
    IplImage *frame, *frame_copy = 0;
    int optlen = strlen(&quot;--cascade=&quot;);
    const char* input_name;


        cascade_name = &quot;./data/haarcascades/haarcascade_frontalface_alt2.xml&quot;;
        input_name = &quot;001.bmp&quot;;

    cascade = (CvHaarClassifierCascade*)cvLoad( cascade_name, 0, 0, 0 );

        IplImage* image = cvLoadImage( input_name, 1 );

        if( image )
        {
            storage = cvCreateMemStorage(0);
            printf(&quot;width=%d,height%d\\n&quot;,image->width,image->height);
            detect_and_draw( image );
            cvReleaseImage( &image );
        }

    return 0;
}

void detect_and_draw( IplImage* img )
{
    static CvScalar colors[] =
    {
        {{0,0,255}},
        {{0,128,255}},
        {{0,255,255}},
        {{0,255,0}},
        {{255,128,0}},
        {{255,255,0}},
        {{255,0,0}},
        {{255,0,255}}
    };

    double scale = 1.3;
    IplImage* gray = cvCreateImage( cvSize(img->width,img->height), 8, 1 );
    //IplImage* small_img = cvCreateImage( cvSize( cvRound (img->width/scale),
    //                     cvRound (img->height/scale)),
    //                 8, 1 );
    int i;

    cvCvtColor( img, gray, CV_BGR2GRAY );
    //cvResize( gray, small_img, CV_INTER_LINEAR );
    //cvEqualizeHist( small_img, small_img );
   cvClearMemStorage( storage );

    if( cascade )
    {
        double t = (double)cvGetTickCount();
       CvSeq* faces = cvHaarDetectObjects( gray, cascade, storage,
                                           1.1, 2, 0/*CV_HAAR_DO_CANNY_PRUNING*/,
                                           cvSize(30, 30) );
        t = (double)cvGetTickCount() - t;
        printf( &quot;detection time = %gms\\n&quot;, t/((double)cvGetTickFrequency()*1000.) );
        for( i = 0; i < (faces ? faces->total : 0); i++ )
        {
            CvRect* r = (CvRect*)cvGetSeqElem( faces, i );
            CvPoint center;
            int radius;
            center.x = cvRound((r->x + r->width*0.5)*scale);
            center.y = cvRound((r->y + r->height*0.5)*scale);
            radius = cvRound((r->width + r->height)*0.25*scale);
            //cvCircle( img, center, radius, colors[i%8], 3, 8, 0 );
        }
    }

  //  cvShowImage( &quot;result&quot;, img );
    cvReleaseImage( &gray );
    //cvReleaseImage( &small_img );
}
我是通过./configure --host=arm-linux --without-gtk --without-carbon --without-v4l --without-quicktime --without-1394libs --without-ffmpeg --without-python --without-swig
然后make,make install
arm-linux-gcc facedetect.c -o facetect `pkg-config --cflags --libs opencv`
编译没有问题,还是下到arm9的板子上出的上面的 Segmentation fault 错误!



你这样编译好像是动态库呀,不是静态库的话,你要指定动态库的目录!另外,1。建议你多加printf,看看到底是哪一句造成segmentation fault, 一般来说,这个错误是野指针造成的。 2。 建议参考http://www.opencv.org.cn/forum/viewtopic.php?p=4148
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|OpenCV中文网站

GMT+8, 2024-4-26 00:17 , Processed in 0.010561 second(s), 16 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表