#include "dialog.h"
#include "ui_dialog.h"
#include <QDebug>
#include <QFile>
#include <QTextStream>
ui(new Ui::Dialog)
{
ui->setupUi(this);
cam = cvCaptureFromCAM(-1);
if(cam==NULL)
qDebug()<<"error";
timer->start(30);
connect(timer,SIGNAL(timeout()),this,SLOT(getFrame()));
connect(ui->hueSlide1,SIGNAL(valueChanged(int)),this,SLOT(saveValue()));
connect(ui->hueSlide2,SIGNAL(valueChanged(int)),this,SLOT(saveValue()));
connect(ui->satSlide1,SIGNAL(valueChanged(int)),this,SLOT(saveValue()));
connect(ui->satSlide2,SIGNAL(valueChanged(int)),this,SLOT(saveValue()));
connect(ui->lumSlide1,SIGNAL(valueChanged(int)),this,SLOT(saveValue()));
connect(ui->lumSlide2,SIGNAL(valueChanged(int)),this,SLOT(saveValue()));
connect(ui->load,SIGNAL(clicked()),this,SLOT(loadValue()));
}
void Dialog::getFrame()
{
frame = cvQueryFrame(cam);
QImage image
= QImage ((const uchar
*)frame
->imageData,frame
->width,frame
->height,
QImage::Format_RGB888).
rgbSwapped();
//rgbSwapped() make color better ui
->original
->setPixmap
(QPixmap::fromImage(image
));
}
void Dialog::prcFrame()
{
imgHSV= cvCreateImage(cvSize(frame->width,frame->height),IPL_DEPTH_8U,3);
cvCvtColor(frame,imgHSV,CV_BGR2HSV);
//threshed , get value from slider value
// QImage filterImg = QImage ((const uchar*)imgHSV->imageData,imgHSV->width,imgHSV->height,QImage::Format_RGB888);
// ui->filter->setPixmap(QPixmap::fromImage(filterImg));
}
void Dialog::saveValue()
{
int h_slide1 = ui->hueSlide1->value();
int h_slide2 = ui->hueSlide2->value();
int s_slide1 = ui->satSlide1->value();
int s_slide2 = ui->satSlide2->value();
int l_slide1 = ui->lumSlide1->value();
int l_slide2 = ui->lumSlide2->value();
QFile valueHSV
("/home/pi/valueHSV/hsv.txt");
if(!valueHSV.
open(QIODevice::WriteOnly|QIODevice
::Text)) {
qDebug() << "cannot open file for writing"<<endl;
return;
}
hsv << "<HUE LOW>" <<h_slide1<<endl;
hsv << "<HUE HIGH>" <<h_slide2<<endl;
hsv << "<SAT LOW>" <<s_slide1<<endl;
hsv << "<SAT HIGH>" <<s_slide2<<endl;
hsv << "<LUM LOW>" <<l_slide1<<endl;
hsv << "<LUM HIGH>" <<l_slide2<<endl;
//qDebug() << "H_low" << h_slide1;
//qDebug() << "H_high" << h_slide2;
//valueHSV.close();
}
void Dialog::loadValue()
{
QFile valueHSV
("/home/pi/valueHSV/hsv.txt");
if(!valueHSV.
open(QIODevice::ReadOnly|QIODevice
::Text)) {
qDebug() << "cannot open file for reading"<<endl;
return;
}
while (!hsv.atEnd())
{
if(load.isNull())
break;
}
{
int h1 = str.toInt();
qDebug() << "value"<<h1;
}
return;
}
Dialog::~Dialog()
{
timer->stop();
cvReleaseCapture(&cam);
delete ui;
}
#include "dialog.h"
#include "ui_dialog.h"
#include <QDebug>
#include <QFile>
#include <QTextStream>
Dialog::Dialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::Dialog)
{
ui->setupUi(this);
timer = new QTimer(this);
cam = cvCaptureFromCAM(-1);
if(cam==NULL)
qDebug()<<"error";
timer->start(30);
connect(timer,SIGNAL(timeout()),this,SLOT(getFrame()));
connect(ui->hueSlide1,SIGNAL(valueChanged(int)),this,SLOT(saveValue()));
connect(ui->hueSlide2,SIGNAL(valueChanged(int)),this,SLOT(saveValue()));
connect(ui->satSlide1,SIGNAL(valueChanged(int)),this,SLOT(saveValue()));
connect(ui->satSlide2,SIGNAL(valueChanged(int)),this,SLOT(saveValue()));
connect(ui->lumSlide1,SIGNAL(valueChanged(int)),this,SLOT(saveValue()));
connect(ui->lumSlide2,SIGNAL(valueChanged(int)),this,SLOT(saveValue()));
connect(ui->load,SIGNAL(clicked()),this,SLOT(loadValue()));
}
void Dialog::getFrame()
{
frame = cvQueryFrame(cam);
QImage image = QImage ((const uchar*)frame->imageData,frame->width,frame->height,QImage::Format_RGB888).rgbSwapped();//rgbSwapped() make color better
ui->original->setPixmap(QPixmap::fromImage(image));
}
void Dialog::prcFrame()
{
imgHSV= cvCreateImage(cvSize(frame->width,frame->height),IPL_DEPTH_8U,3);
cvCvtColor(frame,imgHSV,CV_BGR2HSV);
//threshed , get value from slider value
// QImage filterImg = QImage ((const uchar*)imgHSV->imageData,imgHSV->width,imgHSV->height,QImage::Format_RGB888);
// ui->filter->setPixmap(QPixmap::fromImage(filterImg));
}
void Dialog::saveValue()
{
int h_slide1 = ui->hueSlide1->value();
int h_slide2 = ui->hueSlide2->value();
int s_slide1 = ui->satSlide1->value();
int s_slide2 = ui->satSlide2->value();
int l_slide1 = ui->lumSlide1->value();
int l_slide2 = ui->lumSlide2->value();
QFile valueHSV("/home/pi/valueHSV/hsv.txt");
if(!valueHSV.open(QIODevice::WriteOnly|QIODevice::Text))
{
qDebug() << "cannot open file for writing"<<endl;
return;
}
QTextStream hsv(&valueHSV);
hsv << "<HUE LOW>" <<h_slide1<<endl;
hsv << "<HUE HIGH>" <<h_slide2<<endl;
hsv << "<SAT LOW>" <<s_slide1<<endl;
hsv << "<SAT HIGH>" <<s_slide2<<endl;
hsv << "<LUM LOW>" <<l_slide1<<endl;
hsv << "<LUM HIGH>" <<l_slide2<<endl;
//qDebug() << "H_low" << h_slide1;
//qDebug() << "H_high" << h_slide2;
//valueHSV.close();
}
void Dialog::loadValue()
{
QStringList list;
QFile valueHSV("/home/pi/valueHSV/hsv.txt");
if(!valueHSV.open(QIODevice::ReadOnly|QIODevice::Text))
{
qDebug() << "cannot open file for reading"<<endl;
return;
}
QTextStream hsv(&valueHSV);
while (!hsv.atEnd())
{
QString load=hsv.readLine();
if(load.isNull())
break;
}
foreach(QString str, list)
{
int h1 = str.toInt();
qDebug() << "value"<<h1;
}
return;
}
Dialog::~Dialog()
{
timer->stop();
cvReleaseCapture(&cam);
delete ui;
}
To copy to clipboard, switch view to plain text mode
Bookmarks