ARM当中使用opencv的cvCreateCameraCapture()错误:
编译opencv以及相关库文件如下:
opencv2.0
libz: zlib-1.2.3
libjpeg: jpegsrc.v6b
libpng: libpng-1.2.18
libyasm: yasm-0.7.2
opencv: opencv-2.0.0
libx264: x264-snapshot-20110612-2245-stable
libxvid: xvidcore-1.3.2
ffmpeg: ffmpeg-0.5.3
听说GTK不好移植,所以我用QT来代替GTK部分!
以下是我的程序部分:
widget.cpp:
#include "widget.h"
#include "ui_widget.h"
#include <QPainter>
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
timer = new QTimer(this);
connect(timer,SIGNAL(timeout()),this,SLOT(slot_timer()));
timer->start(FPS);
capture=cvCreateCameraCapture(2);
}
Widget::~Widget()
{
delete ui;
cvReleaseImage(&frame);
}
void Widget::slot_timer()
{
frame=cvQueryFrame(capture);
if(!frame)
{
return;
}
cvCvtColor(frame,frame,CV_BGR2RGB);
img=new QImage((unsigned char*)frame->imageData,frame->width,frame->height,frame->widthStep,QImage::Format_RGB888);
update();
}
void Widget::paintEvent(QPaintEvent *event)
{
QPainter *pp=new QPainter(this);
pp->drawImage(0,0,*img);
}
widget.h:
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include "istream"
#include "stdio.h"
#include "highgui.h"
#include "cv.h"
#include <QTimer>
#include <QImage>
using namespace std;
#define TIME_LOCK 30
#define FPS 30
namespace Ui {
class Widget;
}
class Widget : public QWidget
{
Q_OBJECT
public:
explicit Widget(QWidget *parent = 0);
~Widget();
private:
Ui::Widget *ui;
IplImage *frame;
CvCapture *capture;
QTimer *timer;
QImage *img;
private slots:
void slot_timer();
protected:
void paintEvent(QPaintEvent *event);
};
#endif // WIDGET_H
main.cpp:
#include <QtGui/QApplication>
#include "widget.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Widget w;
w.show();
return a.exec();
}
另外:我的QT都是使用tiny6410自带的,以上的库文件也是用友善tiny6410自带的4.5.1编译器交叉编译的!
交叉编译好后,将库移植后,在arm板上运行程序,出现如下错误:
------------[ cut here ]------------
WARNING: at kernel/mutex.c:205 __mutex_lock_slowpath+0xc4/0x2ac()
Modules linked in:
[<c0177c44>] (unwind_backtrace+0x0/0xe4) from [<c0187078>] (warn_slowpath_common+0x4c/0x64)
[<c0187078>] (warn_slowpath_common+0x4c/0x64) from [<c01870a8>] (warn_slowpath_null+0x18/0x1c)
[<c01870a8>] (warn_slowpath_null+0x18/0x1c) from [<c051619c>] (__mutex_lock_slowpath+0xc4/0x2ac)
[<c051619c>] (__mutex_lock_slowpath+0xc4/0x2ac) from [<c05163a4>] (mutex_lock+0x20/0x38)
[<c05163a4>] (mutex_lock+0x20/0x38) from [<c0441614>] (s3c_fimc_open+0x38/0xa8)
[<c0441614>] (s3c_fimc_open+0x38/0xa8) from [<c03c450c>] (v4l2_open+0x9c/0xd0)
[<c03c450c>] (v4l2_open+0x9c/0xd0) from [<c01e4f10>] (chrdev_open+0x168/0x190)
[<c01e4f10>] (chrdev_open+0x168/0x190) from [<c01e031c>] (__dentry_open.clone.12+0x164/0x26c)
[<c01e031c>] (__dentry_open.clone.12+0x164/0x26c) from [<c01ed194>] (finish_open+0x80/0x158)
[<c01ed194>] (finish_open+0x80/0x158) from [<c01ed610>] (do_filp_open+0x11c/0x520)
[<c01ed610>] (do_filp_open+0x11c/0x520) from [<c01e1144>] (do_sys_open+0x58/0xe4)
[<c01e1144>] (do_sys_open+0x58/0xe4) from [<c01725e0>] (ret_fast_syscall+0x0/0x30)
---[ end trace dbc45def69de5948 ]---
Unable to handle kernel NULL pointer dereference at virtual address 00000000
pgd = cc458000
[00000000] *pgd=5c436831, *pte=00000000, *ppte=00000000
Internal error: Oops: 817 [#1] PREEMPT
last sysfs file: /sys/devices/virtual/vc/vcsa2/dev
Modules linked in:
CPU: 0 Tainted: G W (2.6.38-FriendlyARM #13)
PC is at __mutex_lock_slowpath+0xf8/0x2ac
LR is at __mutex_lock_slowpath+0xe0/0x2ac
pc : [<c05161d0>] lr : [<c05161b8>] psr: 40000093
sp : cd4ebde8 ip : 11111111 fp : ccfef000
r10: cd1568c0 r9 : c01e4da8 r8 : cd4ebde8
r7 : c0793ee0 r6 : cd4c32c0 r5 : 60000013 r4 : c0793ecc
r3 : 00000000 r2 : cd4ea000 r1 : cd4ebde8 r0 : c0793ecc
Flags: nZcv IRQs off FIQs on Mode SVC_32 ISA ARM Segment user
Control: 00c5387d Table: 5c458008 DAC: 00000015
Process QtOpenCV (pid: 1021, stack limit = 0xcd4ea268)
Stack: (0xcd4ebde8 to 0xcd4ec000)
bde0: c0793ee0 00000000 11111111 cd4ebde8 ffffffff c0793ecc
be00: c0793ecc 00000458 c0793a5c cd6930a0 c01e4da8 cd1568c0 ccfef000 c05163a4
be20: c0755db0 c0441614 c0755db0 c04415dc c0755db8 cd6930a0 c055d768 c03c450c
be40: c03c4470 cd1568c0 cd6930a0 ccedc8c0 00000000 c01e4f10 cd1568c0 00000000
be60: c051c614 00000000 cd693320 cd155510 cd6930a0 c01e031c cd4ebee4 00000000
be80: 00000000 00000000 00000024 cd4ea000 ffffffff c01ed194 cd4ebee4 00000000
bea0: 00000000 00000101 cd4ebee4 00000024 00000000 c01ed610 00000000 cd732500
bec0: c073d774 cd732d00 00000001 ffffff9c 00000000 c0183194 00000000 c07242f0
bee0: 00000000 cd693320 cd155510 c0724338 cd4c32f0 cc4011e0 00000000 cd019f30
bf00: 00000000 cd1568c0 00000101 00000004 00000001 00000000 40000000 cd4ea000
bf20: cd154a80 00000010 cd693008 cd154a80 cd425324 00000000 00000001 00000001
bf40: 00000000 00000000 cd425308 cd425300 00016450 c051744c cd425308 00000003
bf60: ffffff9c ccfef000 00000000 00000000 cd4ea000 ffffffff 00016450 c01e1144
bf80: 00000000 bedb6a48 bedb6a48 400e8000 00000002 00000005 c0172788 cd4ea000
bfa0: 00000000 c01725e0 bedb6a48 400e8000 bedb6a48 00000000 ffffffff bedb6a53
bfc0: bedb6a48 400e8000 00000002 00000005 00000000 00000001 400d8ba0 00016450
bfe0: 400e8878 bedb6a28 400d2944 4006436c 40000010 bedb6a48 00000000 00000000
[<c05161d0>] (__mutex_lock_slowpath+0xf8/0x2ac) from [<c05163a4>] (mutex_lock+0x20/0x38)
[<c05163a4>] (mutex_lock+0x20/0x38) from [<c0441614>] (s3c_fimc_open+0x38/0xa8)
[<c0441614>] (s3c_fimc_open+0x38/0xa8) from [<c03c450c>] (v4l2_open+0x9c/0xd0)
[<c03c450c>] (v4l2_open+0x9c/0xd0) from [<c01e4f10>] (chrdev_open+0x168/0x190)
[<c01e4f10>] (chrdev_open+0x168/0x190) from [<c01e031c>] (__dentry_open.clone.12+0x164/0x26c)
[<c01e031c>] (__dentry_open.clone.12+0x164/0x26c) from [<c01ed194>] (finish_open+0x80/0x158)
[<c01ed194>] (finish_open+0x80/0x158) from [<c01ed610>] (do_filp_open+0x11c/0x520)
[<c01ed610>] (do_filp_open+0x11c/0x520) from [<c01e1144>] (do_sys_open+0x58/0xe4)
[<c01e1144>] (do_sys_open+0x58/0xe4) from [<c01725e0>] (ret_fast_syscall+0x0/0x30)
Code: e584d018 e58d7000 e58d3004 e1a0800d (e583d000)
---[ end trace dbc45def69de5949 ]---
note: QtOpenCV[1021] exited with preempt_count 1
BUG: scheduling while atomic: QtOpenCV/1021/0x40000002
Modules linked in:
[<c0177c44>] (unwind_backtrace+0x0/0xe4) from [<c0514d78>] (schedule+0x68/0x370)
[<c0514d78>] (schedule+0x68/0x370) from [<c0183330>] (__cond_resched+0x14/0x20)
one_wire_status: 2
[<c0183330>] (__cond_resched+0x14/0x20) from [<c05151e8>] (_cond_resched+0x34/0x44)
[<c05151e8>] (_cond_resched+0x34/0x44) from [<c01cf928>] (unmap_vmas+0x600/0x6d8)
[<c01cf928>] (unmap_vmas+0x600/0x6d8) from [<c01d41cc>] (exit_mmap+0x100/0x274)
one_wire_status: 2
[<c01d41cc>] (exit_mmap+0x100/0x274) from [<c0184e2c>] (mmput+0x48/0xe4)
[<c0184e2c>] (mmput+0x48/0xe4) from [<c0188b74>] (exit_mm+0x12c/0x138)
[<c0188b74>] (exit_mm+0x12c/0x138) from [<c0189f80>] (do_exit+0x1a0/0x5e4)
one_wire_status: 3
[<c0189f80>] (do_exit+0x1a0/0x5e4) from [<c0176284>] (die+0x190/0x1c0)
[<c0176284>] (die+0x190/0x1c0) from [<c0178bc8>] (__do_kernel_fault+0x64/0x84)
[<c0178bc8>] (__do_kernel_fault+0x64/0x84) from [<c0178dc0>] (do_page_fault+0x1d8/0x1f4)
one_wire_status: 4
[<c0178dc0>] (do_page_fault+0x1d8/0x1f4) from [<c0168218>] (do_DataAbort+0x30/0x98)
[<c0168218>] (do_DataAbort+0x30/0x98) from [<c01721cc>] (__dabt_svc+0x4c/0x60)
one_wire_status: 4
Exception stack(0xcd4ebda0 to 0xcd4ebde8)
bda0: c0793ecc cd4ebde8 cd4ea000 00000000 c0793ecc 60000013 cd4c32c0 c0793ee0
bdc0: cd4ebde8 c01e4da8 cd1568c0 ccfef000 11111111 cd4ebde8 c05161b8 c05161d0
one_wire_status: 4
bde0: 40000093 ffffffff
[<c01721cc>] (__dabt_svc+0x4c/0x60) from [<c05161d0>] (__mutex_lock_slowpath+0xf8/0x2ac)
[<c05161d0>] (__mutex_lock_slowpath+0xf8/0x2ac) from [<c05163a4>] (mutex_lock+0x20/0x38)
one_wire_status: 4
[<c05163a4>] (mutex_lock+0x20/0x38) from [<c0441614>] (s3c_fimc_open+0x38/0xa8)
[<c0441614>] (s3c_fimc_open+0x38/0xa8) from [<c03c450c>] (v4l2_open+0x9c/0xd0)
[<c03c450c>] (v4l2_open+0x9c/0xd0) from [<c01e4f10>] (chrdev_open+0x168/0x190)
one_wire_status: 4
[<c01e4f10>] (chrdev_open+0x168/0x190) from [<c01e031c>] (__dentry_open.clone.12+0x164/0x26c)
[<c01e031c>] (__dentry_open.clone.12+0x164/0x26c) from [<c01ed194>] (finish_open+0x80/0x158)
one_wire_status: 4
[<c01ed194>] (finish_open+0x80/0x158) from [<c01ed610>] (do_filp_open+0x11c/0x520)
[<c01ed610>] (do_filp_open+0x11c/0x520) from [<c01e1144>] (do_sys_open+0x58/0xe4)
[<c01e1144>] (do_sys_open+0x58/0xe4) from [<c01725e0>] (ret_fast_syscall+0x0/0x30)
BUG: scheduling while atomic: QtOpenCV/1021/0x40000002
Modules linked in:
[<c0177c44>] (unwind_backtrace+0x0/0xe4) from [<c0514d78>] (schedule+0x68/0x370)
one_wire_status: 4
[<c0514d78>] (schedule+0x68/0x370) from [<c0183330>] (__cond_resched+0x14/0x20)
[<c0183330>] (__cond_resched+0x14/0x20) from [<c05151e8>] (_cond_resched+0x34/0x44)
[<c05151e8>] (_cond_resched+0x34/0x44) from [<c01cf928>] (unmap_vmas+0x600/0x6d8)
one_wire_status: 4
[<c01cf928>] (unmap_vmas+0x600/0x6d8) from [<c01d41cc>] (exit_mmap+0x100/0x274)
[<c01d41cc>] (exit_mmap+0x100/0x274) from [<c0184e2c>] (mmput+0x48/0xe4)
[<c0184e2c>] (mmput+0x48/0xe4) from [<c0188b74>] (exit_mm+0x12c/0x138)
one_wire_status: 4
[<c0188b74>] (exit_mm+0x12c/0x138) from [<c0189f80>] (do_exit+0x1a0/0x5e4)
[<c0189f80>] (do_exit+0x1a0/0x5e4) from [<c0176284>] (die+0x190/0x1c0)
[<c0176284>] (die+0x190/0x1c0) from [<c0178bc8>] (__do_kernel_fault+0x64/0x84)
[<c0178bc8>] (__do_kernel_fault+0x64/0x84) from [<c0178dc0>] (do_page_fault+0x1d8/0x1f4)
[<c0178dc0>] (do_page_fault+0x1d8/0x1f4) from [<c0168218>] (do_DataAbort+0x30/0x98)
one_wire_status: 2
[<c0168218>] (do_DataAbort+0x30/0x98) from [<c01721cc>] (__dabt_svc+0x4c/0x60)
Exception stack(0xcd4ebda0 to 0xcd4ebde8)
bda0: c0793ecc cd4ebde8 cd4ea000 00000000 c0793ecc 60000013 cd4c32c0 c0793ee0
one_wire_status: 2
bdc0: cd4ebde8 c01e4da8 cd1568c0 ccfef000 11111111 cd4ebde8 c05161b8 c05161d0
bde0: 40000093 ffffffff
[<c01721cc>] (__dabt_svc+0x4c/0x60) from [<c05161d0>] (__mutex_lock_slowpath+0xf8/0x2ac)
[<c05161d0>] (__mutex_lock_slowpath+0xf8/0x2ac) from [<c05163a4>] (mutex_lock+0x20/0x38)
one_wire_status: 2
[<c05163a4>] (mutex_lock+0x20/0x38) from [<c0441614>] (s3c_fimc_open+0x38/0xa8)
[<c0441614>] (s3c_fimc_open+0x38/0xa8) from [<c03c450c>] (v4l2_open+0x9c/0xd0)
one_wire_status: 3
[<c03c450c>] (v4l2_open+0x9c/0xd0) from [<c01e4f10>] (chrdev_open+0x168/0x190)
[<c01e4f10>] (chrdev_open+0x168/0x190) from [<c01e031c>] (__dentry_open.clone.12+0x164/0x26c)
one_wire_status: 4
[<c01e031c>] (__dentry_open.clone.12+0x164/0x26c) from [<c01ed194>] (finish_open+0x80/0x158)
[<c01ed194>] (finish_open+0x80/0x158) from [<c01ed610>] (do_filp_open+0x11c/0x520)
[<c01ed610>] (do_filp_open+0x11c/0x520) from [<c01e1144>] (do_sys_open+0x58/0xe4)
one_wire_status: 4
[<c01e1144>] (do_sys_open+0x58/0xe4) from [<c01725e0>] (ret_fast_syscall+0x0/0x30)
BUG: scheduling while atomic: QtOpenCV/1021/0x40000002
Modules linked in:
[<c0177c44>] (unwind_backtrace+0x0/0xe4) from [<c0514d78>] (schedule+0x68/0x370)
[<c0514d78>] (schedule+0x68/0x370) from [<c0183330>] (__cond_resched+0x14/0x20)
[<c0183330>] (__cond_resched+0x14/0x20) from [<c05151e8>] (_cond_resched+0x34/0x44)
one_wire_status: 2
[<c05151e8>] (_cond_resched+0x34/0x44) from [<c0189d04>] (put_files_struct+0x9c/0xfc)
[<c0189d04>] (put_files_struct+0x9c/0xfc) from [<c0189f90>] (do_exit+0x1b0/0x5e4)
[<c0189f90>] (do_exit+0x1b0/0x5e4) from [<c0176284>] (die+0x190/0x1c0)
one_wire_status: 2
[<c0176284>] (die+0x190/0x1c0) from [<c0178bc8>] (__do_kernel_fault+0x64/0x84)
[<c0178bc8>] (__do_kernel_fault+0x64/0x84) from [<c0178dc0>] (do_page_fault+0x1d8/0x1f4)
one_wire_status: 2
[<c0178dc0>] (do_page_fault+0x1d8/0x1f4) from [<c0168218>] (do_DataAbort+0x30/0x98)
[<c0168218>] (do_DataAbort+0x30/0x98) from [<c01721cc>] (__dabt_svc+0x4c/0x60)
Exception stack(0xcd4ebda0 to 0xcd4ebde8)
one_wire_status: 4
bda0: c0793ecc cd4ebde8 cd4ea000 00000000 c0793ecc 60000013 cd4c32c0 c0793ee0
bdc0: cd4ebde8 c01e4da8 cd1568c0 ccfef000 11111111 cd4ebde8 c05161b8 c05161d0
bde0: 40000093 ffffffff
[<c01721cc>] (__dabt_svc+0x4c/0x60) from [<c05161d0>] (__mutex_lock_slowpath+0xf8/0x2ac)
one_wire_status: 4
[<c05161d0>] (__mutex_lock_slowpath+0xf8/0x2ac) from [<c05163a4>] (mutex_lock+0x20/0x38)
[<c05163a4>] (mutex_lock+0x20/0x38) from [<c0441614>] (s3c_fimc_open+0x38/0xa8)
one_wire_status: 4
[<c0441614>] (s3c_fimc_open+0x38/0xa8) from [<c03c450c>] (v4l2_open+0x9c/0xd0)
[<c03c450c>] (v4l2_open+0x9c/0xd0) from [<c01e4f10>] (chrdev_open+0x168/0x190)
[<c01e4f10>] (chrdev_open+0x168/0x190) from [<c01e031c>] (__dentry_open.clone.12+0x164/0x26c)
one_wire_status: 4
[<c01e031c>] (__dentry_open.clone.12+0x164/0x26c) from [<c01ed194>] (finish_open+0x80/0x158)
[<c01ed194>] (finish_open+0x80/0x158) from [<c01ed610>] (do_filp_open+0x11c/0x520)
one_wire_status: 4
[<c01ed610>] (do_filp_open+0x11c/0x520) from [<c01e1144>] (do_sys_open+0x58/0xe4)
[<c01e1144>] (do_sys_open+0x58/0xe4) from [<c01725e0>] (ret_fast_syscall+0x0/0x30)
one_wire_status: 4
Segmentation fault
我觉得应该是程序中调用了CvCapture *capture=cvCreateCameraCapture(index)函数,当中的index参数我设的为0,是不是参数设置不正确,使得capture指针为空,而导致的segmentation fault!
希望版主能够指导一下,不知道问题出在哪里了!