#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "QScrollArea"
#include "QScrollBar"
#define PROCESS_FRAME_WIDTH (368)
#define PROCESS_FRAME_HEIGHT (276)
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
scrollArea_Car
->setBackgroundRole
(QPalette::Dark);
scaleFactor = 1.0;
QTimer::singleShot(0,
this,
SLOT(myThread
()));
}
void MainWindow::myThread()
{
myframewidget = new IplImageWidget(this);
frame_widget_image = cvLoadImage("myimageunavailable.png",CV_LOAD_IMAGE_COLOR);
/* update frame widget */
ui->frame_image->addWidget(scrollArea_Car,0,0,1,1,0);
myframewidget->setIplImage(frame_widget_image);
scrollArea_Car->setWidget(myframewidget);
myframewidget->show();
myframewidget->adjustSize();
x_start_car = ui->frame->x() + ui->groupBox_2->x() + myframewidget->x();
y_start_car = ui->frame->y() + ui->groupBox_2->y() + myframewidget->y();
x_end_car = ui->frame->x() + ui->groupBox_2->x() + myframewidget->x() + myframewidget->width();
y_end_car = ui->frame->y() + ui->groupBox_2->y() + myframewidget->y() + myframewidget->height();
}
{
if(((event->pos().x() >= x_start_car) && (event->pos().x() <= x_end_car)) && ((event->pos().y() >= y_start_car) && (event->pos().y() <= y_end_car)))
{
int numDegree = event->delta() / 8;
double numStep = numDegree / 15.0f ;
numStep = pow(0.95f,numStep);
scaleImage(numStep);
}
}
void MainWindow::scaleImage(double factor)
{
Q_ASSERT(myframewidget);
scaleFactor *= factor;
myframewidget->resize(scaleFactor * PROCESS_FRAME_WIDTH,scaleFactor * PROCESS_FRAME_HEIGHT);
IplImage* global_image_car_grey = cvCreateImage(cvSize(global_image_car->width,global_image_car->height),IPL_DEPTH_8U,1);
IplImage* global_image_car_resized = cvCreateImage(cvSize(scaleFactor * PROCESS_FRAME_WIDTH,scaleFactor * PROCESS_FRAME_HEIGHT),IPL_DEPTH_8U,1);
cvCvtColor(global_image_car,global_image_car_grey,CV_RGB2GRAY);
cvResize(global_image_car_grey,global_image_car_resized,CV_INTER_LINEAR);
myframewidget->setIplImage(global_image_car_resized);
myframewidget->show();
cvReleaseImage(&global_image_car_resized);
cvReleaseImage(&global_image_car_grey);
adjustScrollBar(scrollArea_Car->horizontalScrollBar(), factor);
adjustScrollBar(scrollArea_Car->verticalScrollBar(), factor);
}
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "QScrollArea"
#include "QScrollBar"
#define PROCESS_FRAME_WIDTH (368)
#define PROCESS_FRAME_HEIGHT (276)
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
scrollArea_Car = new QScrollArea;
scrollArea_Car->setBackgroundRole(QPalette::Dark);
scaleFactor = 1.0;
QTimer::singleShot(0, this, SLOT(myThread()));
}
void MainWindow::myThread()
{
myframewidget = new IplImageWidget(this);
frame_widget_image = cvLoadImage("myimageunavailable.png",CV_LOAD_IMAGE_COLOR);
/* update frame widget */
ui->frame_image->addWidget(scrollArea_Car,0,0,1,1,0);
myframewidget->setIplImage(frame_widget_image);
scrollArea_Car->setWidget(myframewidget);
myframewidget->show();
myframewidget->adjustSize();
x_start_car = ui->frame->x() + ui->groupBox_2->x() + myframewidget->x();
y_start_car = ui->frame->y() + ui->groupBox_2->y() + myframewidget->y();
x_end_car = ui->frame->x() + ui->groupBox_2->x() + myframewidget->x() + myframewidget->width();
y_end_car = ui->frame->y() + ui->groupBox_2->y() + myframewidget->y() + myframewidget->height();
}
void MainWindow::wheelEvent(QWheelEvent *event)
{
if(((event->pos().x() >= x_start_car) && (event->pos().x() <= x_end_car)) && ((event->pos().y() >= y_start_car) && (event->pos().y() <= y_end_car)))
{
int numDegree = event->delta() / 8;
double numStep = numDegree / 15.0f ;
numStep = pow(0.95f,numStep);
scaleImage(numStep);
}
}
void MainWindow::scaleImage(double factor)
{
Q_ASSERT(myframewidget);
scaleFactor *= factor;
myframewidget->resize(scaleFactor * PROCESS_FRAME_WIDTH,scaleFactor * PROCESS_FRAME_HEIGHT);
IplImage* global_image_car_grey = cvCreateImage(cvSize(global_image_car->width,global_image_car->height),IPL_DEPTH_8U,1);
IplImage* global_image_car_resized = cvCreateImage(cvSize(scaleFactor * PROCESS_FRAME_WIDTH,scaleFactor * PROCESS_FRAME_HEIGHT),IPL_DEPTH_8U,1);
cvCvtColor(global_image_car,global_image_car_grey,CV_RGB2GRAY);
cvResize(global_image_car_grey,global_image_car_resized,CV_INTER_LINEAR);
myframewidget->setIplImage(global_image_car_resized);
myframewidget->show();
cvReleaseImage(&global_image_car_resized);
cvReleaseImage(&global_image_car_grey);
adjustScrollBar(scrollArea_Car->horizontalScrollBar(), factor);
adjustScrollBar(scrollArea_Car->verticalScrollBar(), factor);
}
To copy to clipboard, switch view to plain text mode
Bookmarks