我用的是红帽系统(ubantu和fedora都试过,都可以),opencv2.3.1的库,arm-linux-gcc4.3.2的工具链,QT4.7的环境。在PC机上,运行cvcapture的程序时,能打开摄像头,并且在QLabel上显示。但是当我交叉编译放到ARM11板子上时,就会闪退。显示not found camera(这一句是我自己设的调试信息)
segmentation fault
明明我插上摄像头了,却不能识别,而且出现段错误,有哪位高手能帮忙看看怎么回事,不胜感谢!
以下是我的程序:
dialog.h
- #ifndef DIALOG_H
- #define DIALOG_H
- #include <QDialog>
- #include <cv.h>
- #include <highgui.h>
- #include <QTimer>
- #include <QPixmap>
- namespace Ui {
- class Dialog;
- }
- class Dialog : public QDialog
- {
- Q_OBJECT
- public:
- explicit Dialog(QWidget *parent = 0);
- ~Dialog();
- private:
- Ui::Dialog *ui;
- CvCapture *capture; //highgui 里提供的一个专门处理摄像头图像的结构体
- IplImage *frame; //摄像头每次抓取的图像为一帧,使用该指针指向一帧图像的内存空间
- QTimer *timer; //定时器用于定时取帧,上面说的隔一段时间就去取就是用这个实现。
- private slots:
- void getFrame(); //实现定时从摄像头取图并显示在label上的功能。
- };
- #endif // DIALOG_H
复制代码 dialog.cpp
- #include "dialog.h"
- #include "ui_dialog.h"
- #include <QDebug>
- Dialog::Dialog(QWidget *parent) :
- QDialog(parent),
- ui(new Ui::Dialog)
- {
- ui->setupUi(this);
- timer = new QTimer(this);
- capture = cvCaptureFromCAM(0); //cvCaptureFromCAM其实是一个宏,就是cvCreateCameraCapture的别名,0代表第一个摄像头。-1代表默认摄像头。
- if(capture==NULL){
- qDebug()<<"not found camera!!";
- }
- timer->start(50); //1000为1秒,50毫秒去取一帧
- connect(timer,SIGNAL(timeout()),this,SLOT(getFrame())); //超时就去取
- }
- void Dialog::getFrame()
- {
- frame = cvQueryFrame(capture); //从摄像头取帧
- QImage image = QImage((const uchar*)frame->imageData, frame->width, frame->height, QImage::Format_RGB888).rgbSwapped(); //简单地转换一下为Image对象,rgbSwapped是为了显示效果色彩好一些。
- ui->label->setPixmap(QPixmap::fromImage(image));
- }
- Dialog::~Dialog()
- {
- timer->stop(); //停止取帧
- cvReleaseCapture(&capture); //释放资源是个好习惯
- delete ui;
- }
复制代码
|