- 积分
- 16
贡献97
飞刀27 FD
注册时间2019-2-22
在线时间2 小时
扫一扫,手机访问本帖
|
本帖最后由 njxnet 于 2019-3-22 16:10 编辑
开发板移植了opencv2.4.9。
QT代码如下:
widget.h
- #ifndef WIDGET_H
- #define WIDGET_H
- #include <QWidget>
- #include <QImage>
- #include <QTimer> // 设置采集数据的间隔时间
- #include <opencv/highgui.h> //包含opencv库头文件
- #include <opencv/cv.h>
- namespace Ui {
- class Widget;
- }
- class Widget : public QWidget
- {
- Q_OBJECT
- public:
- explicit Widget(QWidget *parent = 0);
- ~Widget();
- private slots:
- void openCamara(); // 打开摄像头
- void readFarme(); // 读取当前帧信息
- void closeCamara(); // 关闭摄像头。
- void takingPictures(); // 拍照
- private:
- Ui::Widget *ui;
- QTimer *timer;
- QImage *imag;
- CvCapture *cam;// 视频获取结构, 用来作为视频获取函数的一个参数
- IplImage *frame;//申请IplImage类型指针,就是申请内存空间来存放每一帧图像
- };
- #endif // WIDGET_H
复制代码
widget.cpp
- #include "widget.h"
- #include "ui_widget.h"
- Widget::Widget(QWidget *parent) :
- QWidget(parent),
- ui(new Ui::Widget)
- {
- ui->setupUi(this);
- cam = NULL ;
- timer = new QTimer(this);
- imag = new QImage();
- connect(timer,SIGNAL(timeout()),this,SLOT(readFarme())); //时间到,读取当前摄像头信息
- connect(ui->OpenCameraPushButton,SIGNAL(clicked()),this,SLOT(openCamara()));
- connect(ui->TakePhotoPushButton,SIGNAL(clicked()),this,SLOT(takingPictures()));
- connect(ui->CloseCameraPushButton,SIGNAL(clicked()),this,SLOT(closeCamara()));
- }
- void Widget::openCamara()
- {
- cam = cvCreateCameraCapture(-1); //打开摄像头,从摄像头中获取视频
- timer->start(33); // 开始计时,超时则发出timeout()信号
- }
- void Widget::readFarme()
- {
- frame = cvQueryFrame(cam);
- QImage image((const uchar*)frame->imageData, frame->width,frame->height,QImage::Format_RGB888);
- ui->label->setPixmap(QPixmap::fromImage(image));
- }
- void Widget::takingPictures()
- {
- frame = cvQueryFrame(cam);
- QImage image((const uchar*)frame->imageData, frame->width,frame->height,QImage::Format_RGB888);
- ui->label_2->setPixmap(QPixmap::fromImage(image));
- }
- void Widget::closeCamara()
- {
- timer->stop();
- cvReleaseCapture(&cam);
- }
- Widget::~Widget()
- {
- delete ui;
- delete timer;
- delete imag;
- delete frame;
- }
复制代码
main.cpp
- #include "widget.h"
- #include <QApplication>
- int main(int argc, char *argv[])
- {
- QApplication a(argc, argv);
- Widget w;
- w.show();
- return a.exec();
- }
复制代码
.pro
- #-------------------------------------------------
- #
- # Project created by QtCreator 2019-03-21T20:20:55
- #
- #-------------------------------------------------
- QT += core gui
- greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
- TARGET = Opencv_pro1
- TEMPLATE = app
- SOURCES += main.cpp\
- widget.cpp
- INCLUDEPATH += /usr/local/opencv/install_opencv/include/\
- /usr/local/opencv/install_opencv/include/opencv\
- /usr/local/opencv/install_opencv/include/opencv2
- LIBS += /usr/local/opencv/install_opencv/lib/libopencv_calib3d.so\
- /usr/local/opencv/install_opencv/lib/libopencv_contrib.so\
- /usr/local/opencv/install_opencv/lib/libopencv_core.so\
- /usr/local/opencv/install_opencv/lib/libopencv_features2d.so\
- /usr/local/opencv/install_opencv/lib/libopencv_flann.so\
- /usr/local/opencv/install_opencv/lib/libopencv_gpu.so\
- /usr/local/opencv/install_opencv/lib/libopencv_highgui.so \
- /usr/local/opencv/install_opencv/lib/libopencv_imgproc.so\
- /usr/local/opencv/install_opencv/lib/libopencv_legacy.so\
- /usr/local/opencv/install_opencv/lib/libopencv_ml.so\
- /usr/local/opencv/install_opencv/lib/libopencv_nonfree.so\
- /usr/local/opencv/install_opencv/lib/libopencv_objdetect.so\
- /usr/local/opencv/install_opencv/lib/libopencv_ocl.so\
- /usr/local/opencv/install_opencv/lib/libopencv_photo.so\
- /usr/local/opencv/install_opencv/lib/libopencv_stitching.so\
- /usr/local/opencv/install_opencv/lib/libopencv_superres.so\
- /usr/local/opencv/install_opencv/lib/libopencv_video.so\
- /usr/local/opencv/install_opencv/lib/libopencv_videostab.so
- HEADERS += widget.h
- FORMS += widget.ui
复制代码
出现的问题:交叉编译移植ARM,点击PushButton打开摄像头,超级终端一直输出 VIDIOC_QUERYCTRL: Inappropriate ioctl for device
|
|