Finish up
This commit is contained in:
@ -17,11 +17,23 @@ void CvImageViewer::setImage(Camera::Image img)
|
||||
{
|
||||
image_ = img.mat;
|
||||
if(image_.type() == CV_8UC3 || image_.type() == CV_8SC3)
|
||||
{
|
||||
qimage_ = QImage(image_.data, image_.cols, image_.rows, image_.step, QImage::Format_RGB888);
|
||||
}
|
||||
else if(image_.type() == CV_8UC1 || image_.type() == CV_8SC1)
|
||||
{
|
||||
qimage_ = QImage(image_.data, image_.cols, image_.rows, image_.step, QImage::Format_Grayscale8);
|
||||
}
|
||||
else if(image_.type() == CV_32FC1 || image_.type() == CV_64FC1)
|
||||
{
|
||||
img.mat.convertTo(image_, CV_8UC1, 255, 0);
|
||||
qimage_ = QImage(image_.data, image_.cols, image_.rows, image_.step, QImage::Format_Grayscale8);
|
||||
}
|
||||
else
|
||||
{
|
||||
img.mat.convertTo(image_, CV_8UC1, 255, 0);
|
||||
qimage_ = QImage(image_.data, image_.cols, image_.rows, image_.step, QImage::Format_Grayscale8);
|
||||
}
|
||||
update();
|
||||
}
|
||||
|
||||
@ -29,8 +41,15 @@ void CvImageViewer::paintEvent(QPaintEvent* event)
|
||||
{
|
||||
Q_UNUSED(event)
|
||||
QPainter painter(this);
|
||||
|
||||
if(!fixedOnWidth_)
|
||||
painter.drawImage(QRect((rect().width()-rect().height())/2, rect().y(), rect().height(), rect().height()), qimage_);
|
||||
{
|
||||
double ratio = qimage_.size().width() / qimage_.size().height();
|
||||
painter.drawImage(QRect((rect().width()-rect().height())/2, rect().y(), rect().height()*ratio, rect().height()), qimage_);
|
||||
}
|
||||
else
|
||||
painter.drawImage(QRect(rect().x(), (rect().height()-rect().width())/2, rect().width(), rect().width()), qimage_);
|
||||
{
|
||||
double ratio = qimage_.size().height() / qimage_.size().width();
|
||||
painter.drawImage(QRect(rect().x(), (rect().height()-rect().width())/2, rect().width(), rect().width()*ratio), qimage_);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user