Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

windows and OS X support #2

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 33 additions & 10 deletions BLDC_Logger.pro
Original file line number Diff line number Diff line change
Expand Up @@ -11,41 +11,64 @@ QT += core
QT += gui
QT += printsupport
QT += multimedia
QT += serialport

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = BLDC_Logger
CONFIG += console
CONFIG -= app_bundle

LIBS += -lopencv_core -lopencv_imgproc -lopencv_highgui \
-lopencv_ml -lopencv_video -lopencv_features2d \
-lopencv_calib3d -lopencv_objdetect -lopencv_contrib \
-lopencv_legacy -lopencv_flann
macx: QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.9

win32 {
OPENCV_PATH = D:/Dev/Tools/opencv2/sources-build/install
INCLUDEPATH += $${OPENCV_PATH}/include
LIBS += -L$${OPENCV_PATH}/x64/mingw/lib -lopencv_core2411.dll -lopencv_highgui2411.dll
}

macx {
OPENCV_PATH = /Users/admin/Dev/opencv-2.4.11-build/install
INCLUDEPATH += $${OPENCV_PATH}/include
LIBS += -L$${OPENCV_PATH}/lib -lopencv_core -lopencv_highgui
}

unix:!macx {
LIBS += -lopencv_core -lopencv_imgproc -lopencv_highgui \
-lopencv_ml -lopencv_video -lopencv_features2d \
-lopencv_calib3d -lopencv_objdetect -lopencv_contrib \
-lopencv_legacy -lopencv_flann
}

TEMPLATE = app


SOURCES += main.cpp \
packetinterface.cpp \
serialport.cpp \
logger.cpp \
consolereader.cpp \
utility.cpp \
MatToQImage.cpp \
qcustomplot.cpp \
videocoder.cpp \
frameplotter.cpp \
framegrabber.cpp
framegrabber.cpp \
argprocessor.cpp

HEADERS += \
packetinterface.h \
serialport.h \
logger.h \
consolereader.h \
utility.h \
MatToQImage.h \
qcustomplot.h \
videocoder.h \
frameplotter.h \
framegrabber.h
framegrabber.h \
argprocessor.h

win32 {
SOURCES += consolereader_win.cpp
HEADERS += consolereader_win.h
} unix {
SOURCES += consolereader.cpp
HEADERS += consolereader.h
}
316 changes: 316 additions & 0 deletions BLDC_Logger.pro.user

Large diffs are not rendered by default.

48 changes: 48 additions & 0 deletions argprocessor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#include "argprocessor.h"

#include <QTextStream>

ArgProcessor::ArgProcessor(QObject *parent) : QObject(parent)
{
QTextStream streamOut(stdout);
QTextStream streamIn(stdin);
#ifdef Q_OS_WIN
QString defaultPort_ = "COM3";
#elif defined(Q_OS_MAC)
QString defaultPort_ = "/dev/tty.usbmodem261";
#else
QString defaultPort_ = "/dev/ttyACM0";
#endif
streamOut << "Port (default is " + defaultPort_ + "): ";
streamOut.flush();
mPort = streamIn.readLine();
if(mPort.isEmpty()) {
mPort = defaultPort_;
}

streamOut << "Camera index (default is 0): ";
streamOut.flush();
mCamera = streamIn.readLine().toInt();

streamOut << "Camera width (default is 1280): ";
streamOut.flush();
mWidth = streamIn.readLine().toInt();
if(mWidth == 0) {
mWidth = 1280;
}

streamOut << "Camera height (default is 720): ";
streamOut.flush();
mHeight = streamIn.readLine().toInt();
if(mHeight == 0) {
mHeight = 720;
}

streamOut << "Camera fps (default is 25.0): ";
streamOut.flush();
mFps = streamIn.readLine().toInt();
if(mFps == 0) {
mFps = 25.0;
}
}

52 changes: 52 additions & 0 deletions argprocessor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#ifndef ARGPROCESSOR_H
#define ARGPROCESSOR_H

#include <QObject>

