Skip to content

Commit 5efaae8

Browse files
authored
Merge pull request #150 from EmixamPP/opencv_err
Fix: Driver configured but not found & OpenCV exception on video feedback
2 parents 912ff4e + 67fd929 commit 5efaae8

10 files changed

Lines changed: 102 additions & 23 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Wed Nov 1 2023 - 5.2.4
2+
- Fix driver generated but not found
3+
- Fix for OpenCV exception thrown
4+
- Reduction in installation size
15
# Fri Oct 20 2023 - 5.2.1
26
- Fix unable to execute commands
37
# Thu Oct 19 2023 - 5.2.0

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ We also support OpenRC, just download the `.openrc` variant.
1616
It can be uninstalled by executing (remove the last line to keep the emitter configuration):
1717
```
1818
sudo rm -rf /usr/lib64/linux-enable-ir-emitter \
19-
/usr/libexec/linux-enable-ir-emitter \
2019
/usr/bin/linux-enable-ir-emitter \
2120
/usr/lib/systemd/system/linux-enable-ir-emitter.service \
2221
/etc/udev/rules.d/99-linux-enable-ir-emitter.rules \

camera/camera.cpp

Lines changed: 65 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ constexpr int NOK_KEY = 110;
3030
*/
3131
bool Camera::isGrayscale()
3232
{
33-
unique_ptr<cv::Mat> frame = read1();
33+
auto frame = read1();
3434

3535
if (frame->channels() != 3)
3636
return false;
@@ -163,8 +163,7 @@ void Camera::closeCap() noexcept
163163
cap->release();
164164
}
165165

166-
Camera::Camera(const string &device)
167-
: id(Camera::deviceId(device)), device(device)
166+
Camera::Camera(const string &device) : id(Camera::deviceId(device)), device(device)
168167
{
169168
cv::utils::logging::setLogLevel(cv::utils::logging::LogLevel::LOG_LEVEL_ERROR);
170169
}
@@ -225,47 +224,94 @@ bool Camera::apply(const CameraInstruction &instruction)
225224
*
226225
* @return the frame
227226
*/
228-
unique_ptr<cv::Mat> Camera::read1()
227+
shared_ptr<cv::Mat> Camera::read1()
229228
{
230229
openCap();
231-
auto frame = make_unique<cv::Mat>();
230+
auto frame = make_shared<cv::Mat>();
232231
cap->read(*frame);
233232
closeCap();
234233
return frame;
235234
}
236235

237236
/**
238-
* @brief Check if the emitter is working
239-
* by showing a video feedback and
240-
* asking confirmation to the user
237+
* @brief Show a video feedback to the user
238+
* and asks if the emitter is working
241239
*
242240
* @throw CameraException if unable to open the camera device
243241
*
244242
* @return true if yes, false if not
245243
*/
246-
bool Camera::isEmitterWorking()
244+
bool Camera::isEmitterWorkingAsk()
247245
{
248-
openCap();
249246
cv::Mat frame;
250247
int key = -1;
251248

252249
cout << "Is the video flashing? Press Y or N in the window" << endl;
253-
254250
while (key != OK_KEY && key != NOK_KEY)
255251
{
256252
cap->read(frame);
257253
cv::imshow("linux-enable-ir-emitter", frame);
258254
key = cv::waitKey(5);
259255
}
260-
261256
cout << (key == OK_KEY ? "Y pressed" : "N pressed") << endl;
262257

263-
closeCap();
264258
cv::destroyAllWindows();
265-
266259
return key == OK_KEY;
267260
}
268261

262+
/**
263+
* @brief Trigger the camera
264+
* and asks if the emitter is working
265+
*
266+
* @throw CameraException if unable to open the camera device
267+
*
268+
* @return true if yes, false if not
269+
*/
270+
bool Camera::isEmitterWorkingAskNoGui()
271+
{
272+
cv::Mat frame;
273+
cap->read(frame);
274+
275+
string answer;
276+
cout << "Is the ir emitter flashing (not just turn on) ? Yes/No ? ";
277+
cin >> answer;
278+
transform(answer.begin(), answer.end(), answer.begin(), [](char c)
279+
{ return tolower(c); });
280+
281+
while (answer != "yes" && answer != "y" && answer != "no" && answer != "n")
282+
{
283+
cout << "Yes/No ? ";
284+
cin >> answer;
285+
transform(answer.begin(), answer.end(), answer.begin(), [](char c)
286+
{ return tolower(c); });
287+
}
288+
289+
return answer == "yes" || answer == "y";
290+
}
291+
292+
/**
293+
* @brief Check if the emitter is working
294+
* by asking confirmation to the user
295+
*
296+
* @throw CameraException if unable to open the camera device
297+
*
298+
* @return true if yes, false if not
299+
*/
300+
bool Camera::isEmitterWorking()
301+
{
302+
openCap();
303+
304+
bool res;
305+
if (noGui)
306+
res = isEmitterWorkingAskNoGui();
307+
else
308+
res = isEmitterWorkingAsk();
309+
310+
closeCap();
311+
312+
return res;
313+
}
314+
269315
/**
270316
* @brief Execute an uvc query on the device indicated by the file descriptor
271317
*
@@ -388,6 +434,11 @@ uint16_t Camera::lenUvcQuery(uint8_t unit, uint8_t selector)
388434
return len;
389435
}
390436

437+
void Camera::disableGui()
438+
{
439+
noGui = true;
440+
}
441+
391442
CameraException::CameraException(const string &device) : message("Cannot access to " + device) {}
392443

393444
const char *CameraException::what() const noexcept

camera/camera.hpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class Camera
1818
int id;
1919
int fd = -1;
2020
const shared_ptr<cv::VideoCapture> cap = make_shared<cv::VideoCapture>();
21+
bool noGui = false;
2122

2223
protected:
2324
int getFd() const noexcept;
@@ -36,6 +37,10 @@ class Camera
3637

3738
int executeUvcQuery(const uvc_xu_control_query &query);
3839

40+
bool isEmitterWorkingAsk();
41+
42+
bool isEmitterWorkingAskNoGui();
43+
3944
public:
4045
const string device;
4146

@@ -59,7 +64,7 @@ class Camera
5964

6065
virtual bool isEmitterWorking();
6166

62-
unique_ptr<cv::Mat> read1();
67+
shared_ptr<cv::Mat> read1();
6368

6469
int setUvcQuery(uint8_t unit, uint8_t selector, vector<uint8_t> &control);
6570

@@ -70,6 +75,8 @@ class Camera
7075
bool isGrayscale();
7176

7277
static shared_ptr<Camera> findGrayscaleCamera();
78+
79+
void disableGui();
7380
};
7481

7582
class CameraException : public exception

command/commands.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ using namespace std;
88

99
extern "C"
1010
{
11-
ExitCode configure(const char* device, bool manual, unsigned emitters, unsigned negAnswerLimit);
11+
ExitCode configure(const char* device, bool manual, unsigned emitters, unsigned negAnswerLimit, bool noGui);
1212
ExitCode delete_driver(const char* device);
1313
ExitCode run(const char* device);
1414
ExitCode test(const char* device);

command/configure.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@ void enableDebug()
2222
* @param manual true for enabling the manual configuration
2323
* @param emitters number of emitters on the device
2424
* @param negAnswerLimit number of negative answer before the pattern is skiped. Use -1 for unlimited
25+
* @param noGui no gui video feedback
2526
*
2627
* @return exit code
2728
*/
28-
ExitCode configure(const char *device_char_p, bool manual, unsigned emitters, unsigned negAnswerLimit)
29+
ExitCode configure(const char *device_char_p, bool manual, unsigned emitters, unsigned negAnswerLimit, bool noGui)
2930
{
3031
const string device = string(device_char_p);
3132

@@ -49,12 +50,15 @@ ExitCode configure(const char *device_char_p, bool manual, unsigned emitters, un
4950
camera = make_shared<AutoCamera>(device);
5051
}
5152

53+
if (noGui)
54+
camera->disableGui();
55+
5256
if (camera == nullptr)
5357
Logger::critical(ExitCode::FAILURE, "Impossible to find an infrared camera.");
5458

5559
Logger::info("Configuring the camera:", camera->device, ".");
5660

57-
const string deviceName = device.substr(device.find_last_of("/") + 1);
61+
const string deviceName = camera->device.substr(camera->device.find_last_of("/") + 1);
5862
const string excludedPath = SAVE_DRIVER_FOLDER_PATH + deviceName + ".excluded";
5963
Finder finder(*camera, emitters, negAnswerLimit, excludedPath);
6064

command/load_cpp_commands.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
ctypes.c_bool,
1010
ctypes.c_uint32,
1111
ctypes.c_uint32,
12+
ctypes.c_bool,
1213
]
1314
cpp_commands.configure.restype = ctypes.c_int
1415

linux-enable-ir-emitter.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,13 @@
7171
default=40,
7272
type=int,
7373
)
74+
command_configure.add_argument(
75+
"-g",
76+
"--no-gui",
77+
help="no gui video feedback",
78+
action="store_true",
79+
default=False,
80+
)
7481
command_test = command_subparser.add_parser(
7582
"test",
7683
help="test a camera",
@@ -119,7 +126,13 @@
119126

120127
elif args.command == "configure":
121128
check_root()
122-
res = cpp_commands.configure(device.encode(), args.manual, args.emitters, args.limit)
129+
res = cpp_commands.configure(
130+
device.encode(),
131+
args.manual,
132+
args.emitters,
133+
args.limit,
134+
args.no_gui
135+
)
123136
if res == ExitCode.SUCCESS:
124137
boot("enable")
125138

meson.build

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
project(
22
'linux-enable-ir-emitter',
33
'cpp',
4-
version: '5.2.1',
4+
version: '5.2.3',
55
license: 'MIT',
66
default_options: [
77
'prefix=/usr',
88
'cpp_std=c++17',
9-
'optimization=3',
9+
'buildtype=release',
1010
'warning_level=everything',
1111
'werror=true',
1212
],

utils/globals.hpp.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include <vector>
77
using namespace std;
88

9-
const string SAVE_DRIVER_FOLDER_PATH = "@SAVE_DRIVER_FOLDER_PATH@";
9+
const string SAVE_DRIVER_FOLDER_PATH = "@SAVE_DRIVER_FOLDER_PATH@/";
1010

1111
enum ExitCode
1212
{

0 commit comments

Comments
 (0)