Skip to content
This repository is currently being migrated. It's locked while the migration is in progress.

Commit

Permalink
Merge pull request #1 from garaemon/bionic
Browse files Browse the repository at this point in the history
Support Bionic
  • Loading branch information
garaemon authored Jun 2, 2019
2 parents 59d286f + 177c864 commit 7759d56
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 39 deletions.
25 changes: 23 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,24 @@ remake_doc(
remake_pack_deb(
DEPENDS libudev0|libudev1 libusb-1.0-0 libboost-chrono[0-9.]*
)

find_program(LSB_RELEASE_EXEC lsb_release)
execute_process(COMMAND ${LSB_RELEASE_EXEC} -cs
OUTPUT_VARIABLE LSB_RELEASE_ID_SHORT
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if (${LSB_RELEASE_ID_SHORT} STREQUAL "bionic")
set(PNG_PACKAGE "libpng16-16")
set(PNG_DEV_PACKAGE "libpng-dev")
else(${LSB_RELEASE_ID_SHORT} STREQUAL "bionic")
set(PNG_PACKAGE "libpng12-0")
set(PNG_DEV_PACKAGE "libpng12-dev")
endif(${LSB_RELEASE_ID_SHORT} STREQUAL "bionic")

remake_pack_deb(
COMPONENT utils
DESCRIPTION "utilities"
DEPENDS libseekthermal libpng12-0
DEPENDS libseekthermal ${PNG_PACKAGE}
)
remake_pack_deb(
COMPONENT gui
Expand All @@ -59,7 +73,6 @@ remake_pack_deb(
COMPONENT doc
DESCRIPTION "documentation"
)

remake_distribute_deb(
DISTRIBUTION precise
SECTION libs
Expand All @@ -76,3 +89,11 @@ remake_distribute_deb(
libpng12-dev libqt4-dev remake doxygen pkg-config
PASS CMAKE_BUILD_TYPE LIBSEEKTHERMAL_GIT_REVISION
)
remake_distribute_deb(
DISTRIBUTION bionic
SECTION libs
UPLOAD ppa:kralf/asl
DEPENDS libboost-chrono-dev libudev-dev libusb-1.0-0-dev
libpng-dev libqt4-dev remake doxygen pkg-config
PASS CMAKE_BUILD_TYPE LIBSEEKTHERMAL_GIT_REVISION
)
75 changes: 38 additions & 37 deletions src/bin/gui/view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include <iostream>
#include <csignal>
#include <cmath>
#include <limits>

#include <QApplication>
Expand Down Expand Up @@ -48,7 +49,7 @@ class FrameEvent:
QEvent(QEvent::User),
frame(frame) {
};

const Pointer<Frame>& getFrame() const {
return frame;
}
Expand All @@ -69,23 +70,23 @@ class Window:
blur(false) {
setCentralWidget(&label);
setStatusBar(&statusBar);

centralWidget()->setAttribute(Qt::WA_TransparentForMouseEvents);
setMouseTracking(true);
}

void setCalibrationFrame(const Frame& calibrationFrame) {
this->calibrationFrame = calibrationFrame;
}

void setScale(double scale) {
this->scale = scale;
}

void setClose(bool close) {
this->close = close;
}

void setBlur(bool blur) {
this->blur = blur;
}
Expand All @@ -95,47 +96,47 @@ class Window:

Frame frame;
Frame calibrationFrame;
Frame lastCalibrationFrame;
Frame lastCalibrationFrame;
size_t frameId;

Frame meanFrame;
Frame varianceFrame;

double scale;
bool close;
bool blur;

void updateValue(const QPointF& position) {
if (!frame.isEmpty()) {
QPointF xy = position*1.0/scale;
size_t x = floor(xy.x());

size_t x = std::floor(xy.x());
if (x >= frame.getWidth())
x = frame.getWidth()-1;
size_t y = floor(xy.y());

size_t y = std::floor(xy.y());
if (y >= frame.getHeight())
y = frame.getHeight()-1;

std::stringstream stream;
stream << "(" << x << ", " << y << "): " << frame(x, y);

statusBar.showMessage(stream.str().c_str());
}
}

bool event(QEvent* event) {
if (event->type() == QEvent::User) {
FrameEvent* frameEvent = (FrameEvent*)event;

if (close && frameEvent->getFrame()->getType() == Frame::typeNormal) {
double t = 1.0+frameId;
Frame frame_t = *frameEvent->getFrame();

if (frameId) {
meanFrame *= (t-1.0)/t;
meanFrame += frame_t*(1.0/t);

varianceFrame *= (t-1.0)/t;
frame_t -= meanFrame;
frame_t *= frame_t;
Expand All @@ -146,45 +147,45 @@ class Window:
meanFrame = frame_t*(1.0/t);
varianceFrame.resize(meanFrame.getWidth(), meanFrame.getHeight());
}

++frameId;
}

if (frameEvent->getFrame()->getType() == Frame::typeNormal) {
frame = *frameEvent->getFrame();
size_t width = frame.getWidth();
size_t height = frame.getHeight();

if (!calibrationFrame.isEmpty())
frame -= calibrationFrame;
else if (!lastCalibrationFrame.isEmpty())
frame -= lastCalibrationFrame;

float epsilon = std::numeric_limits<float>::epsilon();

if (!varianceFrame.isEmpty()) {
for (size_t x = 0; x < width; ++x)
for (size_t y = 0; y < height; ++y)
if (varianceFrame(x, y) < epsilon)
frame.close(x, y);
}

frame.normalize();
if (blur)
frame.gaussianBlur();

QImage image(width, height, QImage::Format_RGB888);
for (size_t x = 0; x < width; ++x)
for (size_t y = 0; y < height; ++y) {
float value = frame(x, y)*255.0;
image.setPixel(x, y, qRgb(value, value, value));
}

label.setPixmap(QPixmap::fromImage(
image.scaled(image.size()*scale)));
setFixedSize(label.pixmap()->width(), label.pixmap()->height()+
statusBar.height());

if (underMouse())
updateValue(centralWidget()->mapFromGlobal(QCursor::pos()));
}
Expand All @@ -194,7 +195,7 @@ class Window:
else
QMainWindow::event(event);
}

void mouseMoveEvent(QMouseEvent* event) {
updateValue(centralWidget()->mapFromGlobal(event->globalPos()));
}
Expand All @@ -208,20 +209,20 @@ class Worker:
device(device),
interruptRequested(false) {
}

void interrupt() {
interruptRequested = true;
wait();
}
protected:
Pointer<Device> device;

bool interruptRequested;

void run() {
while (!interruptRequested) {
Pointer<Frame> frame = new Frame();

device->capture(*frame);

if (parent()) {
Expand Down Expand Up @@ -257,7 +258,7 @@ int main(int argc, char **argv) {
SeekThermal::Usb::Context context;
Pointer<Interface> interface =
context.getInterface(application[0].getValue());

Pointer<Device> device;
if (application["device"].getValue().empty())
device = interface->discoverDevice();
Expand All @@ -269,11 +270,11 @@ int main(int argc, char **argv) {
application["timeout"].getValue<size_t>()*1e-3);
device->setInterface(interface);
device->connect();

device->initialize();

signal(SIGINT, signaled);

QApplication qApplication(argc, argv);
Window window;
window.setScale(application["scale"].getValue<double>());
Expand All @@ -286,12 +287,12 @@ int main(int argc, char **argv) {
calibrationFrame.load(application["calibration"].getValue());
window.setCalibrationFrame(calibrationFrame);
}

window.show();
worker.start();
qApplication.exec();
worker.interrupt();

device->disconnect();
}
else {
Expand Down

0 comments on commit 7759d56

Please sign in to comment.