class ArgProcessor : public QObject
{
Q_OBJECT
public:
explicit ArgProcessor(QObject *parent = 0);

QString getPort() const;
int getCamera() const;
int getWidth() const;
int getHeight() const;
double getFps() const;

private:
QString mPort;
int mCamera;
int mWidth;
int mHeight;
double mFps;

};

inline QString ArgProcessor::getPort() const
{
return mPort;
}

inline int ArgProcessor::getCamera() const
{
return mCamera;
}

inline int ArgProcessor::getWidth() const
{
return mWidth;
}

inline int ArgProcessor::getHeight() const
{
return mHeight;
}

inline double ArgProcessor::getFps() const
{
return mFps;
}

#endif // ARGPROCESSOR_H
3 changes: 2 additions & 1 deletion consolereader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@
*/

#include "consolereader.h"

#include <QTextStream>
#include <unistd.h> // Provides STDIN_FILENO

ConsoleReader::ConsoleReader(QObject *parent) :
QObject(parent)
{
notifier = new QSocketNotifier(STDIN_FILENO, QSocketNotifier::Read);
notifier = new QSocketNotifier(STDIN_FILENO, QSocketNotifier::Read, this);
connect(notifier, SIGNAL(activated(int)), this, SLOT(text()));
}

Expand Down
37 changes: 37 additions & 0 deletions consolereader_win.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include "consolereader_win.h"

#include <QtDebug>

#include <QTextStream>
#include <QTimer>

ConsoleReader::ConsoleReader(QObject *parent) : QThread(parent)
{
start();
}

ConsoleReader::~ConsoleReader()
{
quit();
wait();
}

void ConsoleReader::run()
{
QTimer timer;
connect(&timer, SIGNAL(timeout()), this, SLOT(onCheckStdin()), Qt::DirectConnection);
timer.start(100);
QThread::exec();
}

void ConsoleReader::onCheckStdin()
{
QTextStream stream(stdin);

// Do we have a new line to be read ?
QString line = stream.readLine();
if (!line.isEmpty())
{
emit textReceived(line);
}
}
25 changes: 25 additions & 0 deletions consolereader_win.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#ifndef CONSOLEREADER_H
#define CONSOLEREADER_H

#include <QThread>

class ConsoleReader : public QThread
{
Q_OBJECT

public:
explicit ConsoleReader(QObject *parent = 0);
~ConsoleReader();

signals:
void textReceived(QString message);

protected:
void run();

private slots:
void onCheckStdin();

};

#endif // CONSOLEREADER_H
26 changes: 23 additions & 3 deletions framegrabber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,21 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include "framegrabber.h"
#include <QDebug>

#include <QtDebug>

FrameGrabber::FrameGrabber(int w, int h, int fps, int dev, QObject *parent) :
QThread(parent)
{
mAbort = false;

mVideoCap.open(dev);
qDebug().nospace() << "Opening camera " << dev << "...";
if(mVideoCap.open(dev)) {
qDebug() << "ok";
} else {
qWarning() << "Failed!";
}

mVideoCap.set(CV_CAP_PROP_FRAME_WIDTH, w);
mVideoCap.set(CV_CAP_PROP_FRAME_HEIGHT, h);
Expand Down Expand Up @@ -66,4 +71,19 @@ void FrameGrabber::run()
mLatestFrame = MatToQImage(mFrameMat);
}
}

// working solution for some cameras
// while (mVideoCap.isOpened() && !mAbort) {
// int CAMERA_CHECK_ITERATIONS = 40;
// mVideoCap >> mFrameMat;
// if ( mFrameMat.total() > 0 ) {
// QMutexLocker lock(&mMutex);
// mLatestFrame = MatToQImage(mFrameMat);
// } else {
// qWarning() << "::: Accessing camera :::";
// if ( CAMERA_CHECK_ITERATIONS > 0 ) CAMERA_CHECK_ITERATIONS--;
// if ( CAMERA_CHECK_ITERATIONS < 0 ) break;
// }
// }

}
Loading