提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档
提示:这里可以添加本文要记录的大概内容:
嵌入式图像处理
提示:以下是本篇文章正文内容,下面案例可供参考
示例:树莓派opencv 的安装方法很多,
输入一下指令
sudo apt-get install qt5-default
sudo apt-get install qtcreator
Qt 安装完毕后记得检测一下编译器路径是否对了。
一直以为安装opencv c++的库要重新编译树莓派环境下的源码,直到看了大佬的视频才明白,原来只安装依赖项就可以用了,这个真的很省事
命令如下:安装往后记得找一下文件的路径
sudo apt-get install libopencv-devsudo find / -name "libopencv_core.so"
安装时遇到错误,
在ubuntu22.04上安装qt5-defualt时,我会得到以下错误。sudo apt-get install qt5-default
复制
产出:Reading Done
Building Done
Reading Done
Package qt5-default is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another sourceE: Package 'qt5-default' has no installation candidate
Stack Overflow用户
发布于 2022-10-18 20:28:25
Ubuntu22.04存储库没有qt5-默认包。
解决了Qt安装出错的问题
您可以通过安装qtbase5 5-dev来获得预构建的库。
sudo apt install qtbase5-dev qt5-qmake
更改编译器,解决了Qt运行出错的问题
查找摄像头设备,为测试做准备
INCLUDEPATH +=/usr/include/opencv4
/usr/include/opencv4/opencv2LIBS +=usr/lib/arm-linux-gnueabihf/libopencv_*.so
测试:
静态图像
动态图像
raspistill //静态图像
raspivid //动态图像
代码
QT += core guigreaterThan(QT_MAJOR_VERSION, 4): QT += widgetsCONFIG += c++11# You can make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0SOURCES += main.cpp mainwindow.cppHEADERS += mainwindow.hFORMS += mainwindow.ui# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += targetINCLUDEPATH +=/usr/include/opencv4
/usr/include/opencv4/opencv2LIBS +=/usr/lib/arm-linux-gnueabihf/libopencv_*.so
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QLabel>
#include <QPixmap>
#include <QFileDialog>
#include <QDebug>#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>using namespace cv;MainWindow::MainWindow(QWidget *parent): QMainWindow(parent), ui(new Ui::MainWindow)
{ui->setupUi(this);
}MainWindow::~MainWindow()
{delete ui;
}void MainWindow::on_pushButton_clicked()
{// 读取图像文件
// Mat image = imread("1.jpg");// // 将OpenCV图像转换为Qt图像类型
// QImage qImage(image.data, ls, ws, QImage::Format_RGB888);
// QPixmap qPixmap = QPixmap::fromImage(qImage);
// ui->label->setPixmap(qPixmap);// 创建窗口和标签来显示图像// QWidget window;// QLabel label(this);// label.setPixmap(qPixmap);// window.setCentralWidget(&label);//window.show();// Mat image = imread("1.jpg");// 将OpenCV图像转换为Qt图像类型
// QImage qImage(image.data, ls, ws, QImage::Format_RGB888);
// QPixmap qPixmap = QPixmap::fromImage(qImage);
// ui->label->setPixmap(qPixmap);QString fileName = QFileDialog::getOpenFileName(this, "选择图片", "", "Images (*.jpg *.png)");if (!fileName.isEmpty()) {// 读取OpenCV图片cv::Mat image = cv::Utf8().constData(), cv::IMREAD_COLOR);if (!pty()) {// 将OpenCV图片转换为Qt格式QImage qtImage = QImage((const unsigned char*)(image.data), ls, ws, ls * image.channels(), QImage::Format_RGB888);// 显示图片在标签中ui->label->setPixmap(QPixmap::fromImage(qtImage));//imageLabel->setPixmap(QPixmap::fromImage(qtImage));} else {qDebug() << "Failed to load image:" << fileName;}}}
ls /dev/video*
v4l2-ctl --info -d /dev/video0 --list-formats-ext
查看结果
pi@raspberrypi:~ $ s /dev/video*
bash: s: command not found
pi@raspberrypi:~ $ /dev/video*
bash: /dev/video0: Permission denied
pi@raspberrypi:~ $ ls /dev/video*
/dev/video0 /dev/video12 /dev/video15 /dev/video19 /dev/video22
/dev/video10 /dev/video13 /dev/video16 /dev/video20 /dev/video23
/dev/video11 /dev/video14 /dev/video18 /dev/video21 /dev/video31
pi@raspberrypi:~ $ v4l2-ctl --info -d /dev/video0 --list-formats-ext
Driver Info:Driver name : unicamCard type : unicamBus info : platform:fe801000.csiDriver version : 6.1.21Capabilities : 0xa5a00001Video CaptureMetadata CaptureRead/WriteStreamingExtended Pix FormatDevice CapabilitiesDevice Caps : 0x25200001Video CaptureRead/WriteStreamingExtended Pix Format
Media Driver Info:Driver name : unicamModel : unicamSerial : Bus info : platform:fe801000.csiMedia version : 6.1.21Hardware revision: 0x00000000 (0)Driver version : 6.1.21
Interface Info:ID : 0x03000005Type : V4L Video
Entity Info:ID : 0x00000003 (3)Name : unicam-imageFunction : V4L2 I/OFlags : defaultPad 0x01000004 : 0: SinkLink 0x02000007: from remote pad 0x1000002 of entity 'ov5647 10-0036': Data, Enabled, Immutable
ioctl: VIDIOC_ENUM_FMTType: Video Capture[0]: 'YUYV' (YUYV 4:2:2)Size: Stepwise 16x16 - 16376x16376 with step 1/1[1]: 'UYVY' (UYVY 4:2:2)Size: Stepwise 16x16 - 16376x16376 with step 1/1[2]: 'YVYU' (YVYU 4:2:2)Size: Stepwise 16x16 - 16376x16376 with step 1/1[3]: 'VYUY' (VYUY 4:2:2)Size: Stepwise 16x16 - 16376x16376 with step 1/1[4]: 'RGBP' (16-bit RGB 5-6-5)Size: Stepwise 16x16 - 16376x16376 with step 1/1[5]: 'RGBR' (16-bit RGB 5-6-5 BE)Size: Stepwise 16x16 - 16376x16376 with step 1/1[6]: 'RGBO' (16-bit A/XRGB 1-5-5-5)Size: Stepwise 16x16 - 16376x16376 with step 1/1[7]: 'RGBQ' (16-bit A/XRGB 1-5-5-5 BE)Size: Stepwise 16x16 - 16376x16376 with step 1/1[8]: 'RGB3' (24-bit RGB 8-8-8)Size: Stepwise 16x16 - 16376x16376 with step 1/1[9]: 'BGR3' (24-bit BGR 8-8-8)Size: Stepwise 16x16 - 16376x16376 with step 1/1[10]: 'RGB4' (32-bit A/XRGB 8-8-8-8)Size: Stepwise 16x16 - 16376x16376 with step 1/1[11]: 'BA81' (8-bit Bayer BGBG/GRGR)Size: Stepwise 16x16 - 16376x16376 with step 1/1[12]: 'GBRG' (8-bit Bayer GBGB/RGRG)Size: Stepwise 16x16 - 16376x16376 with step 1/1[13]: 'GRBG' (8-bit Bayer GRGR/BGBG)Size: Stepwise 16x16 - 16376x16376 with step 1/1[14]: 'RGGB' (8-bit Bayer RGRG/GBGB)Size: Stepwise 16x16 - 16376x16376 with step 1/1[15]: 'pBAA' (10-bit Bayer BGBG/GRGR Packed)Size: Stepwise 16x16 - 16376x16376 with step 1/1[16]: 'BG10' (10-bit Bayer BGBG/GRGR)Size: Stepwise 16x16 - 16376x16376 with step 1/1[17]: 'pGAA' (10-bit Bayer GBGB/RGRG Packed)Size: Stepwise 16x16 - 16376x16376 with step 1/1[18]: 'GB10' (10-bit Bayer GBGB/RGRG)Size: Stepwise 16x16 - 16376x16376 with step 1/1[19]: 'pgAA' (10-bit Bayer GRGR/BGBG Packed)Size: Stepwise 16x16 - 16376x16376 with step 1/1[20]: 'BA10' (10-bit Bayer GRGR/BGBG)Size: Stepwise 16x16 - 16376x16376 with step 1/1[21]: 'pRAA' (10-bit Bayer RGRG/GBGB Packed)Size: Stepwise 16x16 - 16376x16376 with step 1/1[22]: 'RG10' (10-bit Bayer RGRG/GBGB)Size: Stepwise 16x16 - 16376x16376 with step 1/1[23]: 'pBCC' (12-bit Bayer BGBG/GRGR Packed)Size: Stepwise 16x16 - 16376x16376 with step 1/1[24]: 'BG12' (12-bit Bayer BGBG/GRGR)Size: Stepwise 16x16 - 16376x16376 with step 1/1[25]: 'pGCC' (12-bit Bayer GBGB/RGRG Packed)Size: Stepwise 16x16 - 16376x16376 with step 1/1[26]: 'GB12' (12-bit Bayer GBGB/RGRG)Size: Stepwise 16x16 - 16376x16376 with step 1/1[27]: 'pgCC' (12-bit Bayer GRGR/BGBG Packed)Size: Stepwise 16x16 - 16376x16376 with step 1/1[28]: 'BA12' (12-bit Bayer GRGR/BGBG)Size: Stepwise 16x16 - 16376x16376 with step 1/1[29]: 'pRCC' (12-bit Bayer RGRG/GBGB Packed)Size: Stepwise 16x16 - 16376x16376 with step 1/1[30]: 'RG12' (12-bit Bayer RGRG/GBGB)Size: Stepwise 16x16 - 16376x16376 with step 1/1[31]: 'pBEE' (14-bit Bayer BGBG/GRGR Packed)Size: Stepwise 16x16 - 16376x16376 with step 1/1[32]: 'BG14' (14-bit Bayer BGBG/GRGR)Size: Stepwise 16x16 - 16376x16376 with step 1/1[33]: 'pGEE' (14-bit Bayer GBGB/RGRG Packed)Size: Stepwise 16x16 - 16376x16376 with step 1/1[34]: 'GB14' (14-bit Bayer GBGB/RGRG)Size: Stepwise 16x16 - 16376x16376 with step 1/1[35]: 'pgEE' (14-bit Bayer GRGR/BGBG Packed)Size: Stepwise 16x16 - 16376x16376 with step 1/1[36]: 'GR14' (14-bit Bayer GRGR/BGBG)Size: Stepwise 16x16 - 16376x16376 with step 1/1[37]: 'pREE' (14-bit Bayer RGRG/GBGB Packed)Size: Stepwise 16x16 - 16376x16376 with step 1/1[38]: 'RG14' (14-bit Bayer RGRG/GBGB)Size: Stepwise 16x16 - 16376x16376 with step 1/1[39]: 'GREY' (8-bit Greyscale)Size: Stepwise 16x16 - 16376x16376 with step 1/1[40]: 'Y10P' (10-bit Greyscale (MIPI Packed))Size: Stepwise 16x16 - 16376x16376 with step 1/1[41]: 'Y10 ' (10-bit Greyscale)Size: Stepwise 16x16 - 16376x16376 with step 1/1[42]: 'Y12P' (12-bit Greyscale (MIPI Packed))Size: Stepwise 16x16 - 16376x16376 with step 1/1[43]: 'Y12 ' (12-bit Greyscale)Size: Stepwise 16x16 - 16376x16376 with step 1/1[44]: 'Y14P' (14-bit Greyscale (MIPI Packed))Size: Stepwise 16x16 - 16376x16376 with step 1/1[45]: 'Y14 ' (14-bit Greyscale)Size: Stepwise 16x16 - 16376x16376 with step 1/1
本来以为很ok了,结果还是遇到了大问题;
调用:
videocapture =new VideoCapture(0, cv::CAP_V4L2);
open VIDEOIO(V4L2:/dev/video0): can‘t open camera by index
解决:
参考链接:
输入: ls /dev/video* -l
sudo chmod 777 /dev/video0
打开摄像头模块
1、在树莓派终端中输入以下命令,打开配置:
sudo raspi-config
Qt 安装好后的软件展示
学习框架和测试,用一种不用编译opencv源码的方式,成功的将Qt和opencv 用c++的方式运行了起来,写了基本图像处理的框架,接下来将测试摄像头的参数和相关设置
本文发布于:2024-02-04 11:21:07,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170706012555108.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |