#include "camera.h"
#include "ui_camera.h"
#include<QDebug>
Camera::Camera(QWidget *parent) :
QWidget(parent),
ui(new Ui::Camera)
{
ui->setupUi(this);
timer=new QTimer(this);
vd=NULL;
connect(ui->btn_Start,SIGNAL(clicked()),this,SLOT(slotStart()));
connect(ui->btn_Catch,SIGNAL(clicked()),this,SLOT(slotCatch()));
connect(ui->btn_Continue,SIGNAL(clicked()),this,SLOT(slotContinue()));
connect(ui->btn_Save,SIGNAL(clicked()),this,SLOT(slotSave()));
connect(timer,SIGNAL(timeout()),this,SLOT(slotUpdata()));
ui->btn_Catch->setEnabled(false);
ui->btn_Save->setEnabled(false);
ui->btn_Continue->setEnabled(false);
}
Camera::~Camera()
{
vd->CloseDev();
delete ui;
}
void Camera::slotStart()
{
if (ui->btn_Start->text()=="Start")
{
if (ui->rbn_Out->isChecked())
dev=0;
else dev=1;
vd=new VideoDevice(this,dev);
vd->OpenDev();
timer->start(33);
ui->btn_Start->setText("Stop");
ui->btn_Catch->setEnabled(true);
}
else {
ui->btn_Start->setText("Start");
ui->btn_Catch->setEnabled(false);
ui->btn_Continue->setEnabled(false);
ui->btn_Save->setEnabled(false);
timer->stop();
vd->CloseDev();
ui->lbl_Image->clear();
}
}
void Camera::slotUpdata()
{
frame=vd->GetFrame();
ui->lbl_Image->setPixmap(QPixmap::fromImage(frame));
}
void Camera::slotCatch()
{
ui->btn_Continue->setEnabled(true);
ui->btn_Save->setEnabled(true);
timer->stop();
}
void Camera::slotContinue()
{
timer->start();
}
void Camera::slotSave()
{
QString imageName=NULL;
imageName=QFileDialog::getSaveFileName(this,tr("Save image"),"",tr("(*.jpg)"));
if (imageName!=NULL)
frame.save(imageName,"JPG",-1);
}
- 1
- 2
前往页