【发布时间】:2019-12-03 13:37:32
【问题描述】:
我正在开发一个计算机视觉项目,这是一个可交互的表面,它必须通过识别用户手的视频源来处理用户交互。系统识别用户的手指并将其映射到 GUI 上。我在 Visual Studio 2017 中开发了解决方案,使用 OpenCV 进行视频处理,使用 QT 5 构建 GUI,使用 arduino 来检查表面上的点击。目前我必须使用 arduino 串行输出控制 QTPushButton,控制 C++ 程序主类中的布尔值(isChecked),我已经阅读了很多关于 QT 中的 SIGNAL 和 SLOT 但是当我触发 SIGNAL使用 arduino 串行连接,我在 MainWindow 界面中使用 connect() 方法处理信号,系统响应错误:QObject::connect: No such signal QPushButton::valueChangedButton1(unsigned int)。
程序未能connect(button1, SIGNAL(valueChangedButton1(unsigned int)), this, SLOT(button1clicked()));,在 MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) 实例。
SerialPort.h 是一个实用程序类,用于处理来自 arduino 的串行输出。我试图将 connect() 方法放在 openCV 的 while 循环中,但不起作用。
MainWindow.h
#define NSAMPLES 7
#define ORIGCOL2COL COLOR_BGR2HLS
#define COL2ORIGCOL COLOR_HLS2BGR
#define PI 3.14159
#include <QtWidgets/QMainWindow>
#include <QtCore/qcoreapplication.h>
#include <QtGui/qtguiglobal.h>
#include <iostream>
#include "ui_MainWindow.h"
#include "opencv2/opencv.hpp"
#include "SerialPort.h"
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = Q_NULLPTR);
private:
void initializationClicked();
void stopCapture();
void button1clicked();
void button2clicked();
signals:
void valueChangedButton1(unsigned int value);
private:
QPushButton *startCapture;
QPushButton *releaseCapture;
QPushButton *button1;
QPushButton *button2;
QLabel *interactionLabel;
QLabel *interactionType;
QFont f, i;
char *PORT;
bool b1Over, b2Over, isChecked;
// opencv stuff
cv::VideoCapture cap;
cv::Mat src;
// arduino stuff
char output[MAX_DATA_LENGTH];
char incomingData[MAX_DATA_LENGTH];
int intFromArduino;
char *port;
int fromArduino;
}
MainWindow.cpp
#include "MainWindow.h"
using namespace cv;
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
f = QFont("Arial", 12, QFont::Bold);
i = QFont("Arial", 10, QFont::Black);
PORT = "\\\\.\\COM5";
width = 600;
height = 380;
setMinimumSize(width, height);
startCapture = new QPushButton("INIT SYSTEM", this);
startCapture->setGeometry(QRect(QPoint(10, height - 120), QSize(100, 50)));
connect(startCapture, SIGNAL(clicked()), this, SLOT(initializationClicked()));
releaseCapture = new QPushButton("KILL SYSTEM", this);
releaseCapture->setGeometry(QRect(QPoint(10, height - 60), QSize(100, 50)));
connect(releaseCapture, SIGNAL(clicked()), this, SLOT(stopCapture()));
button1 = new QPushButton("BUTTON 1", this);
button1->setGeometry(QRect(QPoint(width / 2 - 100, height - 120), QSize(150, 100)));
b1 = Point(width / 2 - 100, height - 120);
// receive the signal
connect(button1, SIGNAL(valueChangedButton1(unsigned int)), this, SLOT(button1clicked()));
button2 = new QPushButton("BUTTON 2", this);
button2->setGeometry(QRect(QPoint(width / 2 + 100, height - 120), QSize(150, 100)));
b2 = Point(width / 2 + 100, height - 120);
interactionLabel = new QLabel(this);
interactionLabel->setText("log: ");
interactionLabel->setGeometry(QRect(QPoint(10, 15), QSize(200, 20)));
interactionLabel->setFont(f);
interactionType = new QLabel(this);
interactionType->setText("kind of interaction");
interactionType->setGeometry(QRect(QPoint(110,15), QSize(250, 20)));
interactionType->setFont(i);
}
void MainWindow::initializationClicked()
{
controllMainVideoFlow();
}
void MainWindow::controllMainVideoFlow()
{
SerialPort arduino(PORT);
cap = VideoCapture(0);
if(!cap.isOpen())
{
cout << "no video feed" << endl;
}else
{
if(arduino.isConnected())
{
while(cap.isOpen())
{
cap >> src;
arduino.readSerialPort(output, MAX_DATA_LENGTH);
fromArduino = strlen(output);
if(fromArduino == 0)
{
isChecked = false;
}
else if(fromArduino != 0)
{
isChecked = true;
// emit the signal
emitSignalB1();
}
imshow("SOURCE", src);
qApp->processEvents();
if (cv::waitKey(30) == 'q') break;
}
cap.release();
src.release();
}
}
}
void MainWindow::emitSignalB1()
{
// emit the signal
emit valueChangedButton1(fromArduino);
}
void MainWindow::stopCapture()
{
interactionType->setText("system killed");
cap.release();
src.release();
destroyAllWindows();
}
void MainWindow::button1clicked()
{
interactionType->setText("button 1 clicked");
}
void MainWindow::button2clicked()
{
interactionType->setText("button 2 clicked");
}
【问题讨论】:
标签: c++ opencv user-interface computer-vision qt5