1、实现了光谱仪简单的采集功能:曝光、调焦、暗电流、采集影像、保存影像;
2、设置光谱仪帧率、曝光时间、gain; 3、在页面中嵌入了rgb相机图传(通过opencv实现); 4、平台的相机位置模拟、x/y马达的分别控制、x/y马达的量程检测; 5、轨迹规划; 6、加入了张卓的自动调焦模块; 7、加入了自动电源控制;
This commit is contained in:
227
HPPA/ImageViewer.cpp
Normal file
227
HPPA/ImageViewer.cpp
Normal file
@ -0,0 +1,227 @@
|
||||
#include "stdafx.h"
|
||||
#include <iostream>
|
||||
|
||||
#include <QWheelEvent>
|
||||
#include <QPoint>
|
||||
|
||||
#include "ImageViewer.h"
|
||||
|
||||
|
||||
#define VIEW_CENTER viewport()->rect().center()
|
||||
#define VIEW_WIDTH viewport()->rect().width()
|
||||
#define VIEW_HEIGHT viewport()->rect().height()
|
||||
|
||||
|
||||
ImageViewer::ImageViewer(QWidget* pParent) :QGraphicsView(pParent)
|
||||
{
|
||||
m_qtGraphicsScene = new QGraphicsScene(this);
|
||||
this->setScene(m_qtGraphicsScene);
|
||||
|
||||
m_framNumberLabel = new QLabel(this);
|
||||
m_framNumberLabel->setAlignment(Qt::AlignHCenter);
|
||||
m_framNumberLabel->setAlignment(Qt::AlignVCenter);
|
||||
|
||||
QFont ft;
|
||||
ft.setPointSize(14);
|
||||
m_framNumberLabel->setFont(ft);
|
||||
m_framNumberLabel->setText("0");
|
||||
|
||||
|
||||
m_GraphicsPixmapItemHandle = nullptr;
|
||||
|
||||
m_scale = 1.0;
|
||||
m_zoomDelta = 0.1;
|
||||
m_translateSpeed = 1.0;
|
||||
m_bMouseTranslate = false;
|
||||
|
||||
|
||||
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
}
|
||||
|
||||
ImageViewer::~ImageViewer()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void ImageViewer::DisplayFrameNumber(int frameNumber)
|
||||
{
|
||||
m_framNumberLabel->setText(QString::number(frameNumber));
|
||||
m_framNumberLabel->adjustSize();
|
||||
}
|
||||
|
||||
void ImageViewer::SetImage(QPixmap *image)
|
||||
{
|
||||
if (!HasImage())
|
||||
{
|
||||
m_GraphicsPixmapItemHandle = m_qtGraphicsScene->addPixmap(*image);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_GraphicsPixmapItemHandle->setPixmap(*image);
|
||||
}
|
||||
|
||||
setSceneRect(QRectF(image->rect()));
|
||||
|
||||
}
|
||||
|
||||
bool ImageViewer::HasImage()
|
||||
{
|
||||
if (m_GraphicsPixmapItemHandle == nullptr)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
void ImageViewer::wheelEvent(QWheelEvent *event)
|
||||
{
|
||||
//qDebug() << "---------------+++++++++++++++++++++++++++++++++++++++++++++++++++ ";
|
||||
if (true)//HasImage()
|
||||
{
|
||||
//Χ<><CEA7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŵ<EFBFBD><C5B4><EFBFBD>https://blog.csdn.net/GoForwardToStep/article/details/77035287?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-3.channel_param&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-3.channel_param
|
||||
// <20><>ȡ<EFBFBD><C8A1>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>view<65><77>λ<EFBFBD><CEBB>;
|
||||
QPointF cursorPoint = event->pos();
|
||||
// <20><>ȡ<EFBFBD><C8A1>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>scene<6E><65>λ<EFBFBD><CEBB>;
|
||||
QPointF scenePos = this->mapToScene(QPoint(cursorPoint.x(), cursorPoint.y()));
|
||||
|
||||
// <20><>ȡview<65>Ŀ<EFBFBD><C4BF><EFBFBD>;
|
||||
qreal viewWidth = this->viewport()->width();
|
||||
qreal viewHeight = this->viewport()->height();
|
||||
|
||||
// <20><>ȡ<EFBFBD><C8A1>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>λ<EFBFBD><CEBB><EFBFBD>൱<EFBFBD><E0B5B1>view<65><77>С<EFBFBD>ĺ<EFBFBD><C4BA>ݱ<EFBFBD><DDB1><EFBFBD>;
|
||||
qreal hScale = cursorPoint.x() / viewWidth;
|
||||
qreal vScale = cursorPoint.y() / viewHeight;
|
||||
|
||||
|
||||
// <20><><EFBFBD>ֵĹ<D6B5><C4B9><EFBFBD><EFBFBD><EFBFBD>
|
||||
QPoint scrollAmount = event->angleDelta();
|
||||
// <20><>ֵ<EFBFBD><D6B5>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD>Զ<EFBFBD><D4B6>ʹ<EFBFBD><CAB9><EFBFBD>߷Ŵ<DFB7><C5B4><EFBFBD>ֵ<EFBFBD><D6B5>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С
|
||||
scrollAmount.y() > 0 ? zoomIn() : zoomOut();
|
||||
|
||||
|
||||
// <20><>scene<6E><65><EFBFBD><EFBFBD>ת<EFBFBD><D7AA>Ϊ<EFBFBD>Ŵ<EFBFBD><C5B4><EFBFBD>С<EFBFBD><D0A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>;
|
||||
QPointF viewPoint = this->matrix().map(scenePos);
|
||||
// ͨ<><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>view<65>Ŵ<EFBFBD><C5B4><EFBFBD>С<EFBFBD><D0A1><EFBFBD><EFBFBD>չʾscene<6E><65>λ<EFBFBD><CEBB>;
|
||||
horizontalScrollBar()->setValue(int(viewPoint.x() - viewWidth * hScale));
|
||||
verticalScrollBar()->setValue(int(viewPoint.y() - viewHeight * vScale));
|
||||
}
|
||||
|
||||
QGraphicsView::wheelEvent(event);
|
||||
}
|
||||
|
||||
void ImageViewer::scaling(qreal scaleFactor)
|
||||
{
|
||||
//qDebug() << this->sceneRect();
|
||||
scale(scaleFactor, scaleFactor);
|
||||
}
|
||||
|
||||
void ImageViewer::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
if (event->button()==Qt::LeftButton)
|
||||
{
|
||||
m_bMouseTranslate = true;
|
||||
m_lastMousePos = event->pos();
|
||||
|
||||
//qDebug() << mapToScene(m_lastMousePos);
|
||||
|
||||
emit leftMouseButtonPressed(mapToScene(m_lastMousePos).x(), mapToScene(m_lastMousePos).y());
|
||||
}
|
||||
|
||||
|
||||
//If you do not perform all the necessary work in your implementation of the virtual function, you may need to call the base class's implementation.
|
||||
QGraphicsView::mousePressEvent(event);
|
||||
}
|
||||
|
||||
void ImageViewer::mouseMoveEvent(QMouseEvent *event)
|
||||
{
|
||||
if (m_bMouseTranslate){
|
||||
QPointF mouseDelta = mapToScene(event->pos()) - mapToScene(m_lastMousePos);
|
||||
translate(mouseDelta);
|
||||
}
|
||||
|
||||
m_lastMousePos = event->pos();
|
||||
QGraphicsView::mousePressEvent(event);
|
||||
}
|
||||
|
||||
void ImageViewer::mouseReleaseEvent(QMouseEvent *event)
|
||||
{
|
||||
m_bMouseTranslate = false;
|
||||
QGraphicsView::mouseReleaseEvent(event);
|
||||
}
|
||||
|
||||
void ImageViewer::mouseDoubleClickEvent(QMouseEvent *event)
|
||||
{
|
||||
QGraphicsView::mouseDoubleClickEvent(event);
|
||||
}
|
||||
|
||||
void ImageViewer::zoomIn()
|
||||
{
|
||||
zoom(1 + m_zoomDelta);
|
||||
}
|
||||
|
||||
void ImageViewer::zoomOut()
|
||||
{
|
||||
zoom(1 - m_zoomDelta);
|
||||
}
|
||||
|
||||
void ImageViewer::zoom(float scaleFactor)
|
||||
{
|
||||
// <20><>ֹ<EFBFBD><D6B9>С<EFBFBD><D0A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
qreal factor = transform().scale(scaleFactor, scaleFactor).mapRect(QRectF(0, 0, 1, 1)).width();
|
||||
if (factor < 0.07 || factor > 100)
|
||||
return;
|
||||
|
||||
scale(scaleFactor, scaleFactor);
|
||||
m_scale *= scaleFactor;
|
||||
}
|
||||
|
||||
void ImageViewer::translate(QPointF delta)
|
||||
{
|
||||
// <20><><EFBFBD>ݵ<EFBFBD>ǰ zoom <20><><EFBFBD><EFBFBD>ƽ<EFBFBD><C6BD><EFBFBD><EFBFBD>
|
||||
delta *= m_scale;
|
||||
delta *= m_translateSpeed;
|
||||
|
||||
////<2F><><EFBFBD><EFBFBD>1<EFBFBD><31>
|
||||
//scene()->setSceneRect(scene()->sceneRect().x() - delta.x(), scene()->sceneRect().y() - delta.y(),
|
||||
// scene()->sceneRect().width(), scene()->sceneRect().height());
|
||||
//scene()->update();
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD>2<EFBFBD><32>
|
||||
// view <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>µĵ<C2B5><C4B5><EFBFBD>Ϊê<CEAA><C3AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ scene
|
||||
setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
|
||||
QPoint newCenter(VIEW_WIDTH / 2 - delta.x(), VIEW_HEIGHT / 2 - delta.y());
|
||||
centerOn(mapToScene(newCenter));
|
||||
|
||||
// scene <20><> view <20><><EFBFBD><EFBFBD><EFBFBD>ĵ<EFBFBD><C4B5><EFBFBD>Ϊê<CEAA><C3AA>
|
||||
setTransformationAnchor(QGraphicsView::AnchorViewCenter);
|
||||
}
|
||||
|
||||
void ImageViewer::setTranslateSpeed(qreal speed)
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>ٶȷ<D9B6>Χ
|
||||
Q_ASSERT_X(speed >= 0.0 && speed <= 2.0,
|
||||
"InteractiveView::setTranslateSpeed", "Speed should be in range [0.0, 2.0].");
|
||||
m_translateSpeed = speed;
|
||||
}
|
||||
|
||||
qreal ImageViewer::translateSpeed() const
|
||||
{
|
||||
return m_translateSpeed;
|
||||
}
|
||||
|
||||
void ImageViewer::setZoomDelta(qreal delta)
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Χ
|
||||
Q_ASSERT_X(delta >= 0.0 && delta <= 1.0,
|
||||
"InteractiveView::setZoomDelta", "Delta should be in range [0.0, 1.0].");
|
||||
m_zoomDelta = delta;
|
||||
}
|
||||
|
||||
qreal ImageViewer::zoomDelta() const
|
||||
{
|
||||
return m_zoomDelta;
|
||||
}
|
||||
Reference in New Issue
Block a user