Skip to content

Commit 7312ead

Browse files
authored
Bugfix/build with newer boost and opencv libs (#20)
* Fix build for newer boost lib versions * Fix build for newer versions of OpenCV * Use std::string instead of std::__cxx11::string * Fix boost package dependencies * Fix path to app executable * Revert "Fix path to app executable" This reverts commit 4be17f3 as this breaks the original self-o-mat boxes as described in #20.
1 parent e0fe086 commit 7312ead

File tree

4 files changed

+56
-9
lines changed

4 files changed

+56
-9
lines changed

CMakeLists.txt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,14 @@ add_custom_command(OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/src/protobuf/api.pb.cc ${C
1818

1919

2020
find_package(OpenCV REQUIRED)
21-
find_package(Boost REQUIRED COMPONENTS system thread filesystem)
21+
find_package(Boost REQUIRED)
22+
if(Boost_FOUND)
23+
if(${Boost_VERSION} VERSION_GREATER_EQUAL 1.70)
24+
find_package(Boost REQUIRED COMPONENTS system thread filesystem chrono)
25+
else()
26+
find_package(Boost REQUIRED COMPONENTS system thread filesystem)
27+
endif()
28+
endif()
2229
find_package(Cups REQUIRED)
2330
find_package(Protobuf REQUIRED)
2431

src/camera/NopCamera.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,20 @@
1010
#include <opencv2/opencv.hpp>
1111
#include <SFML/System/Clock.hpp>
1212

13+
/* Some OpenCV definitions are outdated/ have been renamed and moved into the `cv` namespace;
14+
* see also: https://stackoverflow.com/questions/57982505/opencv-4-cap-prop-pos-frames-was-not-declared-in-this-scope
15+
* Conditionally defining the macros by the preprocessor if they don't already exist shouldn't
16+
* break the build for older OpenCV versions but fix it for newer ones.
17+
*/
18+
#ifndef CV_CAP_PROP_POS_FRAMES
19+
#define CV_CAP_PROP_POS_FRAMES cv::CAP_PROP_POS_FRAMES
20+
#endif
21+
#ifndef CV_CAP_PROP_FRAME_COUNT
22+
#define CV_CAP_PROP_FRAME_COUNT cv::CAP_PROP_FRAME_COUNT
23+
#endif
24+
#ifndef CV_CAP_PROP_FPS
25+
#define CV_CAP_PROP_FPS cv::CAP_PROP_FPS
26+
#endif
1327

1428
namespace selfomat {
1529
namespace camera {

src/camera/OpenCVCamera.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,18 @@
44

55
#include "OpenCVCamera.h"
66

7+
/* Some OpenCV definitions are outdated/ have been renamed and moved into the `cv` namespace;
8+
* see also: https://stackoverflow.com/questions/57982505/opencv-4-cap-prop-pos-frames-was-not-declared-in-this-scope
9+
* Conditionally defining the macros by the preprocessor if they don't already exist shouldn't
10+
* break the build for older OpenCV versions but fix it for newer ones.
11+
*/
12+
#ifndef CV_CAP_PROP_FRAME_WIDTH
13+
#define CV_CAP_PROP_FRAME_WIDTH cv::CAP_PROP_FRAME_WIDTH
14+
#endif
15+
#ifndef CV_CAP_PROP_FRAME_HEIGHT
16+
#define CV_CAP_PROP_FRAME_HEIGHT cv::CAP_PROP_FRAME_HEIGHT
17+
#endif
18+
719
using namespace selfomat::camera;
820

921
std::string OpenCVCamera::TAG = "OPENCV_CAMERA";
@@ -133,11 +145,11 @@ bool OpenCVCamera::autofocusBlocking() {
133145

134146

135147
string OpenCVCamera::getCameraName() {
136-
return std::__cxx11::string();
148+
return std::string();
137149
}
138150

139151
string OpenCVCamera::getLensName() {
140-
return std::__cxx11::string();
152+
return std::string();
141153
}
142154

143155
int OpenCVCamera::getExposureCorrection() {

src/tools/blocking_reader.h

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,18 @@
2828
#include <iostream>
2929
#include <tools/verbose.h>
3030

31+
/* Use the following macro to allow builds for different boost library versions;
32+
* inspired by: https://stackoverflow.com/a/67773642/1627585
33+
*/
34+
#if BOOST_VERSION >= 107000
35+
#define GET_IO_SERVICE(s) ((boost::asio::io_context&)(s).get_executor().context())
36+
#else
37+
#define GET_IO_SERVICE(s) ((s).get_io_service())
38+
#endif
39+
40+
#define BRDR_TAG "BLOCKING_READER"
41+
42+
3143
using namespace selfomat::tools;
3244

3345
class blocking_reader
@@ -41,10 +53,11 @@ class blocking_reader
4153
// Called when an async read completes or has been cancelled
4254
void read_complete(const boost::system::error_code& error,
4355
size_t bytes_transferred) {
56+
LOG_D(BRDR_TAG, "read complete: bytes_transferred=" + std::to_string(bytes_transferred));
4457
read_error = (error || bytes_transferred == 0);
4558

4659
if(read_error) {
47-
LOG_E("BLOCKING_READER", "error: ", error.message());
60+
LOG_E(BRDR_TAG, "boost error message: ", error.message());
4861
}
4962

5063
// Read has finished, so cancel the
@@ -54,11 +67,12 @@ class blocking_reader
5467

5568
// Called when the timer's deadline expires.
5669
void time_out(const boost::system::error_code& error) {
57-
// Was the timeout was cancelled?
70+
// Was the timeout cancelled?
5871
if (error) {
5972
// yes
6073
return;
6174
}
75+
LOG_D(BRDR_TAG, "timeout");
6276

6377
// no, we have timed out, so kill
6478
// the read operation
@@ -73,7 +87,7 @@ class blocking_reader
7387
// a timeout in milliseconds.
7488
blocking_reader(boost::asio::serial_port& port, size_t timeout) :
7589
port(port), timeout(timeout),
76-
timer(port.get_io_service()),
90+
timer( GET_IO_SERVICE(port) ),
7791
read_error(true) {
7892

7993
}
@@ -86,8 +100,7 @@ class blocking_reader
86100

87101
// After a timeout & cancel it seems we need
88102
// to do a reset for subsequent reads to work.
89-
port.get_io_service().reset();
90-
103+
GET_IO_SERVICE(port).reset();
91104

92105
// Asynchronously read 1 character.
93106
boost::asio::async_read(port, boost::asio::buffer(&c, 1),
@@ -97,6 +110,7 @@ class blocking_reader
97110
boost::asio::placeholders::bytes_transferred));
98111

99112
// send the request
113+
LOG_D(BRDR_TAG, "Sending request (size: " + std::to_string(request_size) + ")");
100114
port.write_some(boost::asio::buffer(request, request_size));
101115

102116
// Setup a deadline time to implement our timeout.
@@ -106,7 +120,7 @@ class blocking_reader
106120

107121
// This will block until a character is read
108122
// or until the it is cancelled.
109-
port.get_io_service().run();
123+
GET_IO_SERVICE(port).run();
110124

111125
if (!read_error)
112126
val = c;

0 commit comments

Comments
 (0)