OpenCV中文网站

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

Segmentation fault

[复制链接]
发表于 2008-10-7 15:21:22 | 显示全部楼层 |阅读模式
#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-7 19:33:08 | 显示全部楼层

Segmentation fault

Segmentation fault 一般由使用未分配内存引起。
回复 支持 反对

使用道具 举报

发表于 2008-11-23 14:25:36 | 显示全部楼层

Segmentation fault

加个printf看看不就知道是哪一行的问题了,然后再有针对性的去分析代码,看看API用的对不对。
回复 支持 反对

使用道具 举报

发表于 2009-2-25 11:50:32 | 显示全部楼层

Segmentation fault

问题解决了没?
回复 支持 反对

使用道具 举报

发表于 2012-3-2 10:41:43 | 显示全部楼层

Segmentation fault

我也遇到这个问题,请问怎么解决?
回复 支持 反对

使用道具 举报

发表于 2012-3-8 10:40:57 | 显示全部楼层

Segmentation fault

求高手指点
回复 支持 反对

使用道具 举报

发表于 2012-4-30 21:13:10 | 显示全部楼层

Segmentation fault

我也遇到了同样的问题!!!!急啊! 高人指点 我移植的是opencv2.0到arm6410上 欢迎大家交流 1603944332
回复 支持 反对

使用道具 举报

发表于 2012-6-27 12:57:03 | 显示全部楼层

Segmentation fault

遇到同样的问题,通过 v4l2 从 USB 摄像头读取 MJPEG 数据并存储到 tmp.jpg 文件,然后用 cvLoadImage 读进来,再通过 Framebuffer 显示,通过测试发现主要根源还是 opencv 这一部分,把显示注释掉还是有这个错误,但是把读图像注释掉就没有问题,看来还是 libjpeg 的问题,但是要怎么解决呢?貌似 cvLoadImage 应该会自动分配内存的啊,期待解答
回复 支持 反对

使用道具 举报

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

本版积分规则

手机版|OpenCV中文网站

GMT+8, 2024-5-14 05:13 , Processed in 0.010322 second(s), 17 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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