基于opencv的图像分析串口发送,单片机接收,输出脉冲继而控制步进电机转动
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QDebug>
#include <QtSerialPort/QSerialPort>
#include <QtSerialPort/QSerialPortInfo>
#include "imagebuffer.h"
#include "wlinkusbcamera.h"
using namespace cv;
#include<QTimer>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
void Init() ;
void PidControl(int,int,int,int);
void sendSerialPortData(long , char,long );
void handleSerialError(QSerialPort::SerialPortError error,bool &);
private slots:
void on_clearButton_clicked();
void on_sendButton_clicked();
void on_openButton_clicked();
void Read_Data();
void slot1();
void on_PidChange_valueChanged(int value);
void on_PidChange_sliderReleased();
void on_PidChange_sliderPressed();
void on_pushButton_clicked();
void on_pushButton_2_clicked();
void on_pushButton_3_clicked();
private:
Ui::MainWindow *ui;
QSerialPort *serial;
WLinkUsbCamera *tab ;
QTimer *timer;
int LastError; //Error[-1]上一次
int PrevError; //Error[-2]上两次
int Output;
};
#endif // MAINWINDOW_H
mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <opencv2/opencv.hpp>
#include "opencv2\highgui\highgui.hpp"
#include <QMessageBox>
#include<QDebug>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow),LastError(0),PrevError(0),Output(0)
{
ui->setupUi(this);
Init();
qDebug()<<"sioflong"<<sizeof(long)<<sizeof(int)<<sizeof(char);