I am so sorry for that.
i am doing a GUI to filter out the colour i do not want,
I would like to get value of H, S and V using slider and store these value inside a .txt file.
After that i would call these value into another function to processing and show a filter stream video,
I did use QFile and QTextStreamer, but could not get through.
below is my code
//getCam.pro
######################################################################
# Automatically generated by qmake (2.01a) Tue Jun 24 17:53:36 2014
######################################################################
CONFIG += console
TEMPLATE = app
TARGET =
DEPENDPATH += .
INCLUDEPATH += .
# Input
HEADERS += dialog.h
FORMS += dialog.ui
SOURCES += dialog.cpp main.cpp
//getCam.pro
######################################################################
# Automatically generated by qmake (2.01a) Tue Jun 24 17:53:36 2014
######################################################################
CONFIG += console
TEMPLATE = app
TARGET =
DEPENDPATH += .
INCLUDEPATH += .
# Input
HEADERS += dialog.h
FORMS += dialog.ui
SOURCES += dialog.cpp main.cpp
To copy to clipboard, switch view to plain text mode
//main.cpp
#include <QApplication>
#include "dialog.h"
int main(int argc, char *argv[])
{
Dialog w;
w.show();
return a.exec();
}
//main.cpp
#include <QApplication>
#include "dialog.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Dialog w;
w.show();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
//dialog.h
#ifndef DIALOG_H
#define DIALOG_H
#include <QDialog>
#include "opencv/cv.h"
#include "opencv/highgui.h"
#include <QTimer>
#include <QPixmap>
namespace Ui
{
class Dialog;
}
{
Q_OBJECT
public:
explicit Dialog
(QWidget *parent
= 0);
~Dialog();
private:
Ui::Dialog *ui;
CvCapture *cam;
IplImage *frame,*imgHSV;
private slots:
void getFrame();
void prcFrame();
void getValue();
};
#endif // DIALOG_H
//dialog.h
#ifndef DIALOG_H
#define DIALOG_H
#include <QDialog>
#include "opencv/cv.h"
#include "opencv/highgui.h"
#include <QTimer>
#include <QPixmap>
namespace Ui
{
class Dialog;
}
class Dialog : public QDialog
{
Q_OBJECT
public:
explicit Dialog(QWidget *parent = 0);
~Dialog();
private:
Ui::Dialog *ui;
CvCapture *cam;
IplImage *frame,*imgHSV;
QTimer *timer;
private slots:
void getFrame();
void prcFrame();
void getValue();
};
#endif // DIALOG_H
To copy to clipboard, switch view to plain text mode
//dialog.cpp
#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()));
}
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));
}
[COLOR="#FFFF00"]void Dialog::getValue()
{
int h_slide1 = ui->hueSlide1->value();
QFile valueHSV
("/home/pi/valueHSV/hsv.txt");
if(!valueHSV.
open(QIODevice::WriteOnly|QIODevice
::Text)) {
qDebug() << "cannot open file for writing"<<endl;
return;
}
hsv <<h_slide1;
qDebug() << "Value=" << h_slide1;
valueHSV.close();
}[/COLOR]
Dialog::~Dialog()
{
timer->stop();
cvReleaseCapture(&cam);
delete ui;
}
//dialog.cpp
#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()));
}
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));
}
[COLOR="#FFFF00"]void Dialog::getValue()
{
int h_slide1 = ui->hueSlide1->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 <<h_slide1;
qDebug() << "Value=" << h_slide1;
valueHSV.close();
}[/COLOR]
Dialog::~Dialog()
{
timer->stop();
cvReleaseCapture(&cam);
delete ui;
}
To copy to clipboard, switch view to plain text mode
//compile output
04:45:50: Running steps for project getCam...
04:45:50: Configuration unchanged, skipping qmake step.
04:45:50: Starting: "/usr/bin/make" -w
make: Entering directory `/home/pi/qt/getCam'
/usr/bin/qmake-qt4 -spec /usr/share/qt4/mkspecs/linux-g++ -o Makefile getCam.pro
make: Leaving directory `/home/pi/qt/getCam'
make: Entering directory `/home/pi/qt/getCam'
g++ -c -pipe -O2 -Wall -W -D_REENTRANT -DQT_WEBKIT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. -I. -I. -I/usr/local/include/opencv -o dialog.o dialog.cpp
g++ -c -pipe -O2 -Wall -W -D_REENTRANT -DQT_WEBKIT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. -I. -I. -I/usr/local/include/opencv -o main.o main.cpp
/usr/bin/moc-qt4 -DQT_WEBKIT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. -I. -I. -I/usr/local/include/opencv dialog.h -o moc_dialog.cpp
g++ -c -pipe -O2 -Wall -W -D_REENTRANT -DQT_WEBKIT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. -I. -I. -I/usr/local/include/opencv -o moc_dialog.o moc_dialog.cpp
g++ -Wl,-O1 -o getCam dialog.o main.o moc_dialog.o -L/usr/lib/arm-linux-gnueabihf /usr/local/lib/libopencv_core.so /usr/local/lib/libopencv_highgui.so /usr/local/lib/libopencv_ml.so /usr/local/lib/libopencv_imgproc.so -lQtGui -lQtCore -lpthread
make: Leaving directory `/home/pi/qt/getCam'
04:47:35: The process "/usr/bin/make" exited normally.
//compile output
04:45:50: Running steps for project getCam...
04:45:50: Configuration unchanged, skipping qmake step.
04:45:50: Starting: "/usr/bin/make" -w
make: Entering directory `/home/pi/qt/getCam'
/usr/bin/qmake-qt4 -spec /usr/share/qt4/mkspecs/linux-g++ -o Makefile getCam.pro
make: Leaving directory `/home/pi/qt/getCam'
make: Entering directory `/home/pi/qt/getCam'
g++ -c -pipe -O2 -Wall -W -D_REENTRANT -DQT_WEBKIT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. -I. -I. -I/usr/local/include/opencv -o dialog.o dialog.cpp
g++ -c -pipe -O2 -Wall -W -D_REENTRANT -DQT_WEBKIT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. -I. -I. -I/usr/local/include/opencv -o main.o main.cpp
/usr/bin/moc-qt4 -DQT_WEBKIT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. -I. -I. -I/usr/local/include/opencv dialog.h -o moc_dialog.cpp
g++ -c -pipe -O2 -Wall -W -D_REENTRANT -DQT_WEBKIT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. -I. -I. -I/usr/local/include/opencv -o moc_dialog.o moc_dialog.cpp
g++ -Wl,-O1 -o getCam dialog.o main.o moc_dialog.o -L/usr/lib/arm-linux-gnueabihf /usr/local/lib/libopencv_core.so /usr/local/lib/libopencv_highgui.so /usr/local/lib/libopencv_ml.so /usr/local/lib/libopencv_imgproc.so -lQtGui -lQtCore -lpthread
make: Leaving directory `/home/pi/qt/getCam'
04:47:35: The process "/usr/bin/make" exited normally.
To copy to clipboard, switch view to plain text mode
and this is the pic of GUI design
snapshot1.jpg
Please advise
regards
YDYD
Bookmarks